Repository navigation
Conversation
oowl
force-pushed
the
feat/balancer-keepalive-pool-size
branch
2 times, most recently
from
October 25, 2026 16:26
49c6702 to
b867dba
Compare
…ve().
balancer.enable_keepalive(idle_timeout?, max_requests?, pool_size?)
pool_size caps the number of idle connections cached for the pool of the
current connection (peer address, host given to set_current_peer() and
local address). When the pool is full, its own least recently used idle
connection is closed instead of evicting idle connections of other pools
from the upstream-wide balancer_keepalive cache. Omitting it, or passing
0, keeps the previous behaviour.
This requires the matching FFI signature change in lua-nginx-module.
The C side of the pool_size argument lives in openresty/lua-nginx-module#2536 and is not on master yet, so CI must be built against that branch for the FFI signature to match. Drop this commit before merging, once #2536 is merged.
oowl
force-pushed
the
feat/balancer-keepalive-pool-size
branch
from
October 25, 2026 16:43
b867dba to
ac98801
Compare
This was referenced Oct 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related PRs
pool_sizein the balancer keepalive FFI API, per-pool descriptorsbalancer.enable_keepalive(idle_timeout?, max_requests?, pool_size?)ngx_http_lua_versionto 10033Suggested merge order:
bugfix: send the HUP mode signals from perl instead of running kill(1). test-nginx#190, then drop theDone: tests: the trace id number maybe two or more digits. #190 is merged and #2536 no longer carries a CI commit.TEMPORARYCI commit from feature: added the pool_size argument to the balancer keepalive FFI API. lua-nginx-module#2536.TEMPORARYCI commits of #2540 and change: require ngx_http_lua_module 0.10.33 and bumped version to 0.1.36. #547 when merging. Drop theTEMPORARYCI commit from feature: ngx.balancer: added the pool_size argument to enable_keepalive(). #544 once #2536 is on master.Summary
Adds an optional third argument
pool_sizetongx.balancer.enable_keepalive():pool_sizesets the maximum number of idle connections cached for the pool of the current connection. A pool is identified by the peer address, thehostargument ofset_current_peer()and the local address. When a pool is full, its own least recently used idle connection is closed. Without this, a busy pool evicts the idle connections of other pools from the upstream-widebalancer_keepalivecache. Omitting the argument or passing0keeps the current behaviour.pool_sizenever raises thebalancer_keepalivetotal.Depends on openresty/lua-nginx-module#2536, which changes the FFI signature of
ngx_http_lua_ffi_balancer_enable_keepalive(). The two PRs should be merged together.Docs
enable_keepaliveused to say the connection goes into "the pool specified by thepooloption ofset_current_peer". That option does not exist (it is a leftover of the original design). The text now describes the actual pool key: peer address,host(orproxy_ssl_namefor HTTPS whenhostis nil), and local address. It also explains that all pools share thebalancer_keepalivecapacity.pool_size: the limit is checked against the value passed by the request whose connection is being inserted, so every request using the same pool should pass the samepool_size.Tests
New in
t/balancer-keepalive.t:pool_sizepool_size = 1makes a pool evict its own oldest idle connectionbalancer_keepalive 2, a full pool does not evict another pool's idle connection. This test fails ifpool_sizeis0.pool_size = 0behaves exactly like omitting it, i.e. the global LRU evicts the other pool's connection.pool_sizealso applies to pools split by SNI (hostnil, name fromproxy_ssl_name), and each request still gets its own SNI.New in
t/balancer-keepalive-localaddr.t:pool_sizeapplies per local address (bind_to_local_addr). A full pool for one source address does not evict the other source address's connection.TEST 33 fails if the C side ignores the host in the pool key, and localaddr TEST 8 fails if it ignores the local address (checked with deliberately broken builds).
Ran locally against nginx 1.31.8 + the lua-nginx-module branch, both as a normal
--with-debugbuild and as an ASan build:t/balancer*.tandt/stream/balancer*.tall pass with no ASan reports.t/balancer-keepalive.tpassed 20 runs in a row. Line length and tab checks pass.Temporary CI commit
The last commit (
tests: TEMPORARY: ...) points the CI build at the PR branch of openresty/lua-nginx-module#2536 (oowl/lua-nginx-module@feat/balancer-keepalive-pool-size), so the FFI signature matches. It must be dropped before merging, once #2536 is merged, so CI goes back to lua-nginx-module master.