On 2017-07-14, 06:15, golang-nuts@googlegroups.com on behalf of Chifeng Chou 
wrote:

>    I implemented a weighted fair queue using a naive approach which is giving 
> different amount of attempts according to weights to access upstreams.
>    However, when calls of fetch() come very fast, our internal sync 
> constructs are not ready(when
>    select) and many attempts are simply wasted.

Indeed, busy looping here is a bad idea. Look at reflect.Select for a better 
way to do selects with a dynamic set of channels.

The reason you are not seeing your expected distribution is that the sender 
goroutine is sending values on the two channels alternatingly – c1, c2, c1, c2, 
etc. Your reader is racing against this and can sometimes keep up. The only 
possible distribution when the receiver is in pace with the sender is 50/50, 
regardless of weighting gymnastics.

//jb

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to