I know the compare to nodejs doesn't mean anything because of different 
mechanism.

I just want to find out what is the best way to use select, specially in a 
for loop.

And in my messageLoop case, perhaps I have to reduce the number of channels 
in the select, and make multiple kind of events route to only one channel.


在 2017年2月6日星期一 UTC+8上午3:00:15,fwan...@gmail.com写道:
>
> I make a test to see the performance of select, and found the result is 
> not good.
>
> I make 1000 SeqQueue objects and run its messageLoop function (which does 
> a small piece of work, and is listed as below) in 1000 separate go 
> routines. The CPU cost is more than 20%.
> If I make the ticker 1 second, the CPU cost can slow down to about 2%.
>
> With pprof, I see the most top cost are methods related to 
> runtime.selectGo, runtime.lock.
>
> Who knows is there anything wrong in my case?
>
> func (this *SeqQueue) messageLoop() {
> var ticker = time.NewTicker(100 * time.Millisecond)
> defer ticker.Stop()
> for {
> select {
> case <-serverDone:
> return
> case <-this.done:
> return
> case <-ticker.C:
> this.tickCounter += 1
> case message := <-this.messages:
> this.messageCounter += 1
> _ = message
> }
> }
> }
>
>
>
>

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