All,
I am trying to write a simple message broker that can handle in-time and delayed requests.
I wanted to use Executors.newSingleThreadExecutor() combined with a Callables.
What I found is that performance degrades significantly if I use just in-time requests.
Request:
Broker:
TestCode:
My
test includes 10 threads constantly pumping requests in the broker and timer that puts delayed message every 200 millsec. The throughput is:
Time: 5 sec
# of delayed messages: 24
# of messages: 356732
Av time: 0.1366528749551489
If I modify the broker to use 2 executors for in-time and delayed requests, the performance is significantly better:
Output:
Time: 5 sec
# of delayed messages: 24
# of messages: 434754
Av time: 0.11181648599102487
Any idea why 2 threaded app with 2 queues that have to be linked is faster than single threaded with one priority queue?
Any way to optimize?