[Haskell-cafe] System calls and Haskell threads

2011-11-03 Thread Andreas Voellmy
I just read Kazu Yamamoto's article on a high performance web server in the
latest Monad.Reader, and I came across a statement that doesn't sound
correct to me. He says:

When a user thread issues a system call, a context switch occurs. This
means that all Haskell user threads stop, and instead the kernel is given
the CPU time. 

Is this right? I thought that when a system call is made by a Haskell
thread being run by a particular worker thread on a CPU, other runnable
Haskell threads in the run queues of the HECs for other CPUs can continue
running concurrently (provided we've run our Haskell program with multiple
CPUs using the -Nx RTS argument). That's what I understood from the
discussion of foreign calls in Runtime Support for Multicore Haskell.

Andreas
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] System calls and Haskell threads

2011-11-03 Thread Johan Tibell
On Thu, Nov 3, 2011 at 8:35 AM, Andreas Voellmy
andreas.voel...@gmail.comwrote:

 I just read Kazu Yamamoto's article on a high performance web server in
 the latest Monad.Reader, and I came across a statement that doesn't sound
 correct to me. He says:

 When a user thread issues a system call, a context switch occurs. This
 means that all Haskell user threads stop, and instead the kernel is given
 the CPU time. 

 Is this right? I thought that when a system call is made by a Haskell
 thread being run by a particular worker thread on a CPU, other runnable
 Haskell threads in the run queues of the HECs for other CPUs can continue
 running concurrently (provided we've run our Haskell program with multiple
 CPUs using the -Nx RTS argument). That's what I understood from the
 discussion of foreign calls in Runtime Support for Multicore Haskell.


That's correct. Blocking syscalls will not prevent other Haskell threads
from running. IIRC it will block the OS thread used to run the Haskell
thread making the blocking syscall, but the RTS always has one free OS
thread (i.e. it will allocated more if needed) that it can use to continue
running other Haskell threads with. Your best reference is probably
Extending the Haskell Foreign Function Interface with Concurrency.

-- Johan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] System calls and Haskell threads

2011-11-03 Thread David Barbour
On Thu, Nov 3, 2011 at 8:35 AM, Andreas Voellmy
andreas.voel...@gmail.comwrote:

 I just read Kazu Yamamoto's article on a high performance web server in
 the latest Monad.Reader, and I came across a statement that doesn't sound
 correct to me. He says:

 When a user thread issues a system call, a context switch occurs. This
 means that all Haskell user threads stop, and instead the kernel is given
 the CPU time. 

 Is this right?


It is correct in context. Mighttpd does not use the -Nx argument to create
multiple OS threads, instead uses a `prefork` model that creates separate
processes to balance user invocations. Using multiple processes instead of
multiple Haskell threads avoids issues with garbage collection.

Regards,

Dave
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] System calls and Haskell threads

2011-11-03 Thread David Barbour
On Thu, Nov 3, 2011 at 10:22 AM, David Barbour dmbarb...@gmail.com wrote:

 It is correct in context. Mighttpd does not use the -Nx argument to create
 multiple OS threads, instead uses a `prefork` model that creates separate
 processes to balance user invocations. Using multiple processes instead of
 multiple Haskell threads avoids issues with garbage collection.


I should rephrase that: using multiple processes in place of -Nx threads
avoids issues with GC. Mighttpd does use multiple Haskell threads per
Haskell process.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe