I started a thread on comp.lang.python which will give you the background...

http://groups.google.com/groups?dq=&hl=en&lr=&ie=UTF-8&th=ca31e9f204280589

Basically, in WebKit, when a thread needs a servlet instance, it does this:

        try:
                instance = cache.get_nowait()
        except Queue.Empty:
                instance = new_instance()
        # use the instance...
        cache.put(instance)

But unfortunately Queue.get_nowait() can raise the Empty exception even if
the queue is not in fact empty (see the Google thread for the explanation).
This can cause the servlet cache to grow unnecessarily.  And since the size
of the Queue object is initialized to be the maximum number of threads plus
one, eventually it causes servlets to stop responding because the put()
operation blocks.

I in fact observed this in our test system -- due to a peculiar type of load
exerted by our testing framework, over the course of several days and
thousands of requests for the same servlet it eventually stopped responding
because the cache had hit its limit and it couldn't return the servlet to
the cache until the _next_ request for that servlet came in.

I am now thinking that since we are simply using the queue as a cache and we
don't ever want it to block, we'd be better off just using a list, whose
append() and pop() operations are guaranteed to be atomic:

        try:
                instance = cachelist.pop()
        except IndexError:
                instance = new_instance()
        # use the instance
        cachelist.append(instance)

I'm going to try this out locally, and if it works and nobody objects, I'll
check it in.  As a bonus, it should be slightly (but probably not
noticeably) faster.

- Geoff


-------------------------------------------------------
This sf.net email is sponsored by: Jabber - The world's fastest growing 
real-time communications platform! Don't just IM. Build it in! 
http://www.jabber.com/osdn/xim
_______________________________________________
Webware-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-devel

Reply via email to