Comment 6 for bug 530229

Revision history for this message
Roger Binns (ubuntu-rogerbinns) wrote :

It wouldn't work here due to the other pieces it talks to. I altered the code to fix bug 529855 and to remove the inheritance from threading.local. Neither issue could be monkey patched to fix them which is the usual approach I take to third party libraries.

My use case is that I have a long running server process. A thread runs in the background that monitors the config server for changes. On changes it calls set_servers to update the server list. Consequently the threading.local stuff means I could never change the servers for an existing instance.

Separately I do have a monkey patch for the _set method. This is because I need to know which host and port was used as that information is communicated to other components. I also made my version raise exceptions rather than do error codes. It is also a little different in that it is a loop that gets the server, tries it and if that fails marks it dead, and tries again until there are no servers left. (ie I do not depend on any of the allocation/hashing algorithms.)

I have a pool of these client instances and then a function that returns one with context management. ie you use it like this:

    with mymemcached.client() as client:
        client.get(,..)
        client.set(...)

Server threads come and go all the time depending on traffic and load so having one Client per thread would result in a huge number of TCP connections being made and dropped, not to mention the difficulty of updating their config.