Python extension for libmemcache

Contents

Description

Python extension for libmemcache, the C API to memcached. cmemcache API is very similar to python-memcache, except for some return codes which follow libmemcache conventions.

cmemcache is about 2 times faster then python-memcache with short key names (8 characters), faster with larger key names.

Motivation

This extension was created after doing some timings on a simple session caching scheme where I noticed that python-memcache was 'only' three times as fast as PostgreSQL. I expected it to be faster than that, since PostgreSQL does a lot more than memcached. It was suggested that it was perhaps python-memcache, which for instance gets the initial part of the message from memcached byte for byte. After discovering libmemcache it seemed pretty straight forward to create an extension on top of that.

cmemcache has 2 clients: StringClient and Client. StringClient is the extension that only supports python strings for values. The api was copied from python-memcache, except that it excepts strings only. Client is a module that implements caching of arbitrary python objects using Pickle on top of the StringClient. This code is a copy/paste from python-memcache. Most of the test code in test.py is run on the cmemcache Client and the python-memcache Client to make sure that they are interchangeable. Although I have not tested this but it should be possible to mix cmemcache and python-memcache clients in a running system as well, since they use the same constants for encoding object types.

The speed difference would be less if the memcached protocol would be changed to precede the reply header with its size. A client could then read the header size, read the full header (in one read), parse header to get the data size, and read data (this is already done in one read).

Dependencies

Download

To do

Known Bugs

cmemcache:

libmemcache:

Changes

Versions:

0.92
Changed return values for set, add, and replace to be the same as memcache.py, ie nonzero on success. Reported by Marek Majkowski.
0.91
Remove @staticmethod from _convert method to make it python 2.3 compatible.
0.90
Initial version.

Copyright and License

Copyright (C) 2006-2008 Gijsbert de Haan. This code is distributed under the GNU General Public License.

Author

Gijsbert de Haan <gijsbert.de.haan@gmail.com>