Sites that show up quickly on a user's screen tend to keep the user's attention for longer and also rank better in Google. So when listening to the excellent Lullabot Podcast 80: Top 40 Drupal Modules Revisited I was caught by Drupal experts stating that Memcache would even speed up your site if it's not a high traffic site. It could off-load the database. I decided to give it a try on a relatively low traffic site of one of my clients. The site is already being served by nginx so the load times are already pretty good. When setting up the experimentation I was a bit confused by the thorough but chaotic instruction to set up memcache. I ran into a problem setting up PECL memcache:
$ sudo pecl install memcache
downloading memcache-2.2.5.tgz ...
Starting to download memcache-2.2.5.tgz (35,981 bytes)
..........done: 35,981 bytes
11 source files, building
running: phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519
shtool at '/tmp/pear/temp/memcache/build/shtool' does not exist or is not executable.
Make sure that the file exists and is executable and then rerun this script.

ERROR: `phpize' failed
Since I run Debian I solved this by running apt-get install php5-memcache instead. I restarted php-fastcgi (needed for nginx) and added $conf['cache_inc'] ='sites/all/modules/memcache/memcache.db.inc'; to settings.php. Then I ran some tests in Hammerhead.  Not on the front page since there is an embedded Youtube video. I chose a page without any external elements. I was a bit confused at first, and ran several short tests. I forgot to log out and the memcache module was adding a lot of extra information in the bottom.  I thought that was the reason that my site was a lot slower with memcache than without it.  So I logged out and tried again:
count latest median avg
empty cache with memcache 4 1449 1449 1759
primed cache with memcache 4 1277 1186 1184
empty cache without memcache 4 1239 1283 1483
primed cache without memcache 4 1014 900 950
It could be that I'd have to tweak some memcache settings, or run longer tests, but I think these numbers are clear enough: memcache made my site slower instead of faster!

Comments

memcached is a memory object caching daemon, mainly aiming to lower *database* load. it does so by caching the result of repeating queries in memory. in order to take advantage of memcached you will need to adjust your php code first. check out http://code.google.com/p/memcached/wiki/FAQ#Simple_query_result_caching to see how that's done.

if you want to speed up your php code without modifying it, use APC (also see http://en.wikipedia.org/wiki/PHP_accelerator) - at ecobytes it works wonders with ez publish, wordpress, drupal and so on.

ideally you use both, apc for zillions of opcode fragments and memcached for expensive database queries.

but by now you probably found this out by yourself. :)

cheers, meinhard of http://benn.org

If he's setup the memcache Drupal module, it automatically switches Drupal's caching from using tables in the database to using memcache.

You really should check you know what you're talking about before writing patronising comments.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.