Here is the minimal test case 0:

package main


import "fmt"
import "runtime"


type callRet struct {
    ret int
}


type callIn struct {
    ret_chan *chan *callRet
    arg1     int
}


func caller(call_in_c *chan *callIn, arg1 int) int {
    ret_c := make(chan *callRet)
    ci := callIn{&ret_c, arg1}
    *call_in_c <- &ci
    ret := <-ret_c
    return ret.ret
}


func call_srv(call_in_c *chan *callIn) {
    //runtime.LockOSThread()
    for {
        in := <-*call_in_c
        ret_c := in.ret_chan
        ret := callRet{3 + in.arg1}
        *ret_c <- &ret
    }
    //runtime.UnlockOSThread()
}


func main() {
    p := fmt.Println
    runtime.GOMAXPROCS(2)
    call_in_c := make(chan *callIn)


    go call_srv(&call_in_c)


    fp := func(call_in_c chan *callIn) {
        ct := 0
        for ; ct < 10000000; ct = ct + 1 {
            //caller_batch(&call_in_c, 3, 100)
            caller(&call_in_c, 1)
            if ct%1000000 == 0 {
                fmt.Println(ct)
            }
        }
        p("done:)")
    }
    {
        ct := 0
        for ; ct < 0; ct++ {
            go fp(call_in_c)
        }
    }
    fp(call_in_c)
    return
}


It's perf output is about 1000,000 ops/sec :)

But when you uncomment the runtime.LockOSThread() at line 24(the beginning 
at func call_srv),it goes so slow to 10,000/sec and the cpu usage of kernel 
goes into madness.

Is it a normal penalty when you using channel with LockOSThread?

Thanks! ☺

------------
$ go version
go version go1.7 linux/amd64

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