A while back I looked at the Memcached UDF for MySQL, and noticed that it didn't use libmemcached in an optimal way. In order to work in a multithreaded environment it used the following pattern:
memcached_st* clone = memcached_clone(NULL, memc); ... memcached operations using the clone --- memcached_free(clone);
Well, that doesn't look bad, does it? Well, it isn't that bad, but if you look at the network traffic you will see that we end up connecting / disconnecting to the involved memcached servers every time, and memcached is not optimized for "single-shot" connections.
So how should you solve this? Well, you should reuse your clones!
And luckily for you, you don't have to reinvent the wheel.
Yesterday I pushed a patch to libmemcached
introducing a new library: libmemcachedutil. The
intention of that library is to put utility functions built on
top of libmemcached …