[Twisted-Python] Fork/Spawn children to accept connections on the same port.

Jean-Paul Calderone exarkun at divmod.com
Fri Apr 10 11:57:19 EDT 2009

On Mon, 6 Apr 2009 15:25:39 -0700, Eric York <eyork at apple.com> wrote:
>I am trying to get the highest level of performance using all of the 
>processors cores on a server.
>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  to do 
>that in Twisted. Can someone point me in the right direction?
>The solution of using a single process to accept connections and then  farm 
>out work to child processes, while a workable solution, isn’t at  the same 
>level of performance as children processes that are doing  their own 

There are many ways to do this.  The common idea is to just run multiple
processes, not by allocating resources and then forking to share them, but
just by running multiple processes.  You can make this transparent to the
outside in various ways - have a load balancing port forwarded in front of
all the processes, for example.  On Linux, you can even use iptables to do
this.  It's also possible to bind a port in one process and then send it
over a UNIX socket to another process; this comes closer to the bind/fork
approach, but accomplishes the resource sharing explicitly via fd passing
rather than through fork.


More information about the Twisted-Python mailing list