So, it appears that for certain syscalls, like reading from a socket, the
runtime uses some kind of polling or pushing provided by the OS allowing it
to free the thread occupied by the goroutine blocked in such a call.
What about the other calls? Is it the present issue only related to cgo? If
not, is it documented which calls cause an OS thread to be blocked when the
goroutine running on it blocks?
I understand, that Go doesn't want to expose much info about the
multiplexing mechanism to the user, but if user code may cause thousands of
OS threads to be created, it should be common knowledge which syscalls do
that.
In Erlang, processes are scheduled preemptively and one OS thread can run
thousands of concurrent processes. It also has an issue with calling to C
code that is linked into the VM -- the scheduler can't preempt the process
before it has returned from the C land. This caveat is known and understood
by Erlang users.
Go has cooperative goroutines that might be not so cooperative depending on
the code they are running. So I think it should be well documented which
use cases cause a goroutine to misbehave. Is it already?
On Mon, Apr 15, 2013 at 5:51 PM, minux wrote:On Mon, Apr 15, 2013 at 9:44 PM, Alexey Palazhchenko <
alexey.palazhchenko@gmail.com> wrote:
I have a Go program which uses multi-threaded C library via cgo. After a
load testing I noticed that program allocates (MemStats.Alloc) 200 MB of
memory. pprof showed only about 2. I dig further and found that there are
4k of OS threads, most of them are sitting at sys_linux_amd64.s:238[1] (Go
1.0.3).
Does Go runtime created those threads to keep up with load? Does Go
(1.0, 1.1) runtime ever shrinks thread pool?
When one goroutine blocks in syscall on one of the OS thread and there is
no available OS thread to
host other ready goroutines, the runtime has no choice but to create
another OS thread.
The Go runtime currently doesn't ever shrink its thread pool.
A related issue:
https://code.google.com/p/go/issues/detail?id=4056for now, you will have to limit the number concurrent OS thread blocking
yourself
(mostly cgo calls, because calling into C world is treated the same as
blocking in
syscall).
--
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+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out. --
Best regards
Alexei Sholik
--
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+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.