Despite my previous post about the confusing recommendation in the Django documentation to use cmemcache as Python client library for memcached I decided to give it a try.
cmemcache is based on the C library libmemcache, but for some reason the author includes a patch for libmemcache that should be applied before compiling. The only problem is that this patch doesn’t work. After patching, compiling, and installing libmemcache and then installing cmemcache, any attempt to import the cmemcache module in your Python code comes back with this error:
ImportError: /usr/local/lib/libmemcache.so.0: undefined symbol: mcm_buf_len
I’m not the first one experiencing this issue, as can be seen here and here. One of the comments in the second link mentions another patch, which supposedly should work better than the original one. Despite having an icky feeling about it, I went ahead and installed libmemcache with the fishy patch as follows:
wget http://people.freebsd.org/~seanc/libmemcache/libmemcache-1.4.0.rc2.tar.bz2 tar xvfj libmemcache-1.4.0.rc2.tar.bz2 cd libmemcache-1.4.0.rc2/ wget --no-check-certificate https://svn.pardus.org.tr/pardus/devel/programming/libs/libmemcache/files/libmemcache.patch patch -p1 < libmemcache.patch sudo apt-get install automake1.9 ./configure && make sudo make install
The patch modifies the configure.ac file, which make first complained about, so I had to install automake1.9 before running make again. Once libmemcache is installed, cmemcache can be installed:
wget http://gijsbert.org/downloads/cmemcache/cmemcache-0.95.tar.bz2 tar xvfj cmemcache-0.95.tar.bz2 cd cmemcache-0.95/ sudo apt-get install python-dev sudo python setup.py install
I had to install the python-dev package first because cmemcache depends on Python.h provided by that package. Running the test.py test suite after this actually works better than with the official patch earlier, but one test fails even so:
Traceback (most recent call last):
File "test.py", line 254, in test_memcache
self._test_base(cmemcache,
cmemcache.StringClient(self.servers), ok=1)
File "test.py", line 132, in _test_base
self.failUnlessEqual(len(stats), 1)
AssertionError: 0 != 1
That being said, you can test cmemcache manually at this point and it actually seems to work a little bit (memcached should be running on localhost):
>>> import cmemcache
>>> c = cmemcache.StringClient(['127.0.0.1:11211'])
>>> c.set('testkey', 'testval')
1
>>> c.get('testkey')
'testval'
>>>
All things considered, this was a less than convincing experience with cmemcache, and the thought of running an unofficial and undocumented patch for an aging library in a production environment is not altogether appealing.
Update: See also my subsequent attempt of installing libmemcache through apt-get. Not really more successful, but easier at least.

9 responses so far ↓
Pawan Kumar // April 1, 2009 at 12:49
Thanks man! You suggestion worked for me.
devdoodles // April 1, 2009 at 13:35
You’re welcome.
If you’re using Ubuntu, you could consider installing libmemcache through apt-get too. The result seems to be the same, but it’s a bit easier to carry out. Good luck!
Byron Ruth // April 21, 2009 at 05:05
Worked for me. Thanks for the tips. I really need to learn C one of these days…
Installing memcached for use with Python and Django » Death of a Gremmie // June 14, 2009 at 06:17
[...] that are included with cmemcache, one of them fails. This is kind of disturbing. I’ve noticed at least one other blogger has run into [...]
Brian Neal // June 14, 2009 at 06:23
Hi -
Thank you for your blog post. I was able to get cmemcache running on Ubuntu 8.04 without any errors, but ran into that test failing also. I wrote a blog post about my experiences, see my link. Again, thanks for sharing your experience with this.
devdoodles // June 14, 2009 at 10:10
Thanks for the feedback! Personally I use python-memcached for small-scale deployments because of this hassle with cmemcache, but should speed become more of an issue I’d try cmemcache live for a while, and if it works without any issues then all is well I suppose.
Brian Neal // June 14, 2009 at 16:08
Sounds like a good strategy, I’ll have to look into python-memcached a bit more.
joe vasquez // September 2, 2009 at 05:37
new url for patch https://svn.pardus.org.tr/pardus/tags/2008.1/programming/libs/libmemcache/files/libmemcache.patch
devdoodles // September 2, 2009 at 05:52
Thanks, I’ve updated the link in the post!