Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close

txwsgi README

Introduction

txwsgi is a reference asynchronous implementation of Python Web Server Gateway Interface v1.0 for the Twisted Web server.

The project is a fork of twisted.web.wsgi, but unlike the original implementation, the WSGI application is executed inside the main I/0 thread.

This allows a WSGI application to be seamlessly integrated in Twisted.

Installation

txwsgi is available on BitBucket.

The project requires at least Python 2.5. It has been tested with Twisted 10.0.0.

The package can be installed using easy_install:

easy_install http://bitbucket.org/mperillo/txwsgi/get/tip.tar.gz

txwsgi is currently not available on PyPI.

Features

The purpose of txwsgi is to have a reference implementation of WSGI for an asynchronous web server, in order to use it to easy experiment with asynchronous extensions to the WSGI specification.

txwsgi was not designed to be used in a production environment, and no test suite has been written.

The main features of this WSGI implementation are:

  • Support for Twisted IPushProducer interface.

    When the WSGI application produces (yielding in the application iterator) more data that can be processed by the HTTP channel, the execution of the application is suspended. In source code this is called implicit suspension.

    An example is available in doc/examples/demo_producer.py.

  • Support of the x-wsgiorg.suspend extension.

    This extension is documented in doc/x-wsgiorg.suspend.rst document, and has been proposed for standardization.

    This extension enables explicit suspension support, for WSGI applications. This complements the required implicit suspension support and enables support to asynchronous WSGI applications. With txwsgi it can be used to freely access Twisted API.

    An example is available in doc/examples/demo_getpage.py.

  • Support for direct configuration of WSGI middlewares stack.

    An example is available in doc/examples/demo_producer.py.

  • write callable is not supported, since it can not be implemented in an asynchronous server.

    However support is available via a custom adapter, available in txwsgi.greenlet.write_adapter. The adapter use greenlet to provide support for write callable on top of a WSGI implementation that implements the x-wsgiorg.suspend extension. write_adapter is not enabled by default since most WSGI applications do not require the write callable.

    An example is available in doc/examples/demo_write.py.

  • Experimental support for WSGI applications using greenlet.

    The support is enabled using a custom adapter, available in txwsgi.greenlet.greenlet_adapter and support API. The adapter allows execution of WSGI applications in a greenlet, on top of a WSGI implementation that implements the x-wsgiorg.suspend extension.

    An example is available in doc/examples/demo_getpage_green.py.

Open Issues

(The following issues are not specific to txwsgi implementation.)

Using of x-wsgiorg.suspend extension can affect performance of a WSGI application, increasing request lifetime and worsening average request completion latency. This can be verified with the doc/examples/demo_cooperative.py example.

The same problem is present for asynchronous WSGI applications. This can be verified with the doc/examples/demo_fdevent.py example.

In order to increase perforances, suspensions should be reduced. A good example is doc/examples/demo_getpage.py. Using Twisted features allow the application to only suspend execution one time. This should be compared with the doc/examples/demo_fdevent.py example.

When using greenlets, there is an additional problem: the greenlet context switch.

To summarize, the WSGI application SHOULD minimize both suspensions and greenlet context switches. In case the WSGI implementation is written in C, or the event API is written in C (see ngx_http_wsgi_module), the application SHOULD also minimize roundtrips between C and Python code.

Recent activity

Manlio Perillo

Commits by Manlio Perillo were pushed to mperillo/txwsgi

0c16bd9 - Feature: improved error handling in the greenlet adapter. The gresume function now requires an optional exc_info parameter, as a tuple. This allows to pass full ...
Manlio Perillo

Commits by Manlio Perillo were pushed to mperillo/txwsgi

7063ad7 - Feature: implemented the green_adapter and support API. The greenlet WSGI adapter and support API enable execution of WSGI applications using greenlet with an asynchronous WSGI ...
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.