Home » Reflections » Apache and MySQL Memory Optimization

Apache and MySQL Memory Optimization

If you didn’t catch my blog post last month, I moved ocabj.net to a Linode VPS after about 13 months running on Dreamhost (and before that a couple years on Bluehost). Without getting too deep into it, I was basically unhappy with site performance (specifically load times) on Bluehost and Dreamhost.

But that’s what you get with shared hosting, right?

Anyway, I moved to a Linode Virtual Private Server (VPS) and with my blog’s regular volume of traffic, I opted for the lowest end Linode account option which consists of 512MB RAM. This is more than enough for a LAMP server with my website’s normal traffic.

Linode has some basic built in monitoring for the VPS with graphs, and I was regularly getting alerts that my VPS host was exceeding the disk I/O rate threshold. I raised the threshold beyond the default limit (since thresholds should be based on some level of normalcy). But every couple days, I would still get alerts about the threshold being exceeded.

Looking at the graphs, I did notice that the disk I/O rate spikes were directly correlated to swap space I/O. Translation: My VPS was regularly needing to swap from physical memory to swap space because it was running low on memory.

Upon that revelation, I decided to see what I could do to tweak Apache and MySQL, since those are the only services running on the box.

Thankfully, Linode has a nice library of documentation which contained a short write-up on “Troubleshooting Memory and Networking Issues”. After using the Apache and MySQL tweaks discussed (minus disabling InnoDB, because I have some databases with InnoDB tables), my disk I/O rates became virtually flat.

In the above graph, I implemented the Apache and MySQL memory optimization tweaks at approximately ~2230PST. From then on there is virtually no Swap I/O activity.

Doing random real-time memory usage tests through the day after I implemented the optimizations, I saw that the VPS was never having to swap memory to disk.

While this may not be exciting for everyone else, this is actually quite exhilarating for me since I have improved the performance of my website significantly since the move from Dreamhost to Linode.

So if you ever need to optimize your LAMP environment while running on a resource limited (specifically RAM) host, you definitely need to modify the default Apache and MySQL configurations.

Follow Jonathan Ocab:
Owner and administrator of ocabj.net

Comment on this post

This site uses Akismet to reduce spam. Learn how your comment data is processed.