Thinking about this overnight I think this benchmark

https://play.golang.org/p/5d4MUKqPYd

Shows the issue you are having. On my machine

% go test -bench=. -benchtime=5s 
BenchmarkWithoutLockOSThread-4 5000 1827196 ns/op 
BenchmarkWithLockOSThread-4 200 31506649 ns/op

My guess is the LockOSThread version causes a context switch because the 
thread the sending goroutine runs on must be parked, and the receiving 
thread locked to the receiving goroutine must be woken to drain the value. 

I don't see an easy workaround for this slowdown.

On Tuesday, 22 November 2016 22:43:34 UTC+11, Cia wrote:
>
> I have been tested Cgo's perf and here is the result below:
>
> chan:
> 1000,0000 op/s (buffer 100)
> 400,0000 op/s (no buffer,blocked)
>
> cgo:
> 554,4729 op/s
>
> It shows that the speed of Cgo is acceptable,and even without thinking 
> about the batch optimization method when using it *:)*
>
> On Tuesday, 22 November 2016 19:30:55 UTC+8, Dave Cheney wrote:
>>
>> The cgo call is going to cost you a lot more than this. Can you write up 
>> your real code and profile it.
>>
>> On Tuesday, 22 November 2016 22:11:34 UTC+11, Cia wrote:
>>>
>>>
>>>
>>> On Tuesday, 22 November 2016 18:51:46 UTC+8, Dave Cheney wrote:
>>>>
>>>> Why do you want to use LockOSthread, you've proved it has a significant 
>>>> performance cost for your application.
>>>
>>>
>>>  *Cgo* is the answer.....
>>>
>>> (Actually I want to use a C library(which needs LockOSthread to reach 
>>> local constant thread execution model) through Cgo in the Go 
>>> application.And one of the biggest benefits of Go is the Channel's event 
>>> notification mechanism which is on the user space and powerful.It could be 
>>> used to create a sync & nonblock application easily.)
>>>
>>> Is this a expected performance penalty when we use channel with 
>>> LockOSthread?(Maybe due to a design tradeoff or anything)
>>>
>>> (: Just want to figure it out and be sure the exclusion of the 
>>> probability of some bugs maybe hidden on this test codes here :)
>>>
>>>

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