Python Run-Time Environment

Version 1.1.2, 19th April 2008

Copyright © 2007,2008 Mark G. Daniel
This program, comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under the
conditions of the GNU GENERAL PUBLIC LICENSE, version 3, or any later version.
http://www.gnu.org/licenses/gpl.txt

Contents




PyRTE is an interface to a Python interpreter engine and environment for the WASD VMS Web server. It is designed to be able to be used in standard CGI and CGIplus/RTE persistent scripting modes. The persistent modes (default) provide a ~35x (yes, an approximate thirty-five times) improvement in script activation times (compared to CGI/command-line) and comparably reduced load on both server and system. Note that this package does not contain the Python interpreter or kit, that has to be obtained and installed separately (a simple matter as it is provided via a PCSI package).

PyRTE is linked against the Python interpreter shareable image and so shares a set of Python capabilities in common with command-line OpenVMS Python. Alpha (AXP) and Itanium object modules are provided for the VMS platforms available for Python.

PyRTE has been developed and tested on VMS V8.3 using the WASD v9.2.0 and VMS Python kit JFP AXPVMS PYTHON251 available from and documented at http://vmspython.dyndns.org/. JFP's Python kits are kept very up-to-date as Python updates or implementation problems arise.

Installation

Configure WASD

Although there are experimentation modes built into PyRTE basically it will be used as a WASD Run-Time Environment providing persisten Python interpreter(s) and environment(s) for Python scripts and applications. Benchmarking indicates the CGIplus/RTE use reduces activation time to 3% of CGI (yes, that's correct, by a factor 35 - a python interpreter is quite expensive to instantiate). There are subtle differences in the way CGIplus and RTE parse and provide the PATH_INFO data (see the "WASD Scripting Overview" for detail).

Configuration and Mapping

One or more of the following approaches can be implemented.

Remember to

$ HTTPD /DO=MAP
after changing mapping rules.

Example Scripts

After configuration (as described immediately above) the following scripts may be used to confirm the environment is functioning.

Some of these examples also support CGIplus mode for comparison purposes.

Of course the Python code in the script may be inspected from the source directory:

/ht_root/src/python/scripts/

Web Server Gateway Interface

PyRTE contains a Web Server Gateway Interface v1.0 (WSGI). This is a Python standard specification for web servers and application servers to communicate with web applications (though it can also be used for more than that).

The WSGI code has been developed under the sponsorship of SysGroup

http://www.sysgroup.fr/
and generously made available to the wider WASD community.

The following is an example of a simple (and classic) WSGI application being activated using the PyRTE wasd.wsgi_run() function.

def hello_world (environ, start_response):
    status = '200 OK'
    response_headers = [('Content-type','text/plain')]   
    start_response(status, response_headers)
    return ['Hello world!\n']

import wasd
wasd.wsgi_run(hello_world)

WSGI Output Buffering

PEP 333 specifies that WSGI should not buffer output and pyRTE complies but some tools (like Mercurial) don't buffer internally themselves and end up sending many very small records. This is obviously inefficient. If buffered the throughput boost for Mercurial is about x4. Well worth having for specific Web applications.

This forced buffering may be enabled on a per-application basis using a mapping rule, for example

set /mercurial/* script=param=PYRTE=/WSGI=BUFFER
or by defining the logical name
$ DEFINE /JOB PYRTE_WSGI_FORCE_BUFFERING TRUE
in a wrapper procedure.

Example WSGI Scripts

The following scripts may be used to confirm the environment is functioning.

The Python code in the script may be inspected from the source directory:

/ht_root/src/python/scripts/

There are also equivalent wsgiref (the Python reference implementation) scripts available for comparison. Just add ref to the wsgi in the script name.

Leveraging PyRTE

Python scripts activated using the default persistent engine generally have low-latency, low-system-impact characteristics and seem to perform reliably and efficiently. The PyRTE generally handles all the WASD server interaction requirements. However there may be occasions where the application itself benefits from being persistent (many Python Web application are written with this in mind) or where more control needs to be exercised by the application designer. The WASD PyRTE provides a WASD Python module that provides an API for some of these aspects. Rather than clutter this document with such arcane detail the description may be found in the prologue to the PyRTE source code:

/ht_root/src/python/pyrte.c

An example of where an application benefits from an explicitly CGIplus activation is MoinMoin:

MoinMoin is generally run independently to a system's primary Web server using the embedded Web server available for Python. Reverse proxy is often then use to provide and control access through to the persistent MoinMoin server.

Using the same principle of keeping MoinMoin persistent (for the obvious latency and efficiency benefits) it can be run and controlled directly by the WASD Web server using a CGIplus wrapper DCL procedure and a little Python glue (directly derived from persistence code already present in the MoinMoin package).

/ht_root/src/python/moincgiplus.com

The same principles may be applied to any application environment (third-party or in-house) with similar characteristics. Python applications running as CGIplus scripts using the PyRTE must be activated via DCL wrappers as illustrated above (in part due to mapping requirements).

With CGIplus persistent applications configuration or code changes will in all probability require a 'restart' of the application using one or other of:

$ HTTPD/DO=PURGE
$ HTTPD/DO=DELETE

Problems?

Unfortunately the author of the PyRTE interface is such a Python novice he is not in any position to answer queries about Python "programming" or usage. There is the VMS Python Wiki

http://vmspython.dyndns.org/

and support forum

http://vmspython.dyndns.org/piforum/index.py

for VMS Python issues. If there's an obvious behavioural problem with PyRTE then contact the author or use the info-WASD mailing list.

Acknowlegements

Many thanks to Jean-François Piéronne for his initial port of Python to VMS and his energetic, ongoing maintenance of the product.



he server. It handles \ all of the stream flushing and sentinal output required of WASD CGIplus."); static PyObject* RtePyMethCgiPlusEnd (PyObject*, PyObject*); PyDoc_STRVAR (rte_cgiplus_end__doc__, "For a Python script implementing the CGIplus protocol itself this method \ provides all of the flushing and sentinal output required at the end of \ request process. This functionality is implicitly provided by the \ cgiplus_begin() method and so generally is not explicitly required."); static PyObject* RtePyMethGetVar (PyObject*, PyObject*); PyDoc_STRVAR (rte_getvar__doc__, "Returns a string containing the value of the CGI variable specified by name \ in the function argument. Generally CGI variables are accessed from \ os.environ in the same manner as other environment variables."); static PyObject* RtePyMethReuseInterpreter (); PyDoc_STRVAR (rte_reuse_interpreter__doc__, "Enables (True) or disables (False) interpreter reuse for the next request \ received by pyRTE."); static PyObject* RtePyMethRteCacheEntry (PyObject*, PyObject*); PyDoc_STRVAR (rte_cache_entry__doc__, "Returns a string containing details of a pyRTE cache entry as a series of \ comman-separated values (CSV) in the same order as the data structure. \ Multiple calls step through each cache element until None is returned. \ This function will not succeed unless logical name PYRTE_CACHE_ENTRY is \ defined."); static PyObject* RtePyMethRteId (); PyDoc_STRVAR (rte_id__doc__, "Returns a string containing the pyRTE version and build date/time."); static PyObject* RtePyMethStatTimer (); PyDoc_STRVAR (rte_stat_timer__doc__, "Returns a string containing LIB$STAT_TIMER() statistics for the request."); static PyObject* RtePyMethUsageCode (); PyDoc_STRVAR (rte_usage_code__doc__, "Returns an integer value for how many times the cached byte-code \ has been used."); static PyObject* RtePyMethUsageInterpreter (); PyDoc_STRVAR (rte_usage_interpreter__doc__, "Returns an integer value for how many times the current Python \ (sub)interpreter has been use