Palaiologos1453 opened a new pull request, #11476: URL: https://github.com/apache/rocketmq/pull/11476
### Which Issue(s) This PR Fixes Fixes #10982 ### Brief Description `getRouteInfoByTopic` currently copies route data and encodes it for every query. Add an opt-in cache of encoded responses so repeated queries of stable routes reuse the response body. - `routeInfoCacheMaxBytes` defaults to `0` (disabled), is startup-only, and bounds retained encoded bodies, keys and estimated entry overhead. Oversized responses remain uncached. Cache misses populate only the requested JSON variant; both variants share the weight budget. - Effective route mutations advance a global revision. Unchanged registrations and heartbeats preserve the cached response. Registration performs no cache traversal/rebuild. Misses detach mutable data under the existing read lock and serialize outside it. A fill racing a completed mutation cannot be reused under the newer revision. - Read `orderTopicConf` from KV on each query and validate its value and the acting-master setting on hits. Zone filtering transforms a decoded copy and does not alter the shared cache body. - FIFO capacity maintenance runs only on fills; hits do not acquire an eviction lock or enqueue access records. Entries refresh on lookup after five minutes. The bound is a cache weight budget, not an exact JVM heap cap. This takes a deliberately conservative approach to #4246: no eager route cache rebuilding in broker registration, default off, and a fixed memory budget. The global revision can lower hit rates when unrelated routes change; an undersized cache can churn and be slower than uncached lookup. The docs describe these limits. This is a first implementation for design review, not a claim that all large-cluster cases are solved. ### How Did You Test This Change? - **JDK 8:** `mvn -B -f namesrv/pom.xml verify -Djacoco.skip=true` — **136 tests, 0 failures/errors/skips; Checkstyle and SpotBugs passed**. No SpotBugs suppression was added. JaCoCo was disabled for these local runs. - **JDK 17:** 27 final route/cache/request/zone tests passed. The full suite has an existing `RequestProcessorTest` reflective access to `Field.modifiers` that fails on this JDK; the full successful verification above used JDK 8. - **License check:** `mvn -B -f namesrv/pom.xml apache-rat:check` passed (0 unapproved/unknown files). - Tests cover repeated-response reuse, unchanged registration/heartbeat, queue/address/zone/filter changes, topic deletion/recreation, permission changes, static mappings, acting-master transitions, KV ordering changes, JSON selection, aggregate capacity/oversized responses, lazy variant merging, zone hook isolation, interrupted misses, and a fill deliberately paused across completed topic deletion. That last case also checks serialization does not hold the route read lock. **Local JMH** (Windows x86_64, Ryzen 9 7945HX, OpenJDK 17.0.17, JMH 1.19, fixed 512 MiB heap, 8 brokers / 10,000 queried topics; 2 forks, 3 × 1s warmup, 3 × 1s measurement, 1 thread, `-prof gc`): | Method | Cache | ns/op | JMH 99.9% error | B/op | | --- | --- | ---: | ---: | ---: | | Query | disabled | 1,982.5 | 136.8 | 5,816.5 | | Query | 64 MiB | 32.8 | 8.9 | < 0.001 | | Registration | original upstream class | 1,049,852.9 | 697,579.0 | 320,540.3 | | Registration | disabled | 828,471.8 | 319,719.4 | 320,497.4 | | Registration | 64 MiB | 689,833.4 | 316,458.7 | 320,498.9 | The registration uncertainty intervals overlap; no registration speedup is claimed. The upstream control loads `RouteInfoManager` compiled from base commit `57c2dc04` ahead of the benchmark classpath. Registration payload versions change while effective routes remain equivalent. A 4-reader / 1-registration group also completed; its subgroup results, raw query iteration means and reproduction instructions are in `docs/en/namesrv-route-cache.md`. The cache fits the working set in the reported hit-path results. These are method-level measurements, not end-to-end throughput or a 300-broker-scale validation. -- 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]
