[Zope-dev] Streaming Response

Casey Duncan casey@zope.com
Wed, 16 Apr 2003 11:56:56 -0400


On Wednesday 16 April 2003 10:26 am, Toby Dickenson wrote:
> On Wednesday 16 April 2003 3:13 pm, Casey Duncan wrote:
>=20
> > The file is divided into 64K chunks, each of which is pickled. Each c=
hunk
> > is unpickled separately and then discarded.
>=20
> If I remember correctly, chunks are not explicitly discarded. They will=
=20
> certainly stay in memory until the end of the transaction, then the gar=
bage=20
> collector will drop the least recently used objects. A 200MB file will=20
> certainly cause a 200MB memory surge when downloaded.

Here is the code in question from the index_html method of OFS/Image.py:

        data=3Dself.data
        if type(data) is type(''):=20
            RESPONSE.setBase(None)
            return data

        while data is not None:
            RESPONSE.write(data.data)
            data=3Ddata.next

        return ''

Although a reference to data is not kept here, I imagine the ZODB cache m=
ay=20
keep a reference. Perhaps this should be changed to explicitly discard it=
=20
from the cache each time through the loop?

If the whole thing is indeed loaded into memory, then it pretty much defe=
ats=20
the purpose of this code.

-Casey