I'm not seeing how to do this clearly using cherrypy.
I'm pretty sure i need to use the response object.
has anyone got a simple example ?
or can point me to one?
Fred:
Ran into this problem last month. See post on XMLHttpRequest() on
this list from last week. If your binary content is static and larger
than 1MB or so, use Apache2 to serve it. CherryPy does not scale well
when trying to transmit binary data. For example: in the
_cphttpserver.py file, there is code that measures "Content-Length"
line by line. For large, static binary files, that approach is not
recommended. I added two lines to the static content check portion
(doRequest or handleRequest method...don't have code in front of me
right now...)
.....
contentLength=os.path.getsize(fname)
<Header Map dictionary variable>["Content-Length"] = contentLength
This improved things quite a bit in terms of beginning the download.
However, the download still took about 15 min to complete. By
comparison, Apache2 serves the same file in 4 seconds or so !!!
The speed issue must have something to do with how CherryPy handles
socket communication with the browser (my client is Mozilla based
Javascript).
Another problem serving large binary content with CherryPy is that the
slow download would terminate when about 90% of the content was
transferred (tested with varying files). This happened about 50-75% of
the time with a variety of large binary files. In this case, I am not
sure CherryPy is responsible; could be the browser code. Anyway having
deadlines to meet, I have deferred investigation of this matter to a
later date.
BOTTOM LINE: Run Apache2 on a separate port on the server. Point all
binary download requests to this port and get your content served
quickly and scalably, while freeing CherryPy to do what it does
best...server side computations using Python.
Thanks to Remco and nopas for answering my XMLHttpRequest question of
last week.
Regards
Ravi
is there away similar to the upload recipe to have cherrypy NOT process
the output, or sidestep CP for this one process ?
I believe that the CherryPy code needs to be revamped to support
HTTP1.1 especially w.r.t to chunked data in order to serve binary files
efficiently...maybe someday I will take a stab at it myself....
BTW, I wished to thank Remi Delon and nopa90 for responding to me last
week and not as misattributed in my previous post...
Regards
Ravi
I was thinking about what you said about reading fixed amounts and I
was playing and looked at the upload recipe, while not as pretty it
seemed to be faster.
still learning python though.
.def file2Generator(self,f):
. while 1:
. data = f.read(1024 * 8) # Read blocks of 8KB at a time
. if not data: break
. yield data
. #for l in f:
. # yield l