You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "membphis (via GitHub)" <gi...@apache.org> on 2026/03/05 06:04:59 UTC

[PR] feat: add router_rebuild_min_interval to reduce CPU spikes from frequ… [apisix]

membphis opened a new pull request, #13073:
URL: https://github.com/apache/apisix/pull/13073

   ## 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_interval` option 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
   
   ```yaml
   apisix:
     router:
       http: radixtree_host_uri
       ssl: radixtree_sni
       router_rebuild_min_interval: 0  # default: 0 (rebuild immediately, current behavior)
   ```
   
   ### Expected Impact
   
   | Scenario (30s duration) | min_interval: 0 | min_interval: 1 | min_interval: 5 |
   |---|---|---|---|
   | 20 changes/sec | 600 rebuilds | ~31 rebuilds | ~7 rebuilds |
   | 50 changes/sec | 1500 rebuilds | ~31 rebuilds | ~7 rebuilds |
   | 1 change/3sec | 10 rebuilds | 10 rebuilds | 10 rebuilds |
   
   ### Changes
   
   - **`conf/config.yaml.example`**: Added `router_rebuild_min_interval` config option
   - **`apisix/cli/config.lua`**: Default value `0`
   - **`apisix/router.lua`**: Reads config and passes to HTTP router modules (+3 lines)
   - **`apisix/http/router/radixtree_uri.lua`**: Min interval check before rebuild
   - **`apisix/http/router/radixtree_host_uri.lua`**: Min interval check before rebuild
   - **`apisix/http/router/radixtree_uri_with_parameter.lua`**: Min interval check before rebuild
   - **`t/router/router-rebuild-min-interval.t`**: Test cases covering default behavior, skip behavior, and deferred rebuild
   
   ### Backward Compatibility
   
   Default value is `0`, preserving the existing behavior of rebuilding immediately on every route change. No existing configurations are affected.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: add router_rebuild_min_interval to reduce CPU spikes from frequ… [apisix]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #13073: feat: add router_rebuild_min_interval to reduce CPU spikes from frequ…
URL: https://github.com/apache/apisix/pull/13073


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: add router_rebuild_min_interval to reduce CPU spikes from frequ… [apisix]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #13073:
URL: https://github.com/apache/apisix/pull/13073#issuecomment-4466586627

   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 is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: add router_rebuild_min_interval to reduce CPU spikes from frequ… [apisix]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #13073:
URL: https://github.com/apache/apisix/pull/13073#issuecomment-4698307310

   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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: add router_rebuild_min_interval to reduce CPU spikes from frequ… [apisix]

Posted by "moonming (via GitHub)" <gi...@apache.org>.
moonming commented on PR #13073:
URL: https://github.com/apache/apisix/pull/13073#issuecomment-4064897075

   **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:
   
   - **This PR**: `router_rebuild_min_interval` — throttle/debounce rebuilds (quick win, low risk)
   - **#12826**: Incremental compilation — only rebuild affected parts of the radix tree (fundamental fix, higher complexity)
   
   **Proposed path forward**:
   1. Merge this throttling approach first as an immediate relief (low risk, easy to understand)
   2. Continue developing incremental compilation as a longer-term optimization
   3. The two approaches are complementary — throttling reduces frequency, incremental reduces cost per rebuild
   
   Will coordinate with @apaloleg on #12826 to align timelines.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org