Trading APC for Zend

When the big dogs switch to Zend, it's time for the little dogs to do it too. Gain some speed and style with Zend Optimizer+, coming soon with PHP 5.5

zend-optimizerThe last thing I did before Passover was a totally unannounced, not telling anyone, surprise flip from my old standby, APC, to the new hotness, Zend.

As of PHP 5.5, Zend Optimizer+ will be included. Back in 2009, I decided to use APC for a couple reasons: It was made by the PHP blokes and it worked well with mod_php and MediaWiki. Since PHP decided to change, I joined in. Why the change? Zend went open source.

Installing Zend

I grabbed the latest tagged version from the official GitHub repository, since I don’t cotton to using bleeding edge all the time.

$ wget https://github.com/zend-dev/ZendOptimizerPlus/archive/v7.0.1.zip
$ unzip v7.0.1
$ cd ZendOptimizerPlus-7.0.1/
$ phpize
$ ./configure
$ make
$ make install

That gave me the final output of: Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20100525/ You want to hang on to that path, because we’re going to edit php.ini and put this in below the line for IonCube, if you have that installed:

 zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20100525/opcache.so

Replace the path with your own.

I also followed their advice on the recommended config and put this in my php.ini as well:

[Zend]
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1

Since I had APC there before, I removed all those lines while I was at it. Restarted PHP (well, httpd in my case, I like a clean slate) and I was done.

Cleanup

As I mentioned before, I removed the APC lines while I was in the php.ini and, since I installed it via a downloaded pecl, I just removed the apc.so file from the same folder where opcache.so was installed.

On WordPress, I also removed the APC Object Cache Backend plugin from the two sites that had it, since I’m not using APC. There doesn’t appear to be an equivilent for Zend, but I may or may not need that.

For MediaWiki, I had to edit LocalSettings.php and remove $wgMainCacheType = CACHE_ACCEL; as that’s no longer being used. Then I went into my maintenance folder and ran php rebuildLocalisationCache.php --force to flush everything and my errors went away. MediaWiki has a pretty different cache method than other apps, and for yonks flat out didn’t work with Zend. It does now, and there seemed to be no speed loss without an OpCode cache.

None of my other apps seemed to care, so I moved on to see how this all played out.

Results

Much like the ManageWP guys, I saw an immediate drop in memory and CPU. And I’m still on PHP 5.4! There was an initial spike while I was mucking around, which I expected, and then everything dropped. Some things did not so much drop as level out and change my ‘spike’ range. Normally my load average for 1 minute would spike at 0.8 or so every hour. Now it’s spiking at 0.5, give or take, which is a success in my book.

Load Avg 5min - Post Zend
Can you guess when Zend went on?

Before someone points out that, hey, this is hardly a real check, I want to note that I was having one of those 200% traffic days. Actually I was having a few of them in a row, and I know it’s going to go up from there. Here’s a quick look at my traffic:

traffic ga-traffic

The real test will be tonight and tomorrow, though, as I push some large data (videos) on a popular topic, but frankly, this is looking good.

The benchmarks used in the ticket to include Zend in PHP (why are they using WP 2? I have no idea) were startling compared to normal PHP. Compared to APC it’s a minimal kick in the pants, but the assurance of bundling to come speaks for itself. This is where PHP is going.

APC v Zend Benchmarks
Credit: Dimitry

I’m not yet on PHP 5.5, but I’ve already found that 5.4 is a notable kick to my speed. Zend took me from a B to an A in PageSpeed and YSlow (when you tell YSlow that I’m a small blog and not Amazon). Also it ‘feels’ faster, which is totally subjective, but still a valid remark. The site feels fast, it doesn’t hang (yet) and it didn’t crash over Passover!

Former bbPress regular, _ck_, went and wrote a neat little Control Panel for Zend Optimizer+ which I snagged and tossed into my secret bin for poking at later.

Since I’m the Zend Rookie, anyone have any tips and tricks for configuring it to make it sing? Remember, I don’t just use WordPress on this box!

32 Comments

  1. It looks like it includes a key/value store. Someone should write a WordPress object cache backend!

  2. I think RFC explicitly listed that it doesn’t do key/calue cache as downside comparing to APC? https://wiki.php.net/rfc/optimizerplus#alternatives

  3. Zend Optimizer is not a drop in replacement for APC. As it is strictly an opcode cache, it lacks a userspace cache. To get a key/value cache (like for WordPress object cache) you will also need something like Memcache or Redis.

  4. I bet your database queries will have gone through the roof without an object cache backend.

    Fingers crossed someone makes an object cached backend for it soon.

  5. Are you using a static caching solution?

    • You mean like how WP Super Cache and W3TC do? No. I was having serious issues with it keeping up with traffic (go on, laugh). It was causing me more churn when my really active site was getting a lot of comments, and either I got near thrashing when it kept flushing cache with new comments, or the comments didn’t show up anywhere close to real time. That’s when I said fuckit, put in more memory and Google PageSpeed.

    • I have a boner for Batcache. It makes static caching much more pleasant 🙂
      http://wordpress.org/extend/plugins/batcache/

      You can set it to only cache the pages which are visited the most frequently and you can make it refresh the cache very often, so you don’t get those annoying cache flushing issues like you do with W3 or WP Super Cache. Win win 🙂 Bjørn doesn’t seem to like it very much those :/

    • The problem is the pages hit most frequently are the ones I don’t want cached!

      Put it this way, the highest trafficked pages on the breaking news site (which is not Ipstenu News, sorry 😉 ) are:

      1. Post from yesterday
      2. Post from today
      3. Front Page
      4. Video Page

      Only pages 3 and 4 would I want to cache right now :/

    • May I ask why you wouldn’t want to cache them?

      I use a 300 second cache time on http://geek.ryanhellyer.net/, but I’ve been known to set it down to 30 seconds when I need it refreshed more often. Since it uses an object cache backend instead of static files, it’s able to refresh the cache much more efficiently and so the constant refreshing process isn’t a problem.

      WP Super Cache can probably serve pages faster, but the ability to refresh the cache rapidly is much more important to me, if only to save my (remaining) sanity.

    • I had to weigh the traffic of the site with the need to be a communication ‘center.’ I’m halfway between a ‘normal’ site and a ‘live blog’ on that particular site, and right now I’m able to maintain speed and functionality without a static cache plugin. The amount of dynamism I was losing was painful, and people complained. When it’s noticeable to people that there’s a cache, something’s wrong. Now that said, if it gets worse I will look into Batcache (nananananananana BAT CACHE) as the description reads like what I’m looking for:

      Batcache is aimed at preventing a flood of traffic from breaking your site. It does this by serving old pages to new users. This reduces the demand on the web server CPU and the database. It also means some people may see a page that is a few minutes old. However this only applies to people who have not interacted with your web site before. Once they have logged in or left a comment they will always get fresh pages.

      But … y’know I don’t want to use a plugin if I don’t have to. I don’t believe the fallacy that more plugins == slower sites, but at the same time I try to never use a plugin I don’t need right now.

      Zend Optimizer+ + Memcached + Google Pagespeed + enough memory.

      And yeah, I have enough memory. Before I upped the memory to 2G, even W3TC was struggling to keep up. I was just too big 🙂 The main site that causes this traffic gets 100k a month, and then you have to add in the Ipstenu Network and three other fansites. It adds up to quite a lot of traffic on the server, and one is a forum that simply cannot live by caching. Oh yeah, just TRY to cache shit with a forum and you will cry really fast. Faster than I do when I see a ticket start with “I’m having a problem with TimThumb…”

    • There might be nothing wrong with Batcache, but I have no idea on how to control it … Also, a disadvantage compared to other solutions is that all requests will still hit PHP. With other caching solutions like WPSC, W3TT, Varnish or Nginx the requests will be served from one level higher up allowing for more requests per second.

      That said, for people who don’t want to or know how to configure caching, I recommend Batcache. It’s a drop-in-and-forget solution that works well.

    • I thought WPSC and W3TC still hit PHP to do processing….

    • Nginx or Varnish caching seem nice. But unless WP Super Cache or W3 can handle refreshing their cache more regularly, I’m going to avoid them. I’ve had way too many problems with caches not refreshing when I need them to.

    • I’ve been using http://wordpress.org/extend/plugins/varnish-http-purge/ on my nginx setup at DreamHost (to the point that Shredder and I took over the plugin)

  6. BTW: I have a friend with a WordPress site that gets 85-100k page views every month. It runs very well on a server with 512 MB RAM and W3TC.

    • When I was only having one site with that much traffic it was fine 🙂 Multiply that by three, and add in a handful more sites on the server plus other projects.

      I keep telling everyone, I don’t JUST run WP on this stuff 😉 If it was only WP, my life would be way simpler. (And with W3TC, I can get by at a gig so long as I don’t have a massive slam of traffic).

  7. Ryan pointed me here 🙂 I highly recommend nginx micro cache (aka fastcgi_cache), there’s a nice guide at http://rtcamp.com/tutorials/nginx-wordpress-fastcgi_cache-with-conditional-purging/ If you want conditional purging, you have to add the nginx purge_module to nginx.

    btw, I “had” to test opcode+, it doesn’t play well with newrelic

Comments are closed.

%d bloggers like this: