feat: add router_rebuild_min_interval to reduce CPU spikes from frequ…#13073
feat: add router_rebuild_min_interval to reduce CPU spikes from frequ…#13073membphis wants to merge 1 commit into
Conversation
…ent route changes When routes change frequently (e.g., 20-50 changes/sec), the router is rebuilt on every change which causes CPU spikes under high-frequency updates due to full radixtree recompilation with all routes. This adds a configurable minimum interval between router rebuilds. When set to a positive value (e.g., 1 or 5 seconds), rebuilds are throttled so the router is not recompiled more frequently than the configured interval, significantly reducing CPU usage during bulk route updates. Default value is 0 (rebuild immediately on every change), preserving backward compatibility with existing behavior.
|
Architectural Note (self-review): This PR (#13073) and #12826 (incremental router compilation by @apaloleg) address the same problem — CPU spikes from frequent router rebuilds — with different approaches:
Proposed path forward:
Will coordinate with @apaloleg on #12826 to align timelines. |
|
This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the dev@apisix.apache.org list. Thank you for your contributions. |
|
This pull request/issue has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time. |
Description
When routes change frequently (e.g., 20-50 changes/sec with 5000+ total routes), the data plane rebuilds the radixtree router on every single change, causing significant CPU spikes (up to 80%) and temporary TPS drops.
This PR adds a configurable
router_rebuild_min_intervaloption that sets a minimum time interval (in seconds) between HTTP router rebuilds. When the interval has not elapsed since the last rebuild, subsequent route changes are acknowledged but the router rebuild is deferred, dramatically reducing CPU usage during bulk route updates.Configuration
Expected Impact
Changes
conf/config.yaml.example: Addedrouter_rebuild_min_intervalconfig optionapisix/cli/config.lua: Default value0apisix/router.lua: Reads config and passes to HTTP router modules (+3 lines)apisix/http/router/radixtree_uri.lua: Min interval check before rebuildapisix/http/router/radixtree_host_uri.lua: Min interval check before rebuildapisix/http/router/radixtree_uri_with_parameter.lua: Min interval check before rebuildt/router/router-rebuild-min-interval.t: Test cases covering default behavior, skip behavior, and deferred rebuildBackward Compatibility
Default value is
0, preserving the existing behavior of rebuilding immediately on every route change. No existing configurations are affected.