pthreadpool: Slightly serialize jobs
authorJeremy Allison <jra@samba.org>
Mon, 25 Aug 2014 19:27:54 +0000 (12:27 -0700)
committerKarolin Seeger <kseeger@samba.org>
Sun, 19 Oct 2014 19:05:07 +0000 (21:05 +0200)
commit26a70367b8f4d71f3c2132a9f31ef94daf0dfebe
tree0ca94538077ec22b4e04ed2b876f144118fbee96
parentfda66b9cb9b15ae461b4991668c819636d03dd0b
pthreadpool: Slightly serialize jobs

Using the new msg_source program with 1.500 instances against a single
msg_sink I found the msg_source process to spawn two worker threads for
synchronously sending the data towards the receiving socket. This should
not happen: Per destination node we only create one queue. We strictly
only add pthreadpool jobs one after the other, so a single helper thread
should be perfectly sufficient.

It turned out that under heavy overload the main sending thread was
scheduled before the thread that just had finished its send() job. So
the helper thread was not able to increment the pool->num_idle variable
indicating that we don't have to create a new thread when the new job
is added.

This patch moves the signalling write under the mutex. This means that
indicating readiness via the pipe and the pool->num_idle variable happen both
under the same mutex lock and thus are atomic. No superfluous threads anymore.

Back port of commit 1c4284c7395f23cefa61a407db74cf5067aee2aa
that went into master.

https://bugzilla.samba.org/show_bug.cgi?id=10779

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/lib/pthreadpool/pthreadpool.c