gzlist at googlemail.com
Sat May 19 21:53:36 EDT 2007
> On 5/20/07, Graham Dumpleton <graham.dumpleton at gmail.com> wrote: > > On 20/05/07, Martin _ <gzlist at googlemail.com> wrote: > > > > > def handler(req): > > > buf =  > > > for i in xrange(1000): > > > buf.append("Yeah\n") > > > req.write("".join(buf), 0) > > > return apache.OK > > > > Or to avoid buffering in Python code and letting Apache buffering do > > its thing instead use: > > > > def handler(req): > > for i in xrange(1000): > > req.write('Yeah\n, 0) > > return apache.OK > > > > By default req.write() flushes data on each call, which using 'print' > > with it would result in happening. Thus call req.write() directly and > > supply second argument of 0 to avoid flushing. > > > > Graham For this exact test, calling req.write a thousand times is actually slower (though only by a factor of two or so). If we were being really minimal: req.write("Yeah\n"*1000, 0) comes in at about a quarter again as fast as the buf version. But clearly 'benchmarks' on this kind of level aren't really useful, just needed to point out the difference between sending response to client in lots of teeny bits vs. one finished chunk.