[Twisted-Python] Setting socket options before bind/listen

Tobias Oberstein tobias.oberstein at tavendo.de
Mon Feb 3 14:49:06 MST 2014


> >for a multiprocess server, I'd like to set SO_REUSEPORT on a TCP
> >listening socket.
> 
> You might find that https://stackoverflow.com/questions/10077745
> /twistedweb-on-multicore-multiprocessor obviates the need for this option (and
> thus your follow-up features as well).

Jean-Paul,

yes, I am aware of this (awesome) answer;) This works, but has 2 slightly
undesirable aspects:

1) it requires to have a master process that creates the socket and starts workers
which "adopt" the port. I'd like to be able to fire up workers independently .. with
no master at all.

2) the distribution of incoming connections to workers isn't completely uniformly
distributed across workers.

This problem is explained here (they report up to 3:1 ratios of connections per worker):
https://lwn.net/Articles/542629/
https://lwn.net/Articles/542718/

and I could verify this during some experiments (though not such extreme non-uniformity)

> 
> Not that Twisted shouldn't offer some way to gain more control over this kind
> of platform-specific option.  But, until it does...

I guess that means there is no "recommended" way currently;)

Would you mind giving a tip on how to make use of a CustomPort deriving
of Port? How to "plug" that into Twisted?

Thanks!
/Tobias

> 
> Jean-Paul
> >The option needs to be set _before_ calling bind() and listen() on the
> >socket.
> >
> >Is there a recommended way of doing this?
> >
> >One option might be subclassing `twisted.internet.tcp.Port` and
> >overriding `createInternetSocket` - is that recommended?
> >
> >And if so: how do I make the CustomPort be used with
> >reactor.listenTCP/listenSSL and endpoints?
> >
> >Any hints appreciated, thanks!
> >
> >/Tobias
> >
> >_______________________________________________
> >Twisted-Python mailing list
> >Twisted-Python at twistedmatrix.com
> >http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
> 
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python



More information about the Twisted-Python mailing list