membphis opened a new pull request, #13069:
URL: https://github.com/apache/apisix/pull/13069
## 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 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 with documentation
- **`apisix/cli/config.lua`**: Added default value (0) for the new config
option
- **`apisix/router.lua`**: Reads config and passes
`router_rebuild_min_interval` to all router modules (HTTP + stream)
- **`apisix/http/router/radixtree_uri.lua`**: Added min_interval check
before router rebuild
- **`apisix/http/router/radixtree_host_uri.lua`**: Added min_interval check
before router rebuild
- **`apisix/http/router/radixtree_uri_with_parameter.lua`**: Added
min_interval check before router rebuild
- **`apisix/stream/router/ip_port.lua`**: Added min_interval check before
router rebuild
- **`t/router/router-rebuild-min-interval.t`**: Test cases covering default
behavior (interval=0), skip behavior, and deferred rebuild after interval expiry
### Backward Compatibility
Default value is `0`, which preserves 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]