Category Archives: General

Optimizing WordPress on Pair.com

This weekend I got a little fed up with how slow WordPress seems to be on Geekfun and PetProject, my wife’s blog and set out trying to figure out why.

First off, I went looking on The Google for what other people had to say about optimizing WordPress.  Much of what I found is a few years old, and applied pretty specifically to older versions of WordPress.  Just now, I found a post written just today on the subject of optimizing not just WordPress, but WordPress 2.7, which was only released a few days ago; unfortunately, pretty much all of the advice covered things I already knew about.  One post I found was almost two years old, but the advice it gave was general enough to be relevant today.  Unfortunately, it wasn’t all that relevant to me, since it covered things like tuning mySQL, and using a PHP opcode cache, neither of which I can do on Pair.com’s shared hosting.  In the end, the biggest benefit from this research was learning some of the things I’m unable to do to make WordPress faster.

Armed with that reality check, I started focusing on figuring out what, exactly, was making WordPress seem slow on our sites.  I started out by measuring just how slow things were.  I turned to the Firebug plugin for Firefox for help there.  Firebug does a lot of useful things, but I was most interested in its ability to chart out how long it takes to load each page component.  I didn’t write down the specifics because I already knew the answer was too damn long.

What I did note is that it was taking a second or more before the browser even started receiving the beginning of the page HTML, and then it was taking another few seconds for all the HTML to arrive.  Once enough HTML arrived, the browser would request the CSS files, which would show up, eventually.  Once this happened, the browser could start rendering the page and fill things in as images and whatnot showed up.  It takes something on the order of 4-5 seconds for a new visitor to actually see the web page.  Too damn long.

First thing I noticed is that pretty much none of the HTML, CSS or Javascript on my blog was being transmitted in compressed form.  I thought this odd, because compression can easily shrink file sizes 2-4x or more, which really helps with transmission time.  I knew this, and I knew that I’d turned on gzip compression in WordPress a year or so ago, and I’d been quite happy with the results, so it was doubly odd that it didn’t seem to be coming into play.  I went looking for the WordPress option to turn it back on, but turned up nothing.  Googling on this one was pretty useless. I found a lot of stuff about turning on gzip compression in earlier versions of wordpress.  Finally, I found something about how they’d removed it in 2.5 because it created vaguely described problems.  The advice was just to turn it on at the Apache webserver level.  Excellent advice, but Pair.com isn’t running mod_gzip or mod_deflate. Grrrrr.

I ended up finding a few plugins that could help me.  First I looked at the gzip output, but for some reason, I didn’t even try installing it, I think because I was hoping to find something that would compress my CSS and Javascript files too.  The WordPress version of PHP Speedy seemed like it would be ideal.  It will compress dynamic pages, and it will compress and cache static javascript and css.  In addition it can do other tricks to combine css and javascript into a smaller number of files to improve performance further.  Actually, its these file combining tricks that are PHP Speedy’s raison d’ etre, where as the straightforward stuff like gzipping stuff before sending it was optional.  This mattered, because some things seemed a little busted with my pages when PHP Speedy was running.  It’s a cool idea though, I’ll have to check back.  Script Compressor will compress both CSS and Javascript, but it looked like it might require me to modify template files, and even without modifying template files, it broke my pages.  I then turned to WP JS & WP CSS, wich optimize, gzip and cache their respective file types, but, unfortunately, they appear to require template modification, something I’m hoping to avoid, since it will make it more difficult to upgrade my theme.

I have a feeling I’m going to come back to JS and CSS compression before too long, but for now, I’m taking advantage of having the HTML itself compressed.  Right now, I’m using the GZip output plugin to compress the HTML on this blog, and taking advantage of the compression feature of WordPress Super Cache on my wife’s.

WordPress Super Cache comes up a lot when you go looking for info on optimizing WordPress.  Gzipping pages is really just secondary to its main function, which is caching static versions of wordpress pages and then serving them up without loading most of WordPress, or even involving PHP at all.  It is pretty elegant in doing what it does, but it doesn’t sit quite right with me.  First off, it does nothing for the css and js files, I still have to find a solution for that.  More importantly though, it strikes me as wrong that I have to rely on static pages just to provide a trickle of users with something approaching reasonable performance.  This is not to slight WP Super Cache, its main focus is less about simple performance, and more about being able to service high loads effectively.  So, I have a principled objection, but I’ve activated it on PetProjectBlog and its helped out a lot.  Normally it takes WordPress somewhere shy of a half a second to a second to produce a page.  With WP Super Cache, once that page has been produced once, subsequent requsts are filled in a tenth of a second or less.

WP Tuner provides a detailed view inside of WordPress.  Most (if not all) WordPress themes record the total execution time and number of queries required to produce a page in a comment in the footer of the page.  From this, I learned that it was taking somewhere between a half-second and a second to generate a page, which already represents a significant % of the response time I’d like to see.  WP Tuner helped me understand where that time was being spent.  It shows the time taken by 12 or so major parts of the WordPress page creation process, and how much of that time was spent waiting for the database.  It also shows what’s using the database at a finer grained level, and can show, in detail, which queries were run.

The first thing I learned is that something like 50% of the time spent by WordPress just goes to starting up (which it has to do for each request).  By sticking some timing statements into the WordPress startup code I was able to see that a big part of that goes to starting up the 12 or so plugins I have active, with about half of that spent starting just a few plugins.  The amount of time spent in startup bothers me, but I couldn’t figure out what I could do to reduce it significantly.  Even giving up the functionality provided by the most startup-intensive plugins would only shave ~12% or so off the overall request time.

Less than 5% of the startup time and only about 10% of the entire request processing time was spent doing database queries, which I was glad to see.  I’d been worried that my hosts database servers weren’t carrying their weight and I’d spent some time trying to understand what the state of WordPress DB caching was since this is another area that has evolved a lot over the last couple of years.

I think that brings me to where I am now.

  • Both blogs are benefitting from gzip compression of the HTML to shave the better part of a second off the time it takes to receive the all the HTML.
  • PetProject Blog has shaved 300-900ms from the time it takes to even send the first part of a page by using WP-SuperCache.
  • I still need a solution for compressing javascript and css files.  I think I’ll probably end up with a small shell script that runs through the plugin and theme directories and gzips all the appropriate files, then I’ll put in some mod_rewrite rules to serve the compressed versions to compatible browsers.  Ideally, I’d like a PHP script that produces the .htaccess rules and compresses assets the first time they are requested without having to modify any of my themes, but that would just be gravy.
  • I’d like to find a way to halve startup time without giving up functionality.  I think this will probably require that I find hosting that includes the use of an PHP opcode cache.
  • Alternate hosting may help by getting me on a faster machine.  Right now, Pair.com has me on an AthlonXP 2800+ with 2GB of RAM.  That’s not a bad machine for a lot of things, even though it must be 5 years old, but it ain’t great for a shared webserver that hosts some dynamic apps.  It only has one core, and that core is probably, at best, half as fast is one of the cores in the CoreDuo machines they have.  When it comes down to it though, I don’t have a good idea of how much a faster CPU will help.  My guess is that random disk IO is a big part of the startup cost, and the CPU isn’t going to help there.  If I have time, I’ll have to try setting things up on one of my home machines and see how things break down.  Short of finding a new host though, I can probably get Pair to move me to a newer machine.  I’ve been a customer for a decade or so.
  • Beyond this, I could look to pushing static assets, including css, javascript, and at least some of my images off to a different IP (to get around limits browsers place on multiple requests from a single server), or taking advantage of Amazon’s new CloudFront pay as you go Content Delivery Network which would push things out to servers geographically closer to users.

Update: I tried running WordPress on a machine at home with the same basic set of plugins.  Per-request startup times were still on the order of 250-300ms, even though the machine was completely unloaded, had plenty of RAM free, and has a faster processor than the machine my site is hosted on at Pair, which makes me think that I/O is the big issue.

Next I installed the APC, which among other things, caches the parsed application code in memory the first time its loaded.  This made a huge difference.  Startup times dropped 10x to about 25-30ms, which had the effect of cutting the total request processing time by half.  Much much better.  I also noted that the per requrest memory consumption also dropped significantly, from 11MB to about 1.1MB.  Unfortunately Pair.com doesn’t include APC, probably because it can take some tweaking to get it to work stabley with some PHP apps.  Also, it may have security issues in shared environments.  It looks like I’m going to have to try alternative hosting if I want to improve WordPress performance further.

Obama Chooses Chu, Lays Down Some Science

Barack Obama is naming nobel prize winning physicist Steven Chu as energy secretary. This makes me happy.

It makes me even happier that he’s said “ethanol is wonderful stuff, but I’d rather drink it.

(thanks to Luke Frankl)

Chu won his nobel prize for experimental work in cooling and trapping atoms via lasers. In recent years he’s been working in the area of biophysics at UC Berkeley and is director of Lawrence Berkeley Laboratory. He’s also been very active in the area of climate change, and advocating alternative energy and energy efficiency.

Killer Bargains

Last Friday was “Black Friday,” the day after Thanksgiving, the start of the holiday shopping season. It is also, by popular lore, the day retailers annual balance sheets tip into the black, all further revenues for the year are profit.

It is the busiest shopping day of the year, and over the years, retailers have done more and more to make sure that shopper’s enthusiasm isn’t left to chance. Extreme loss leaders, like various consumer electronics at discounts approacing half price are common place, though only available in limited quantities. Throw in a few weeks of increacing hype by the media, and on Friday morning you have people in front of malls and people waiting in line for the better part of a day.

It’s hardly surprising then when they start to act like a mob, as they did this past Friday when a mob of shoppers broke through the doors of a Wallmart, injuring shoppers and workers and trampling to death a temporary worker.

Of course the greed and callousness of the crowd is repugnant, but what of the retailers who foment a riot to try and drive sales. Wallmat itself is cuplable here, and the entire industry stands alongside them as codefendants, with much of the media as witting accessories.

Certainly going forward, when the next Black Friday casualties are tallied, none should be able to claim that they didn’t know the evil they were summoning.

Qwest Starts Hijacking DNS

I guess this may have started a few months ago, but I just noticed today that Qwest.net, my ISP and DSL provider, has started hijacking incorrect domain names.

The way the interenet is supposed to work, is that when you click on a link in your browser, or type in a url, your computer asks a nearby DNS server (usually at your ISP) what IP address is associated with the hostname (ie geekfun.com). The DNS server asks a succession of other DNS servers for the answer. If it doesn’t get a satisfactory answer back, it lets your computer know that there is no IP address associated with the name. Whatever application you are using can then decide how best to handle the error. If the DNS server tries to get clever, and provide an IP# of one of the ISPs webservers instead, you get deprived of a useful error message.

Other ISPs have been doing this for a while. They position it as helpful service, but in actuality, they do it because they get a cut of ad revenue on the pages they redirect people to.

Qwest is taking a somewhat conservative approach in rolling this out. They aren’t hitting you with the ad pages right away, they serve a page telling you that they are going to start hijacking your typos (not that they are so plain-spoken about what they intend to do), and they give you an easy way to opt-out, which I’ve done.

Still, one more thing to be aware of when trying to diagnose a name resolution problem.

John McCain’s Last Full Measure of Devotion

Watching John McCain since the Democratic convention has been unsettling. There have been some ups, but it has been mostly down as he’s discarded virtually every last scrap of his dignity and integrity.

There are those who’ll argue that he had never really had either, at least not in the quantities that he’s been credited with. While many will afford him a great deal of honor for suffering torture as a POW in Vietnam, some will deny even that, because Vietnam was a deeply unjust war. Others allow it, but diminish it, pointing out that his treatment improved after his captors realized that he, along with his fellow POWs might be more useful as bargaining chips. They’ll point to the circumstances of his divorce from his first wife, and how that overlapped with the courtship of his current wife. They’ll point to his role with the Keating 5. They’ll point to the fact that he continues to call his captors “gooks.”

I think that the truth is, as always, a bit more complicated. One of the foundations of the western cannon is an epic Greek poem about a soldier’s trials when returning home from war. That McCain’s first marriage didn’t survive is all too human a tragedy.

On the other hand, I think his role in championing normalization of diplomatic relations with Vietnam is a triumph of good character. Some will paint it a hypocritical, against his use of raciat slurs, but I think that just shows the depth of his character. I think it takes a lot to sit down and work with people despite old animosities. When McCain says he’s only speaking of his captors when he uses such an angry slur, I believe him, and I allow him that.

It’s much harder to find either sympathy or empathy for the course McCain has taken these last couple of months. His choice of Sarah Palin seemed, at first, to be cynical gender politics, but it quickly became clear that it was more than that.

Picking Sarah Palin aligned John McCain with the radical religious right. It aligned him with the same divisive politics that was used to initiate and prolong Bush’s disastrous term in office. It aligned him with the politics that sent Bush pursuing an immoderate agenda in a country that was almost evenly divided. It aligned him with a politics of fear.

In the time since, it has become increasingly clear how committed he’s become to this strategy. It started when McCain tried to defend Pailin’s inexperience with exaggerations and falsehoods. Then there were the whisper campaigns against Obama that looked suspiciously like the work of the people who used the same tactics against McCain to win the republican nomination for Bush in 2000. If there were any doubt about the source of those tactics, they were erased when Palin turned the whispers into a rallying cry and McCain followed suit soon after.

Since then John McCain’s campaign has accused Obama of running the most negative campaign in history, even as McCain’s campaign ads have been almost 100% negative, and his rallys have been mostly devoted to attacking Obama and trying to paint him a dangerous radical.

It has been clear that this strategy is doing nothing more than whipping the extreme right into a violent froth even as it drives swing voters, and even more moderate Republicans, to Obama.

So going in to the debates last night, McCain had nothing to loose but whatever scraps of his integrity remain. He could have distanced himself from the dangerous insinuations he and his supporters have been making about Obama, or even repudiated them.

Instead he again tried to paint Obama as a terrorist sympathizer by association with William Ayres. He tried to both pin the financial crisis on Obama, and implicate him in massive voter fraud by tying him to ACORN. It didn’t work. His attack was clumsy, but even if his execution had been flawless, it wouldn’t have mattered.

John McCain sacrificed the last of his honor of integrity last night, but what end did his sacrifice serve? McCain makes a big deal about self-sacrifice, and he talks a lot about putting country first. McCain didn’t put country first last night. In 2000, this country was almost evenly divided in its choice for president. In 2004, in the midst of war, with 9-11 fresh in our minds, the presidential election was still close. The 2008 election hasn’t been held yet, but its clear the country is leaning away from McCain, and even more strongly away from the extremism he’s been embracing.

Last night, John McCain put a narrow sliver of the country first. He put it ahead of his honor, he put it ahead of the rest of the country, he even put it ahead of the Republican party. Last night McCain sacrificed himself for the extremist wing of the Republican party. I don’t look forward to the repercussions.

I fear that McCain has stirred up such anger that someone will take a shot at our next president. I fear that the Democratic party will lack a moderating opposition in the coming decade. My only hope is that whatever effective opposition eventually reconstitutes itself from the Republican party, exiles the corruption and authoritarianism that’s taken hold, and renounces the cultural warfare that’s been used to provide cover for their advance. My hope is that the Democratic party is similarly cleansed.

The Future of Apple TV?

A year or so ago, I started writing a post thinking through the AppleTV business, and how it related to the iPod business. I never finished the post, and I never felt like I quite had a hold on all the pieces.

One thing I did conclude though, was that the margins on the AppleTV would improve significantly in the space of a year or so. My rationale was that the hardware requirements of the AppleTV were largely tied to the demands of HD video playback, which given the dynamics of the consumer electronics industry, were pretty much fixed. As a result, Apple wouldn’t feel much pressure to upgrade the hardware, other than the storage, and so they could ride Moore’s law on down as the CPU and video chips declined in cost and then merged into a single chip.

My other thought was that Apple would also have the option of giving up some of their improving margins in order to improve the graphics capabilities of the AppleTV and make it a platform for more interactive entertainment, like video games. This is, of course, a tough market to enter, but its something Apple will likely have to confront at some point since the both Sony and Microsoft have other ambitions for the living room beyond high-end console gaming. A reasonably capable AppleTV would be capable of running a lot of existing Mac games, and might persuade more developers to do Mac versions of games.

I was reminded of all of this because of a recent rumor that Apple was planning on releasing a line of network-capable flat panel TVs with AppleTV functionality. I hadn’t considered this before, but in retrospect, its a natural progression that takes advantage of the declining costs of AppleTV hardware, Apple’s existing relationships with flat panel manufacturers, and the strength of their position in the entertainment market with the combination of the iPod and iTunes.

We’ll see if it turns out to be true.