Repository navigation
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
ShortestResponseLoadBalancer computes succeededAverageElapsed * inflight, but neither its selection path nor Divide's shortestResponse completion path updates inflight. A fresh upstream starts at 1, so this usually compares historical successful average latency only. A historically fast upstream continues to receive requests even as its pending queue grows.
Expected Behavior
Maintain outstanding request accounting for this strategy, paired across request start and all terminal signals, so increasing concurrency affects the estimate.
Steps To Reproduce
Create two healthy upstreams A and B with equal positive weights. Set both inflight values to 1, and initialize successful response metrics:
a.getSucceeded().set(1);
a.getSucceededElapsed().set(10);
b.getSucceeded().set(1);
b.getSucceededElapsed().set(100);
var balancer = new ShortestResponseLoadBalancer();
int aHits = 0;
for (int i = 0; i < 100; i++) {
if (balancer.select(List.of(a, b), new LoadBalanceData()) == a) {
aHits++;
}
}
System.out.println(aHits); // observed: 100
System.out.println(a.getInflight().get()); // observed: 1Do not complete requests between selections. The result was reproduced against the commit below. In Divide, the shortestResponse callback only records successful elapsed time and count; it does not fix the missing inflight accounting.
Anything else?
- Selection:
Lines 43 to 49 in 862f5e3
boolean sameWeight = true; for (int i = 0; i < upstreamList.size(); i++) { Upstream upstream = upstreamList.get(i); AtomicLong inflight = upstream.getInflight(); // Calculate the estimated response time from the product of active connections and succeeded average elapsed time. long estimateResponse = upstream.getSucceededAverageElapsed() * inflight.get(); - Completion metrics:
Lines 201 to 208 in 862f5e3
Mono<Void> response = Mono.defer(() -> chain.execute(exchange)); if (ruleHandle.getLoadBalance().equals(P2C)) { response = response.doFinally(signalType -> responseTrigger(upstream)); } else if (ruleHandle.getLoadBalance().equals(SHORTEST_RESPONSE)) { long beginTime = System.currentTimeMillis(); response = response.doOnSuccess(e -> successResponseTrigger(upstream, beginTime)); } return probe ? response : UpstreamCircuitBreaker.recordOutcome(response, breakerKey); - Related but different issue: [BUG] DividePlugin.beginTime is a shared mutable instance field, racy under shortestResponse load balancing #6544 addressed the start-time race, not missing inflight accounting.
Environment
- ShenYu: master, 2.7.2-SNAPSHOT
- Commit:
862f5e37e894bd8cef85ef540a8629f313e9ecdf - Java 17
Activity
fix(loadbalancer): track inflight for shortestResponse (apache#7973)
fix(loadbalancer): track inflight for shortestResponse (apache#7973)
fix(loadbalancer): track inflight for shortestResponse (apache#7973)
fix(loadbalancer): track inflight for shortestResponse (apache#7973) (a…