HOWTO: Use Advanced Drupal Caching From Your Desktop

Profile picture

I (heart) the DAMP/Acquia Stack Installer. It makes rapid testing and development easy, and helps me be productive on airplanes even without wifi. In this post I'll explain how I was able to quickly set up an advanced caching testbed on my desktop to investigate some advanced APC and memcache configurations.

Caveat: these instructions are all MacOS centric — apologies in advance to the Redmond-faithful, happy to finally be caught up with all the Ubuntu-ites — but that's my environment and over the years I've found it to be a good one.

First two easy point-and-clicks.

  1. Download and run the DAMP installer.
  2. Next, since I roll with Pressflow and what I wanted to test was a potential new branch, I grabbed myself a copy of BZR, another cool next-generation version control system with an installer.

Now's where the work starts. I pop open my handy iterm and quickly grab a fresh branch of Pressflow:

mithras-4:pressflow joshk$ cd
mithras-4:~ joshk$ cd Sites/
mithras-4:Sites joshk$ bzr branch lp:pressflow
Branched 78 revision(s).

Then fire up your Acquia Stack, pick "More..." from the little sites drop-down, click the import button, and find the freshly branched codebase. Note: this is a great way to set up/run any codebase locally, not just a Pressflow branch. If you've got an existing site tarball, your own SVN repository, or want try out a cool Drupal product like Open Atrium, you can use DAMP to easily import the pre-existing Drupal.

Next thing I do is install Drush. Drush: don't leave home without it. Now, there's an important tweak you'll want to use to get Drush and the DAMP installer working in harmony: adding the acquia-stack php path to the drush helper script. Hopefully that issue will be committed soon, but in the mean time it's a very small fix: just add /Applications/acquia-drupal/php/bin/php to the bit where Drush searches for *AMP installations.

Once I had drush set up, I ran drush dl devel memcache-6.x-1.x-dev to grab the latest Devel and Memcache modules, since my eventual aim was to do some performance.module based testing.

And now we come to the fun part. See, while DAMP ships with a lot of commonly-needed libraries like GD and curl, it doesn't come with the php components to support APC or memcached, both of which I need for my tests. Thankfully JAM has my back, and we got support for custom php libraries baked into the latest releases of the DAMP installer. Those copy/paste instructions worked like a charm to install APC, so that was out of the way and it was on to memcached.

Memcached isn't just a PHP module, it's also the caching system itself, so we need to install that too. This is old hat to any linux/BSD-head who's built from source before, but for the uninitiated here's the voodoo.

First set up a nice working directory and navigate to that directory in your terminal. If you're reading this later than April 2010, you may want to see if there are more current releases of libevent and memcached and update the wget commands appropriately, but:

wget http://monkey.org/~provos/libevent-1.4.13-stable.tar.gz
tar -xzvf libevent-1.4.13-stable.tar.gz
cd libevent-1.4.13-stable
./configure
make
sudo make install

Same for the memcache daemon itself:

wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
tar -xzvf memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure
make
sudo make install

Then repeat Acquia's custom php library instructions for memcache.

Finally, start up a quick memcache bin like so:

/usr/local/bin/memcached -m 32 -d

At that point I'm ready to add the memcache settings to my local sites settings.php file and I'm off to the races.

Three cheers to Acquia, the Drush team, and to the makers of MacOS, Libevent and Memcached for (finally!) getting us to the point where building open-source projects is as simple as configure, make, install.

Comments

Doesn't sound very "simple" to me. Not so click-and-roll.

What Josh is describing here is absolutely cutting edge high-performance Drupal work, so it's not surprising that it's not simple. His work is goes into the awesome Project Mercury, which does make it simple for you to benefit from all this goodness as a product. This article describes setting up the development environment.

@Josh - the link to JAM is access denied unless you're logged in to Acquia.com. May be better to link directly to Jam's site: http://horncologne.com/

Thanks for the kind words, Robert! Link updated. :)

The DAMP installation is in fact quite simple. The rest, well, the only place I used the "simple" was in the phrase "configure, make, install." To those of us who've spent much time looking at library dependency or compiler issues trying to get hot hot opensource working (for instance Robert's very useful original memcache on Debian etch post; how far we've come in three years!), this is a really important kind of simplicity.

However, to the non-command-line developer, this is all voodoo. However, you can still pretty much copy/paste everything here without understanding it and get yourself a working environment. ;)

Thank you,

This is exactly what I was wanting to do but was deferring finding the time to get it working, thanks again for all the work with Mercury. One question, with your DAMP import of the Pressflow codebase, are you using the default site directory or the DAMP generated multi-site one? I noticed the drush command wasn't for multi-site. I have to manually change everything to the default directory when I do DAMP imports for some reason.

Good catch! I'm a fan of using multisite-savvy settings directories even when there's only one site involved. It makes the dev/staging/live transition easier because I can keep appropriate environment settings in their own files in version control the whole time, rather than rolling out a site on a new server and having it need additional configuration.

In this case, because I'm using drush dl, it doesn't need a database connection, so I can skip the uri parameter. If I wanted to enable the modules via drush, I would need to add something along the lines of --uri=mercury.localhost.

Good stuff. Would $ drush @aliasname work, too?

On Ubuntu Server 8.04 LTS, there is no need to build libevent from source, nor memcached either.

What is needed is to do:

# aptitude install memcached php-pear
# pecl install memcache

And you are done the installation part. No download, no configure, no make.

okey gen but now

Good catch! I'm a fan of using travesti multisite-savvy settings directories even when there's only travesti one site involved. It makes the dev/staging/live transition travesti easier because I can keep appropriate

environment travesti settings in their own files in version control travesti the whole time,

rather than rolling out a site on a new server and having it travesti need additional configuration.

When i write code in function “mytheme_form_id” العاب i would like to use $vars for setting some default values but $vars are not available in this function. My form is displayed directly in node template using node_add. Is there a way to alter form from preprocess node function?

Add comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br> <br/> <br /> <p> <img> <blockquote> <i> <b> <u>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.

Client Testimonial

We have found Chapter Three to be a valuable resource in both training and development of custom Drupal functionality. In addition, getting Chapter Three’s help with scaling Drupal has been a real asset.

Jim Nisbet, CTO Highwire Press

Drupalcon SF 2010