473,387 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

cgi.FieldStorage() is slow

i wanted to created a simple CGI script for uploading files to my
http server, and decided to use python for it. it seems to work
fine except for one issue: there is a lot of CPU overhead.

after profiling, it seems like:
self.read_lines_to_outerboundary()
which is called from
cgi.FieldStorage()
is the reason why it's so slow.

when uploading small files, you won't notice a difference, but if
you upload files larger than 2 megs, you can notice it. this
happens on both win2k and freebsd

is there some other way to process CGI, excluding doing it all
manually? will this code be improved in the future?
-- thx, Nehal
Jul 18 '05 #1
5 3483
Nehal wrote:
i wanted to created a simple CGI script for uploading files to my
http server, and decided to use python for it. it seems to work
fine except for one issue: there is a lot of CPU overhead.

after profiling, it seems like:
self.read_lines_to_outerboundary()
which is called from
cgi.FieldStorage()
is the reason why it's so slow.

when uploading small files, you won't notice a difference, but if
you upload files larger than 2 megs, you can notice it. this
happens on both win2k and freebsd

is there some other way to process CGI, excluding doing it all
manually? will this code be improved in the future?
-- thx, Nehal


The cgi module is a confusing mess of code munged, over the years, by
many hands. It would take a brave programmer to plunge in and do what's
necessary.

not-brave-enough-ly y'rs - steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
Jul 18 '05 #2
On Tue, 16 Nov 2004 07:40:17 -0500
Steve Holden <st***@holdenweb.com> wrote:
The cgi module is a confusing mess of code munged, over the
years, by many hands. It would take a brave programmer to plunge
in and do what's necessary.

not-brave-enough-ly y'rs - steve

if i were to do it, could i rewrite the functions in the cgi
module?, or would i need to keep the same functions for backward
compatibility?
-- Nehal
Jul 18 '05 #3
Nehal wrote:
On Tue, 16 Nov 2004 07:40:17 -0500
Steve Holden <st***@holdenweb.com> wrote:

The cgi module is a confusing mess of code munged, over the
years, by many hands. It would take a brave programmer to plunge
in and do what's necessary.

not-brave-enough-ly y'rs - steve


if i were to do it, could i rewrite the functions in the cgi
module?, or would i need to keep the same functions for backward
compatibility?
-- Nehal

Well, code breakage is regarded as pretty bad, so you would need to
retain the same interfaces that the module supports now.

Of course you could implement them completely differently, as long as
they worked the same, and you could add new interfaces as well.

regards
Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119

Jul 18 '05 #4
On 17 Nov 2004 05:47:05 -0800
an********@doxdesk.com (Andrew Clover) wrote:
Nehal <ne*********@gmx.net> wrote:
when uploading small files, you won't notice a difference, but
if you upload files larger than 2 megs, you can notice it.


Yep. Large file upload in cgi.py is slow. I don't immediately
see a way to speed it up without re-architecting some of its
internals.

In any case I dislike(*) the cgi module's interface too, so I
rewrote the lot:

http://www.doxdesk.com/software/py/form.html

This isn't drop-in compatible, and is getting a bit crusty (I'm
expecting to rewrite most of it soon to be more
objecty/threadable, and support WSGI), but in my experience it's
considerably faster than cgi for very large files. (We were
commonly using files in the 10-50MB range.)

(* - more then than now; cgi's interface has got slightly better
since Python 1.5.2's time.)

--
Andrew Clover


I have tested Andrew's 'form.py' module, and also upload cgi
scripts from other languages, i did some benchmarking, i tried
uploading a 6 meg file to localhost and writing to an output file
on apache 2.0.52 win32. here are the results (note: i checked the
error log to make sure all scripts were working and processing the
data as expected):

ruby: 2 sec
Andrew Clover's form.py: 2.5 sec
perl: 2.5 sec
tcl (3rd party module): 4.5 sec
python: 8 sec

of course in practice, most people won't be receiving data at 3
megs/sec, so you won't have to process data at such a speed.
nevertheless, it will put a greater load on the CPU, which may be
an issue for many servers.

it would not be a good idea to put Andrew's form.py in the
official python distribution and have 2 different modules for
processing CGI. either it would have to somehow merged into CGI
module, and keeping backward compatibility, or the existing CGI
module must be optimized; maybe the above benchmark data will
motivate someone to do so ;). until then, i'll stick to form.py
-- thx, Nehal
Jul 18 '05 #5
Nehal Mistry <ne*********@gmx.net> wrote:
nevertheless, it will put a greater load on the CPU, which may be
an issue for many servers.
It certainly was for the ricketty old SPARC box we were trying to
upload umpteen-MB files to! Probably not so critical for most people
these days though.
it would not be a good idea to put Andrew's form.py in the
official python distribution and have 2 different modules for
processing CGI.
Fully agree. In any case the current interface is not general enough
for std lib use.
either it would have to somehow merged into CGI
module, and keeping backward compatibility


If there is interest I could certainly look at providing a cgi-alike
interface to the new version. Personally I was not aiming at the
standard library.

cheers,

--
Andrew Clover
mailto:an*@doxdesk.com
http://www.doxdesk.com/
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Fred Murray | last post by:
Hi all, When uploading a file ("input type=file"), FieldStorage usually behaves correctly, but every once in a while (every couple days?), it will suddenly start causing internal server errors. ...
1
by: Ames Andreas (MPA/DF) | last post by:
Hi, sorry for following-up to myself. Some remarks: 1) Please excuse the bogus original message. I wrote it a minute before I knocked off work and I promise to never do so again :-) 2)...
1
by: Ames Andreas (MPA/DF) | last post by:
Hi, I'm currently using Zope 2.7.2-0 which in turn uses cgi.FieldStorage from Python 2.3.4. FieldStorage can either build a 'list' or a 'file' to represent a request. Unfortunately it...
0
by: Neil Benn | last post by:
Hello, I'm writing a simple cgi script and want to be able to access the filename in a FieldStorage file instance. I have successfully manmaged to access the file as a 'file-like object' by...
4
by: Derek Basch | last post by:
Given this FieldStorage object: FieldStorage(None, None, ) I am trying to cgi.urlencode the FieldStorage object to POST to another cgi script. The documentation for urlencode,...
3
by: Chris Curvey | last post by:
I can't be the first person to want to do this, but I also can't seem to find a solution. (Perhaps my Google skills are poor today.) How can I emulate cgi.FieldStorage() for my unit tests so that...
0
by: John Salerno | last post by:
I'm trying to use a for loop with a FieldStorage object and I get the following error. Can you not treat it like a dictionary, or am I writing the for loop incorrectly? for item in form: print...
7
by: John Salerno | last post by:
If I want to get all the values that are entered into an HTML form and write them to a file, is there some way to handle them all at the same time, or must FieldStorage be indexed by each specific...
4
by: arorap | last post by:
I've mod_php installed with Apache 2.2. In one of my folders, I'm using the cgihandler as the PythonHandler as my target host runs python only as CGI. Here cgi.FieldStorage() doesn't seem to work....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.