For one connection, one worker thread do all the io (read, write), my question is, since socket is a <span class="Apple-style-span" style="font-family: sans-serif; font-size: 13px; line-height: 19px; ">bidirectional protocol, if using one thread for read, another thread for write, will it result in a better response time? especially in situation: few connections but more cpu cores.</span><br>
<br><div class="gmail_quote">On Tue, Mar 23, 2010 at 7:46 PM, Marzullo <span dir="ltr">&lt;<a href="mailto:coder82@gmail.com">coder82@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
You know, I wrote such question after I&#39;ve read about boss thread and worker<br>
thread in case of NIO socket and OIO socket, if you look up the doc, it<br>
gives the idea. The point is:<br>
<br>
OIO socket:<br>
Boss thread accepts for connections, when connection is accepted (3 way<br>
handshake completed in case of TCP), it creates a channel which represents<br>
the accepted connection itself. This channel is handed to a worker thread<br>
(often referred as I/O thread) got from thread pool. On such threads, I/O<br>
operations are blocking. If you ever implemented a server in C, this is very<br>
similar, if not equal to, 1-accepting a socket then 2-create a thread and<br>
3-hand socket descriptor to such thread which will block on reads and<br>
writes, that&#39;s it.<br>
So here the important difference is that you have one accepted channel per<br>
I/O thread and every I/O operation within such thread is blocking.<br>
<br>
NIO socket:<br>
Similar to above, boss thread accepts connection, create channel for such<br>
connection and hands it to worker thread. The difference is here, you can<br>
have more than one channel handed to worker thread, then of course I/O must<br>
be non blocking otherwise by blocking on one channel you&#39;d starve the<br>
others...<br>
So here is the point when I read on the docs:<br>
<br>
&quot;If await()  is called by an event handler method, which is called by the<br>
I/O thread, the I/O operation it is waiting for might never be complete<br>
because await()  can block the I/O operation it is waiting for, which is a<br>
dead lock. &quot;<br>
<br>
so if you wait withing such worker thread (I/O thread) you might<br>
starve/lower responsiveness on other channels or even cause deadlock<br>
depending on what you actually do.<br>
<br>
It&#39;d be nice to have clarifications from T. Lee about all this.<br>
Thanks.<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://n2.nabble.com/Fast-question-about-threading-inside-Netty-tp4765193p4783431.html" target="_blank">http://n2.nabble.com/Fast-question-about-threading-inside-Netty-tp4765193p4783431.html</a><br>

Sent from the Netty User Group mailing list archive at Nabble.com.<br>
_______________________________________________<br>
netty-users mailing list<br>
<a href="mailto:netty-users@lists.jboss.org">netty-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
</font></blockquote></div><br>