[Web-SIG] Proposed WSGI extensions for asynchronous servers

Manlio Perillo manlio_perillo at libero.it
Tue May 13 14:51:58 CEST 2008

James Y Knight ha scritto:
> On May 11, 2008, at 6:15 PM, Christopher Stawarz wrote:
>> Abstract
>> --------
>> This specification defines a set of extensions that allow WSGI
>> applications to run effectively on asynchronous (aka event driven)
>> servers.
>> Rationale
>> ---------
>> The architecture of an asynchronous server requires all I/O
>> operations, including both interprocess and network communication, to
>> be non-blocking.  For a WSGI-compliant server, this requirement
>> extends to all applications run on the server.  However, the WSGI
>> specification does not provide sufficient facilities for an
>> application to ensure that its I/O is non-blocking.  Specifically,
>> there are two issues:
>> * The methods provided by the input stream (``environ['wsgi.input']``)
>>  follow the semantics of the corresponding methods of the ``file``
>>  class.
>> * WSGI does not provide the application with a mechanism to test
>>  arbitrary file descriptors (such as those belonging to sockets or
>>  pipes opened by the application) for I/O readiness.
> There are other issues. How do you do a DNS lookup? How do you get 
> process completion notification? Heck, how do you run a process? Once 
> you have I/O readiness information, what do you do with that? I guess 
> you'd need to write a whole new asynchronous server framework on top of 
> AWSGI? I can't see being able to use it "raw" for any real applications.

This is not a problem with AWSGI.
As an example there are libraries like PostgreSQL and curl that can be 
used with an external event loop.

In the WSGI implementation for Nginx I can provide an interface for 
using the builtin supporto for asynchronous DNS client.

>> The first argument, ``fd``, is either an integer representing a file
>> descriptor or an object with a ``fileno`` method that returns such an
>> integer.  (In addition, ``fd`` may be ``x-wsgiorg.async.input``, even
>> if it lacks a ``fileno`` method.)  The second, optional argument,
>> ``timeout``, is either ``None`` or a floating-point value in seconds.
>> If omitted, it defaults to ``None``.
> What if the event-loop of the server doesn't use integer fds, but 
> windows file handles or a java channel object? Where are you allowed to 
> get these integers from? Is it always a socket from 
> socket.socket().fileno()? Or can it be a file from open().fileno() or 
> os.open()? A pipe from os.pipe()? Note that these distinctions are 
> important everywhere but UNIX.

This has the same problems that we have with wsgi.file_wrapper.

This is the reason, among other things, why the API in my implementation 
uses ngx.connection_wrapper and ngx.poll_register

 > [...]

Manlio Perillo

More information about the Web-SIG mailing list