Fix high CPU usage by WordPress and MySQL

Today one of our wordpress sites had very high server load and it was being caused by MySQL

So I went to the mysql console, and looked up the process list:

So this guy is appearing a lot
SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes';

Let’s see how it’s behaving with explain
explain SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes';

It’s scanning 226k rows to get its search results!

Probably some moronic plugin is doing this and wordpress does not add an index on that table. The solution is simple, let’s add an index!

ALTER TABLE wp_options ADD INDEX (`autoload`);

Now let’s run explain again

From scanning 226k it went down to 408!, 3 orders of magnitude drop.

And now the CPU load went below 4%, crisis averted.

How much RAM can your 64-bit CPU address?

Your old 32-bit CPU, could address up to 2^32 memory addresses, that’s 4294967296 different memory addresses, better said, “only” 4GB, something that 15 to 20 years ago was 1000 larger than any memory created at the time.

Now we have 64-bit CPUs, that means they can address up to 2^64, that’s 18446744073709551616 different memory addresses, better said, 16.8 million terabytes which is the same as 16 exabytes, which as of now (May 2008), represents way more than the total RAM ever created for all computers summed together.

Let’s see if in 20 years, 16 exabytes will be enough, I personally don’t think so, it never is, we always laugh at the tech limitations of the past, in no time we’ll end up with 128-bit processors and I’ll leave you the homework to find out how much memory those CPUs will be able to address.