[Haskell-cafe] STM, IO and event loops
Simon Marlow
simonmar at microsoft.com
Mon Nov 28 07:20:51 EST 2005
On 28 November 2005 11:47, Joel Reymont wrote:
> On Nov 28, 2005, at 11:32 AM, Simon Marlow wrote:
>
>> On Unix with -threaded, all blocking I/O using Handles or sockets
>> goes via the I/O manager thread, which multiplexes all the blocked
>> I/O requests into a single select() call. If you have 20k blocked
>> socket reads, there will be 20k lightweight Haskell threads, and
>> probably 2 or 3 real OS threads. Without -threaded the outcome is
>> pretty much the same, except the runtime does the select().
>
> I'm not well-versed on the differences between select in the I/O
> manager and the runtime. What is the difference? Should I just plug -
> threaded into my cabal file and not worry about it? How big of an
> impact is select() in the runtime?
When the runtime is doing select(), you'll get more calls to select()
because the runtime calls it for every thread switch, whereas with
-threaded select() is only called when something changes - we need to
wait on a new descriptor, or I/O is available on one or more
descriptors. So you should get better performance with -threaded for
large numbers of descriptors. Also you might get a small amount of
parallelism on a multi-processor because the select() will run on a
different CPU.
I'm aware that there are various better alternatives to select(), but we
don't use any of them yet.
Cheers,
Simon
More information about the Haskell-Cafe
mailing list