<br><font size=2 face="sans-serif">Hello,</font>
<br>
<br><font size=2 face="sans-serif">&nbsp; Just writing to let people know
the resolution of this problem...</font>
<br>
<br><font size=2 face="sans-serif">&nbsp; After much frustration and toil,
we realized there was a bug in GHC's handle abstraction over sockets. </font>
<br>
<br><font size=2 face="sans-serif">&nbsp; We resolved our immediate problem
by having our code deal directly with the sockets, and we filed a bug report,
#2703, which has just been (partially fixed) by Simon Marlow. </font>
<br>
<br><font size=2 face="sans-serif">thanks,</font>
<br><font size=2 face="sans-serif">&nbsp; Jeff</font>
<br>
<br><tt><font size=2>Simon Marlow &lt;simonmarhaskell@gmail.com&gt; wrote
on 10/10/2008 09:23:31 AM:<br>
<br>
&gt; Jeff Polakow wrote:<br>
&gt; <br>
&gt; &gt; Don Stewart &lt;dons@galois.com&gt; wrote on 10/09/2008 02:56:02
PM:<br>
&gt; &gt; <br>
&gt; &gt; &nbsp;&gt; jeff.polakow:<br>
&gt; &gt; &nbsp;&gt; &gt; &nbsp; &nbsp;We have a server that accepts messages
over a socket, spawning <br>
&gt; &gt; threads to<br>
&gt; &gt; &nbsp;&gt; &gt; &nbsp; &nbsp;process them. Processing these messages
may cause other, outgoing<br>
&gt; &gt; &nbsp;&gt; &gt; &nbsp; &nbsp;connections, to be spawned. Under
sufficient load, the main <br>
&gt; &gt; server loop<br>
&gt; &gt; &nbsp;&gt; &gt; &nbsp; &nbsp;(i.e. the call to accept, followed
by a forkIO), becomes <br>
&gt; &gt; nonresponsive.<br>
&gt; &gt; &nbsp;&gt; &gt;<br>
&gt; &gt; &nbsp;&gt; &gt; &nbsp; &nbsp;A smaller distilled testcase reveals
that when sufficient socket <br>
&gt; &gt; activity<br>
&gt; &gt; &nbsp;&gt; &gt; &nbsp; &nbsp;is occurring, an incoming connection
may not be responded to <br>
&gt; &gt; until other<br>
&gt; &gt; &nbsp;&gt; &gt; &nbsp; &nbsp;connections have been cleared out
of the way, despite the fact <br>
&gt; &gt; that these<br>
&gt; &gt; &nbsp;&gt; &gt; &nbsp; &nbsp;other connections are being handled
by separate threads. One <br>
&gt; &gt; issue that<br>
&gt; &gt; &nbsp;&gt; &gt; &nbsp; &nbsp;we've been trying to figure out
is where this behavior arises <br>
&gt; &gt; from-- the<br>
&gt; &gt; &nbsp;&gt; &gt; &nbsp; &nbsp;GHC rts, the Network library, the
underlying C libraries.<br>
&gt; &gt; &nbsp;&gt; &gt;<br>
&gt; &gt; &nbsp;&gt; &gt; &nbsp; &nbsp;Have other GHC users doing applications
with large amounts of<br>
&gt; &gt; &nbsp;&gt; socket usage<br>
&gt; &gt; &nbsp;&gt; &gt; &nbsp; &nbsp;observed similar behavior and managed
to trace back where it <br>
&gt; &gt; originates<br>
&gt; &gt; &nbsp;&gt; &gt; &nbsp; &nbsp;from? Are there any particular architectural
solutions that <br>
&gt; &gt; people have<br>
&gt; &gt; &nbsp;&gt; &gt; &nbsp; &nbsp;found to work well for these situations?<br>
&gt; &gt; &nbsp;&gt;<br>
&gt; &gt; &nbsp;&gt; Hey Jeff,<br>
&gt; &gt; &nbsp;&gt;<br>
&gt; &gt; &nbsp;&gt; Can you say which GHC you used, and whether you used
the threaded<br>
&gt; &gt; &nbsp;&gt; runtime or non-threaded runtime?<br>
&gt; &gt; &nbsp;&gt;<br>
&gt; &gt; Oops, forgot about that...<br>
&gt; &gt; <br>
&gt; &gt; We used both ghc-6.8.3 and ghc-6.10.rc1 and we used the threaded
<br>
&gt; &gt; runtime. We are running on a 64 bit linux machine using openSUSE
10.<br>
&gt; <br>
&gt; The scheduler doesn't have a concept of priorities, so the accepting
thread <br>
&gt; will get the same share of the CPU as the other threads. &nbsp;Another
issue is <br>
&gt; that the accepting thread has to be woken up by the IO manager thread
when <br>
&gt; a new connection is available, so we might have to wait for the IO
manager <br>
&gt; thread to run too. &nbsp;But I wouldn't expect to see overly long
delays. &nbsp;Maybe <br>
&gt; you could try network-alt which does its own IO multiplexing.<br>
&gt; <br>
&gt; If you have multiple cores, you might want to try fixing the thread
<br>
&gt; affinity - e.g. put all the worker threads on one core, and the accepting
<br>
&gt; thread on the other core. &nbsp;You can do this using GHC.Conc.forkOnIO,
with <br>
&gt; the +RTS -qm -qw options.<br>
&gt; <br>
&gt; Other than that, I'm not sure what to try right now. &nbsp;We're hoping
to get <br>
&gt; some better profiling for parallel/concurrent programs in the future,
but <br>
&gt; it's not ready yet.<br>
&gt; <br>
&gt; Cheers,<br>
&gt; &nbsp; &nbsp;Simon<br>
</font></tt>
<br>
<span style="font-family:'Arial',sans-serif; font-size:8pt; color:#000000">---<br>
<br>
This e-mail may contain confidential and/or privileged information. If you <br>
are not the intended recipient (or have received this e-mail in error) <br>
please notify the sender immediately and destroy this e-mail. Any <br>
unauthorized copying, disclosure or distribution of the material in this <br>
e-mail is strictly forbidden.</span>