fix: add exptime to ewma shared dict items#12557
Merged
Merged
Conversation
Signed-off-by: Nic <[email protected]>
nic-6443
requested review from
AlinsRan,
Revolyssup,
bzp2010,
membphis and
nic-chen
August 28, 2025 09:54
nic-chen
approved these changes
Aug 28, 2025
AlinsRan
approved these changes
Aug 29, 2025
membphis
approved these changes
Sep 1, 2025
jizhuozhi
pushed a commit
to jizhuozhi/apisix
that referenced
this pull request
Oct 18, 2025
Signed-off-by: Nic <[email protected]>
shreemaan-abhishek
pushed a commit
to shreemaan-abhishek/apisix
that referenced
this pull request
Jan 2, 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.
Description
Because the current ewma load balancer uses two shared memory and has no recycling mechanism, when the user's upstream IP address changes frequently, the shared memory will be quickly consumed, resulting in the following error:
This PR sets expiration times for the two shared memory items used by ewma to record upstream latency data, so that when executing the
setandgetfunctions of sharedict, openresty will attempt to reclaim 1~2 expired entries.https://github.com/openresty/lua-nginx-module/blob/c47084b5d719ce507d2419d8660f39544a9d1fea/src/ngx_http_lua_shdict.c#L1595-L1599
https://github.com/openresty/lua-nginx-module/blob/c47084b5d719ce507d2419d8660f39544a9d1fea/src/ngx_http_lua_shdict.c#L1368
https://github.com/openresty/lua-nginx-module/blob/c47084b5d719ce507d2419d8660f39544a9d1fea/src/ngx_http_lua_shdict.c#L250-L254
This ensures that the shared memory space is released.
The choice of TTL
According to the current ewma algorithm parameters:
apisix/apisix/balancer/ewma.lua
Lines 51 to 58 in 3260931
apisix/apisix/balancer/ewma.lua
Line 20 in 49a48eb
set ttl to 60s is more appropriate because when the current time exceeds 60s from the
last_touched_at, the weight of that historical score is already close to 0. Therefore, whether or not this historical score exists does not matter.This error can only be triggered when there are frequent and continuous changes in the upstream nodes. so it is not able to provide an effective integration test.
Which issue(s) this PR fixes:
Fixes #
Checklist