Hi, folks,
I forgot to attach the context diff against the CVS tree for the threading
changes in the last e-mail, so here they are.
These changes allow me to implement a one request/thread, multiple
request/publisher model in Quixote. They essentially consist of working
three new functions into the current class definition for Publisher:
--- (default code, included in the patch)
def set_request(self, request):
"""Called by process_request to set the current connection's request
object."""
self._request = request
def get_request(self):
"""Called by quixote.get_request() to get the request object."""
return self._request
def clear_request(self):
"""Called at the end of each try_publish() call.
Invalidates the publisher's pointer to the current request object.
"""
--
In the current code, I do not clear self._request by setting it to None
in clear_request; I think that doing this is a good idea, but it might
break people's code, so I left this up to the Quixote team.
By overriding these three functions with code to look up the current
request indexed by thread ID, I can successfully run at concurrency levels
of 10-100 (ten to one hundred concurrent threads at a time) within an
existing Quixote application, Cartwheel.
--- (multithreading code in Cartwheel's Publisher class.)
def set_request(self, request):
id = thread.get_ident()
self.request_dict[id] = request
def get_request(self):
id = thread.get_ident()
return self.request_dict[id]
def clear_request(self):
id = thread.get_ident()
if self.request_dict.has_key(id):
del self.request_dict[id]
---
I'm not sure of how much utility this will be to people currently using
Quixote with Apache/FCGI or Apache/SCGI, neither of which run under this
model. I run under AOLserver/PyWX, which offers a convenient mod_python
style embedding for Python inside of AOLserver.
I'd be happy to expound on the virtues of this approach or this code if
anyone wants to know about it ;).
cheers,
--titus