]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MEDIUM: pools: directly free objects when pools are too much crowded
authorWilly Tarreau <w@1wt.eu>
Fri, 8 May 2020 06:38:24 +0000 (08:38 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 27 May 2020 06:32:42 +0000 (08:32 +0200)
commit63a8738724948fe695335ec83224a03d19e943ae
tree18fe516442787d6716659c459d6cec7e4f10cab6
parenta1e4f8c27c7677593d747eeef1163af0ee04be74
MEDIUM: pools: directly free objects when pools are too much crowded

During pool_free(), when the ->allocated value is 125% of needed_avg or
more, instead of putting the object back into the pool, it's immediately
freed using free(). By doing this we manage to significantly reduce the
amount of memory pinned in pools after transient traffic spikes.

During a test involving a constant load of 100 concurrent connections
each delivering 100 requests per second, the memory usage was a steady
21 MB RSS. Adding a 1 minute parallel load of 40k connections all looping
on 100kB objects made the memory usage climb to 938 MB before this patch.
With the patch it was only 660 MB. But when this parasit load stopped,
before the patch the RSS would remain at 938 MB while with the patch,
it went down to 480 then 180 MB after a few seconds, to stabilize around
69 MB after about 20 seconds.

This can be particularly important to improve reloads where the memory
has to be shared between the old and new process.

Another improvement would be welcome, we ought to have a periodic task
to check pools usage and continue to free up unused objects regardless
of any call to pool_free(), because the needed_avg value depends on the
past and will not cover recently refilled objects.
include/common/memory.h