Installing cmemcache on Ubuntu 8.10 (almost)

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/ 
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:

tar xvfj libmemcache-1.4.0.rc2.tar.bz2
cd libmemcache-1.4.0.rc2/
wget --no-check-certificate
patch -p1 < libmemcache.patch
sudo apt-get install automake1.9 
./configure && make
sudo make install

The patch modifies the 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:

tar xvfj cmemcache-0.95.tar.bz2
cd cmemcache-0.95/
sudo apt-get install python-dev
sudo python install

I had to install the python-dev package first because cmemcache depends on Python.h provided by that package. Running the 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 "", line 254, in test_memcache
                    cmemcache.StringClient(self.servers), ok=1)
  File "", 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([''])
>>> c.set('testkey', 'testval')
>>> c.get('testkey')

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 to “Installing cmemcache on Ubuntu 8.10 (almost)

  1. Pawan Kumar

    Thanks man! You suggestion worked for me.

  2. devdoodles

    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!

  3. Byron Ruth

    Worked for me. Thanks for the tips. I really need to learn C one of these days…

  4. Pingback: Installing memcached for use with Python and Django » Death of a Gremmie

  5. 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.

  6. devdoodles

    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. 🙂

  7. Sounds like a good strategy, I’ll have to look into python-memcached a bit more.

  8. Thanks, I’ve updated the link in the post!