On Fri, Jul 14, 2017 at 2:54 AM, Chifeng Chou <cfc...@gmail.com> wrote:
> The reason why using select instead ok-comma is because I don't one upstream
> to block another. Using blocking ok-comma is ok when upstreams are fast.
> However, when one is slow, others could starve.

I see.  Well, the approach you are using clearly can not work.  It's a
racy busy loop.  Don't do that.

What are you really trying to do?

If you simply want to weight one channel more heavily, and
unpredictable behavior is OK, you can simply write

select {
case i := <-c1:
    ...
case i := <-c2, i := <-c2:
    ...
}

That will give you two chances at c2 for each one at c1.

Ian


> On Friday, July 14, 2017 at 12:46:27 PM UTC+8, Ian Lance Taylor wrote:
>>
>> On Thu, Jul 13, 2017 at 9:15 PM, Chifeng Chou <cfc...@gmail.com> 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.
>> > It seems that Go's scheduler steps in, therefore the results of many
>> > scenarios are not always predictable.
>> >
>> > The involvement of Go's scheduler seems unavoidable. So is it innately
>> > unfit
>> > to implement WFQ in this way?
>>
>> I don't understand why you are using a select statement with a default
>> case.
>>
>> Just use the comma-ok form to read from the channel, as in
>> https://play.golang.org/p/OqK0nELGcX .
>>
>> Ian
>
> --
> 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.

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