timeout move to doubly linked list
authorAndy Green <andy.green@linaro.org>
Mon, 18 Jan 2016 20:32:14 +0000 (04:32 +0800)
committerAndy Green <andy.green@linaro.org>
Mon, 18 Jan 2016 20:32:14 +0000 (04:32 +0800)
commitd738f84ed1b3283a968b0550011799e408bd0527
treebc5bc324a24f7f2e755e5fc0ec9bb5b4d03fb2da
parent15c92b1bf6a4562733b52e03b9e2f21421d180c6
timeout move to doubly linked list

In the case we have a lot of connections, checking them all for timeout state
once a second becomes burdensome.  At the moment if you have 100K connections,
once a second they all get checked for timeout in a loop.

This patch adds a doubly-linked list based in the context to each wsi, and
only wsi with pending timeouts appear on it.  At checking time, we traverse
the list, which costs nothing if empty because nobody has a pending timeout.

Similarly adding and removing from the list costs almost nothing since no
iteration is required no matter how big the list.

The extra 8 or 16 bytes in the wsi are offset a little bit by demoting .pps
from int to char (save 3 bytes).  And trim max act exts to 2, since we only
provide one, saving 8 /16 bytes by itself if exts enabled.

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