]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commit
webish: reduce POST memory footprint by overriding http.Request
authorBrian Warner <warner@lothar.com>
Sat, 11 Aug 2007 00:25:33 +0000 (17:25 -0700)
committerBrian Warner <warner@lothar.com>
Sat, 11 Aug 2007 00:25:33 +0000 (17:25 -0700)
commit9281a0aedc38be2c3384afb17025a574dd5fd1d5
tree52c3fb52a71bd6e4835667995891c7ca499522fa
parentb6ff38e4c75624f44eb4b43cfd1460bcaf674c37
webish: reduce POST memory footprint by overriding http.Request

The original twisted.web.http.Request class has a requestReceived method
that parses the form body (in the request's .content filehandle) using
the stdlib cgi.parse_multipart() function. parse_multipart() consumes a
lot of memory when handling large file uploads, because it holds the
arguments entirely in RAM. Nevow's subclass of Request uses cgi.FieldStorage
instead, which is much more memory-efficient.

This patch uses a local subclass of Request and a modified copy of the
requestReceived method. It disables the cgi.parse_multipart parsing and
instead relies upon Nevow's use of FieldStorage. Our code must look for
form elements (which come from the body of the POST request) in req.fields,
rather than assuming that they will be copied into req.args (which now
only contains the query arguments that appear in the URL).

As a result, memory usage is no longer inflated by the size of the file
being uploaded in a POST upload request. Note that cgi.FieldStorage uses
temporary files (tempfile.TemporaryFile) to hold the data.

This closes #29.
src/allmydata/webish.py