On Sun, Feb 5, 2017 at 12:11 AM,  <fwang2...@gmail.com> wrote:
> 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
> }
> }
> }

It's unfortunately impossible to reasonably analyze a microbenchmark
from an incomplete code fragment.  Please post a complete program,
ideally written as a Benchmark (as described at
https://golang.org/pkg/testing/).

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.

Reply via email to