listen socket more frequent service 03/2903/1
authorAndy Green <andy.green@linaro.org>
Tue, 15 Jan 2013 23:59:47 +0000 (07:59 +0800)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Thu, 7 Mar 2013 21:01:25 +0000 (13:01 -0800)
commit7172caed6ce518aca3d72a86ed11fbdb3fe72b5d
treeb22ea278516eb7fb151d12332606de6716e1457f
parentfb1bb98d264c911b72c270e5b1df413d458f2eb4
listen socket more frequent service

From an idea by Edwin van den Oetelaar <oetelaar.automatisering@gmail.com>

When testing libwebsockets with ab, Edwin found an unexpected bump in
the distribution of latencies, some connections were held back almost
the whole test duration.

http://ml.libwebsockets.org/pipermail/libwebsockets/2013-January/000006.html

Studying the problem revealed that when there are mass pending connections
amongst many active connections, we do not service the listen socket often
enough to clear the backlog, some seem to get stale violating FIFO ordering.

This patch introduces listen socket service "piggybacking", where every n
normal socket service actions we also check the listen socket and deal with
pending connections there.

Normally, it checks the listen socket gratuitously every 10 normal socket
services.  However, if it finds something waiting, it forces a check on the
next normal socket service too by keeping stats on how often something was
waiting.  If the probability of something waiting each time becomes high,
it will allow up to two waiting connections to be serviced for each normal
socket service.

In that way it has low burden in the normal case, but rapidly adapts by
detecting mass connection loads as found in ab.

Signed-off-by: Andy Green <andy.green@linaro.org>
lib/libwebsockets.c
lib/private-libwebsockets.h