Nas01010101 commented on PR #3426:
URL: https://github.com/apache/brpc/pull/3426#issuecomment-5302588579

   @chenBright switched to `upper_bound(random_weight)`. You are right that it 
says the thing directly — the comment is down to two lines now and there is no 
increment left to re-check.
   
   The two forms select the same server for every input. `server_compare` 
orders by `current_weight_sum`, so `upper_bound` calls it as `random_weight < 
prefix(i)` and lands on the first prefix strictly greater than `random_weight`, 
which is what `lower_bound(random_weight + 1)` was computing. I checked it 
exhaustively over every value of `random_weight` in `[0, weight_sum)` for a set 
of weight layouts (all-equal, ascending, one dominant server, single server, 
and a two-server case): 0 disagreements between the two forms, 13 disagreements 
against the pre-fix `lower_bound(random_weight)`, and each server owns exactly 
`weight` values of `random_weight`.
   
   On the overflow point — it is moot now, but it could not fire before either: 
`random_weight` comes from `fast_rand_less_than(weight_sum)` so it is at most 
`weight_sum - 1`, and `weight_sum` is a `uint64_t` accumulated from `uint32_t` 
weights.
   
   Also fixed the tolerance comment @Copilot flagged in the test. With 
`run_times=40000` and `p=0.25`, sigma is `sqrt(n*p*(1-p))` = 86.6, so the 
0.9x~1.1x band is about 11 sigma, not more than 20. The comment now shows the 
arithmetic instead of asserting a number.


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to