Aias00 opened a new issue, #7825: URL: https://github.com/apache/shenyu/issues/7825
## Goal Evaluate publishing concurrency-safe, read-only upstream-list snapshots so routing requests do not need to copy the entire healthy-upstream list on every lookup. Performance baseline/tracking: #7650. Reviewed revision: `04f7c2e8b7d282f14510157a9ab0bfaab538ecac` (`2.7.2-SNAPSHOT`). Allocation/copy behavior is confirmed in source; an application-level performance gain has not been measured. ## Current request-path cost [UpstreamCacheManager.findUpstreamListBySelectorId():128–130](https://github.com/apache/shenyu/blob/04f7c2e8b7d282f14510157a9ab0bfaab538ecac/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/cache/UpstreamCacheManager.java#L128-L130) returns `new ArrayList<>(upstreamList)` for each lookup. Divide requests call this before breaker filtering and load balancing; failover can perform additional lookups. This creates a list and backing-array copy proportional to the selector's upstream count for each request. A single-target, low-rate route will have a much smaller potential benefit than a high-rate selector with many targets. ## Required safety boundary The copy protects callers from mutable health-check state. #6857 previously addressed exposing a concurrently mutated ArrayList. Simply returning the existing shared list, or wrapping a still-mutated backing list, is not an acceptable optimization. A candidate design should move structural copying/publication to configuration/health-state updates and expose a coherent read-only snapshot to readers. Upstream elements themselves contain mutable weight/health metadata: structural list immutability alone does not settle element visibility, identity or update semantics. ## Scope and acceptance criteria - [ ] Establish routing-read and update/health-transition baselines for 1, 10, 100 and larger justified upstream counts; measure allocation/request, CPU, GC and p99 at equal successful throughput. - [ ] Include concurrent health transitions, weight/metadata changes and configuration churn; measure write-side cost as well as read-side benefit. - [ ] Define snapshot ownership/publication and ensure no mutable backing list is exposed across threads. - [ ] Preserve handling of missing/empty lists, target identity, manual offline status, health-check enable/disable, failover and circuit-breaker filtering. - [ ] Regression-test concurrent readers/writers and ensure removed targets do not remain routing candidates. Coordinate with #7791's existing cache-reconciliation correctness work rather than treating stale targets as acceptable snapshot semantics. - [ ] Audit consumers that may mutate returned collections and adapt them without allowing shared-state mutation. - [ ] Compare identical workloads before/after; retain the change only with demonstrated benefit and no unacceptable update-time/p99 regression. ## Related work #6857 is the prior concurrency bug and explains why the current copy must not be deleted without a replacement publication model. #7791 addresses full configuration replacement correctness; #7815 addresses missing Admin delete notifications. This task is specifically the request-side list-copy cost after correctness is preserved. -- 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]
