feat: add router_rebuild_min_interval to reduce CPU spikes from frequent route changes#13069
Closed
membphis wants to merge 1 commit intoapache:masterfrom
Closed
feat: add router_rebuild_min_interval to reduce CPU spikes from frequent route changes#13069membphis wants to merge 1 commit intoapache:masterfrom
membphis wants to merge 1 commit intoapache:masterfrom
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.
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
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 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 option with documentationapisix/cli/config.lua: Added default value (0) for the new config optionapisix/router.lua: Reads config and passesrouter_rebuild_min_intervalto all router modules (HTTP + stream)apisix/http/router/radixtree_uri.lua: Added min_interval check before router rebuildapisix/http/router/radixtree_host_uri.lua: Added min_interval check before router rebuildapisix/http/router/radixtree_uri_with_parameter.lua: Added min_interval check before router rebuildapisix/stream/router/ip_port.lua: Added min_interval check before router rebuildt/router/router-rebuild-min-interval.t: Test cases covering default behavior (interval=0), skip behavior, and deferred rebuild after interval expiryBackward Compatibility
Default value is
0, which preserves the existing behavior of rebuilding immediately on every route change. No existing configurations are affected.