Il giorno 05/giu/2012, alle ore 11:30, Tarek Ziadé ha scritto: > Hey > > I am doing this experimentation where the WGSI server is not started with an > host/port or a unix socket, but rather a FD value, > corresponding to a socket already bound by the parent process. > > The server would then just accept new connection on the FD, using > socket.fromfd() to get a socket object back, > and forget about all the binding work. > > Here's a prototype based on wsgiref : > https://github.com/tarekziade/chaussette > > The goal I have is to be able to just spawn web workers using subprocess and > take care myself of the process > management part. I wrote a blog post on my motivations here : > http://blog.ziade.org/2012/06/12/shared-sockets-in-circus > if you want more background. > > Anyways, the idea I wanted to bring here was the following: > > most web servers out there support regular host/port or Unix Socket, which > are usually the "unix:" prefix followed by a path on the system. > > What if web servers had these two standards *and* a new one which would be a > "fd:" prefix. > > For instance, we would start server foo with: > > $ foo --fd:12:localhost:8080 > > Where 12 is the fd number the foo server would use for getting the socket, > and "localhost:8080" would just be there > as an information to be able to fill some WGSI headers that requires it. > > From there I could just spawn "foo" and pass to it socket.fileno() > > Thoughts ? >
This is the approach used by fastcgi (even if only on file descriptor 0), old inetd-style daemons, and newer upstart and systemd daemons. Gunicorn can already bind (or better, accept) from file descriptors specifying an environment variable. uWSGI supports by-default the inheritance of file descriptor 0 for fcgi-like startup, and working on generic file descriptor or inet/upstart/systemd socket activation. The vast majority of modern systems expects the file descriptor number on an environment variable: upstart: UPSTART_FDS systemd: LISTEN_FDS Circus, could follow the same behaviour, but i do not know if a standard will be required for that. Regarding the --fd:12:localhost:8080 syntax, is redundant as you can get the name of the socket mapped to a file descriptor with getsockname: http://linux.die.net/man/2/getsockname -- Roberto De Ioris http://unbit.it JID: robe...@jabber.unbit.it _______________________________________________ Web-SIG mailing list Web-SIG@python.org Web SIG: http://www.python.org/sigs/web-sig Unsubscribe: http://mail.python.org/mailman/options/web-sig/archive%40mail-archive.com