Repository navigation
feature: ngx.balancer: added the pool_size argument to enable_keepalive(). - #544
Merged
zhuizhuhaomeng merged 1 commit intoOct 31, 2026
Merged
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.
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
oowl
force-pushed
the
feat/balancer-keepalive-pool-size
branch
from
October 31, 2026 03:46
ac98801 to
99c451d
Compare
zhuizhuhaomeng
approved these changes
Oct 31, 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 10033. Closed, not mergedIntegration status:
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.CI
The temporary CI commit has been removed. CI now clones upstream
openresty/lua-nginx-modulemaster again. The feature and tests are unchanged.The C-side dependency openresty/lua-nginx-module#2536 is still open. Until it lands on master, the upstream C function has the old FFI signature, so this CI configuration is expected to fail. Previous successful CI runs used the matching #2536 branch.