MINOR: proxy/pool: prevent unnecessary calls to pool_gc()

Under certain soft-stopping conditions (ie: sticktable attached to proxy
and in-progress connections to the proxy that prevent haproxy from
exiting), manage_proxy() (p->task) will wake up every second to perform
a cleanup attempt on the proxy sticktable (to purge unused entries).

However, as reported by TimWolla in GH #2091, it was found that a
systematic call to pool_gc() could cause some CPU waste, mainly
because malloc_trim() (which is rather expensive) is being called
for each pool_gc() invocation.

As a result, such soft-stopping process could be spending a significant
amount of time in the malloc_trim->madvise() syscall for nothing.

Example "strace -c -f -p `pidof haproxy`" output (taken from
Tim's report):

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 46.77    1.840549        3941       467         1 epoll_wait
 43.82    1.724708          13    128509           sched_yield
  8.82    0.346968          11     29696           madvise
  0.58    0.023011          24       951           clock_gettime
  0.01    0.000257          10        25         7 recvfrom
  0.00    0.000033          11         3           sendto
  0.00    0.000021          21         1           rt_sigreturn
  0.00    0.000021          21         1           timer_settime
------ ----------- ----------- --------- --------- ----------------
100.00    3.935568          24    159653         8 total

To prevent this, we now only call pool_gc() when some memory is
really expected to be reclaimed as a direct result of the previous
stick table cleanup.
This is pretty straightforward since stktable_trash_oldest() returns
the number of trashed sticky sessions.

This may be backported to every stable versions.

(cherry picked from commit 6e1fe253b71707cfe58ab2c7e15d8e36976fd565)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit c4ab8c490ec5ff0152ad672d694b718d9c2b0d3d)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit c2c2ac7195a2d8fe4075ff90b56cd56e490b7838)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 05aaac3fa371aa979c52152cc2fea96abc066c47)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
1 file changed