[concurrency-interest] Reducing contention overhead by suspending worker threads

Peter Kovacs peter.kovacs.1.0rc at gmail.com
Mon Mar 19 18:38:51 EDT 2007


Hi,

I've got a bounded blocking queue "outputQueue". A number of worker
threads are feeding this queue and one single thread is consuming its
elements. I've got two implementations of this setup with slightly
different details and a performance difference of about 25-30%. The
faster implementation is pretty messy and consequently difficult to
compare with the clean(er) but slower implementation.

The worker threads get sometimes blocked because the consumer cannot
keep up with the pace of the result production and the outputQueue
gets full. The only palpable difference between the slow and the fast
implementation I can find is that at this point (outputQueue gets
full) the worker threads of the faster implementation both go into
wait, while one of the workers of the slower implementation goes into
wait while the other get blocked by an outer intrinsic lock
(protecting the input source for the workers).

Now I speculate as follows: the slower guy is slower because the
threads blocked on the intrinsic lock must be rescheduled anyway on
the OS level: the only waiting thread must first be able to put its
data on the output queue before the other can have a chance to go
ahead.

Now if I try to balance the number of worker threads so that the
bounded queue does not possibly get full, then I can significantly
reduce the reschedule overhead.

Does this all makes sense? Or am I completely naive with this idea?
May this kind of speculation hold any substance at all (reschedule
overhead causing performance loss)?

Thanks
Peter


More information about the Concurrency-interest mailing list