I attached the code. Build and run it, and look the cpu usage. Each time when comment out one of serverDone case, the cpu usage will down about 5% in my book. When all the serverDone case are commented out, the cpu is still about 5%, not good compared to nodejs.
在 2017年2月6日星期一 UTC+8上午3:16:15,Ian Lance Taylor写道: > > On Sun, Feb 5, 2017 at 12:11 AM, <fwan...@gmail.com <javascript:>> > 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.
main.go
Description: Binary data