<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><blockquote type="cite"><font class="Apple-style-span" color="#000000"><br></font><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span style="font-family:'Helvetica'; font-size:medium; color:rgba(0, 0, 0, 0.5);"><b>From: </b></span><span style="font-family:'Helvetica'; font-size:medium;">Jean-Paul Calderone &lt;<a href="mailto:exarkun@divmod.com">exarkun@divmod.com</a>&gt;<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span style="font-family:'Helvetica'; font-size:medium; color:rgba(0, 0, 0, 0.5);"><b>Date: </b></span><span style="font-family:'Helvetica'; font-size:medium;">April 10, 2009 8:57:19 AM PDT<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span style="font-family:'Helvetica'; font-size:medium; color:rgba(0, 0, 0, 0.5);"><b>To: </b></span><span style="font-family:'Helvetica'; font-size:medium;">Twisted general discussion &lt;<a href="mailto:twisted-python@twistedmatrix.com">twisted-python@twistedmatrix.com</a>&gt;<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span style="font-family:'Helvetica'; font-size:medium; color:rgba(0, 0, 0, 0.5);"><b>Subject: </b></span><span style="font-family:'Helvetica'; font-size:medium;"><b>Re: [Twisted-Python] Fork/Spawn children to accept connections on the same port. </b><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span style="font-family:'Helvetica'; font-size:medium; color:rgba(0, 0, 0, 0.5);"><b>Reply-To: </b></span><span style="font-family:'Helvetica'; font-size:medium;">Twisted general discussion &lt;<a href="mailto:twisted-python@twistedmatrix.com">twisted-python@twistedmatrix.com</a>&gt;<br></span></div><br><br>On Mon, 6 Apr 2009 15:25:39 -0700, Eric York &lt;<a href="mailto:eyork@apple.com">eyork@apple.com</a>&gt; wrote:<br><blockquote type="cite">I am trying to get the highest level of performance using all of the processors cores on a server.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">In the past, a unix app would bind/listen to a socket and then fork or spawn children to accept connections on that socket. I can’t see how &nbsp;to do that in Twisted. Can someone point me in the right direction?<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">The solution of using a single process to accept connections and then &nbsp;farm out work to child processes, while a workable solution, isn’t at &nbsp;the same level of performance as children processes that are doing &nbsp;their own accepts.<br></blockquote></blockquote><br><blockquote type="cite">It's also possible to bind a port in one process and then send it<br>over a UNIX socket to another process; this comes closer to the bind/fork<br>approach, but accomplishes the resource sharing explicitly via fd passing<br>rather than through fork.<br></blockquote></div><div><br></div><div>This is the path that I would like to follow. I can see how to spawn a child process and pass the fd in Twisted. What I can't see how to do in Twisted is to have a parent process just bind and listen to a socket and have a child process accept on that socket. In twisted/internet/tcp.py in the class Port, there is a function startListening which does bind/listen/startReading all in this one function. It seems that a small&nbsp;refactoring&nbsp;would allow the parent to bind and a child to do&nbsp;startReading, if the call to startReading was moved out of&nbsp;startListening. The reactor calls would also need a&nbsp;small&nbsp;refactoring to allow this type of setup. How does that sound?</div><div><br></div><div>Eric</div><div><br></div></body></html>