[concurrency-interest] Single producer, single consumer: unexpected delays for producer

Gregg Wonderly gregg at cytetech.com
Mon Aug 11 13:25:07 EDT 2008


Daniel Harvey wrote:
> I've tried a number of the above suggestions.
> 
> 1) The prespinTake degraded the performance a little further, and I 
> think suggests that it is not waking the blocked thread that is causing 
> the delay.
> 2) Draining the queue into an ArrayList (Carfield's suggestion) may have 
> slightly improved things, but not significantly (a few % maybe).
> 3) I put some code in to keep track of how many messages are typically 
> in the queue when the consumer thread finishes it's take(), and it is 
> typically 0... ie the majority (around 80-90%) of the time a single 
> message is being removed from the queue.
> 
> Having run the tests more times, and for longer duration, I apparently 
> overstated the degradation that is caused by the consumer executing the 
> socket.write() (in addition to performing the encoding):  it appears to 
> be a factor of 3 and not 6. Nevertheless, that's still a big 
> difference... specifically:
> 
> for (;;) {
>     CharBuffer chars = CharBuffer.wrap(queue.take());
>     ByteBuffer bytes = encoder.encode(chars);
>     socketChannel.write(bytes);
> }

What happens if you run this in a console window and bang on "Ctrl-\" (or send 
SIGQUIT to it with kill) to see where the threads are "at"?  Do you see any 
"waiting to lock" situations in the thread dumps?

Gregg Wonderly


More information about the Concurrency-interest mailing list