[lxml-dev] About lxml status

Ian Bicking ianb at colorstudy.com
Thu Dec 14 22:49:40 CET 2006


Lee Brown wrote:
> Thanks for the warning, but I've already run headfirst into that problem.  My
> apache server is running the Win32MPM, where every request is a new thread, so
> there aren't any tricks I can play with the PythonInterpreter directive.  (None
> that help, anyway.)
> 
> However, I did some benchmark tests and found that I can serve about 32 requests
> per second even with the overhead of recompiling the XSLT template new for each
> request.  This is adequate for my needs, though a very busy website might have
> trouble.

I'm not clear exactly on the way threads and mod_python and all that 
work, but I imagine you could use a pool of templates.  You'd do 
something like:

try:
     tmpl = template_pool.pop()
except IndexError:
     tmpl = compile_template()

# then to return the template to the pool:

template_pool.append(tmpl)


This is assuming that it's okay to move templates between threads, but 
not use them concurrently between threads.  Or if they have to be used 
in the thread they were created in, you can use:

import threading
template_cache = threading.local()

try:
     tmpl = template_cache.template
except AttributeError:
     tmpl = template_cache.template = compile_template()


That's assuming that threads are long-lived, otherwise this won't change 
anything either.


-- 
Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org


More information about the lxml-dev mailing list