Hi,
There is a known problem in runtime with contention related to
handling of syscalls. My scheduler patch contains the following
solution (
https://codereview.appspot.com/6441097/diff/51001/src/pkg/runtime/proc.c,
see sysmon() func). Dedicated background thread checks status of all
threads every 20mks, if a thread is in the same syscall for more than
20mks, the background thread wakes up another worker thread to execute
Go code (assuming that the first thread is blocked).
There are several problems with the approach. It's based on magical
constants, that may work well for one workload/platform and badly for
another workload/platform. The background thread consumes CPU time all
the time, AFAIR on Mac it consumes ~10% and ~5% in Linux, the
background thread can be parked if the program itself does nothing,
but it's not implemented yet. The approach does not actually detect
blocking, the syscall/cgo call can actually be computing something.
What do you think about explicitly saying that net read/write syscalls
and possibly some others (connect/accept) do not block? For cgo we can
implement some annotations that say that the call does not block. Then
runtime does not need to guess whether the call blocks or not. It has
the advantage of being simple and reliable for all
workloads/platforms. + a user can mark as nonblocking cgo calls that
do long computations. + it's probably that simple that we can
implement it before Go1.1. Later we can implement an automatic
solution and disregard the cgo annotations, so it does not burn the
bridges.