[Twisted-web] render_GET and memory consumption

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Tue Dec 21 12:47:13 EST 2010


On 04:43 pm, psanchez at fosstel.com wrote:
>
>OK, I guess I'm being slow :-( Here's another version, same results.
>
>import os
>from twisted.internet import reactor
>from twisted.web.server import Site
>from twisted.web.resource import Resource
>
>CHUNK_SIZE = 32*1024
>data = os.urandom(10*1024*1024)
>chunks = []
>
>def make_chunks():
>     s = 0
>     for chunk in iter(lambda: data[s:s+CHUNK_SIZE], ''):
>         chunks.append(chunk)
>         s = s + CHUNK_SIZE
>
>class TestPage(Resource):
>      isLeaf = True
>
>      def render_GET(self, request):
>          for chunk in chunks:
>              request.write(chunk)
>
>make_chunks()
>root = Resource()
>root.putChild('test', TestPage())
>reactor.listenTCP(8880, Site(root))
>reactor.run()

This version has flat memory usage on my system - 33MB all the way 
through.
Jean-Paul



More information about the Twisted-web mailing list