вторник, 22 ноября 2016 г., 23:47:51 UTC+3 пользователь Ian Lance Taylor написал: > > On Tue, Nov 22, 2016 at 12:37 PM, Dave Cheney <da...@cheney.net > <javascript:>> wrote: > > 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. > > I also have come to think it may be due to thread context switching. > > Still, I also wrote up a benchmark, and I filed > https://golang.org/issue/18023. > > Ian >
For the reference: the context switching, and thus associated slowdown, can be potentially avoided with proper Go scheduler tuning. More, since lockOSThread is used at every CGo call by Go runtime internally, similar slowdown might be also showing on servers which use CGo when handling requests. Details: https://github.com/golang/go/issues/21827 Kirill -- 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.