Memcached: Simple, Effective, and Powerful

Realizing once again I haven’t written a blog post for quite some time, I thought I would just write a few smaller posts on things I’ve learned these last few months. Hopefully I can get back into the habit of blogging regularly again.

This last month I finally broke down and learned how to use memcached.  While I have known about memcached for a very long time, I just never got around to using it. While I heard it was beyond easy to implement, I still assumed it would take a few days to get the hang of it and figure out its quirks. However, when the forces of high load on a webserver and the file-based caching system that I have previously used were found to be too I/O intensive, I had no choice but to take the plunge.

It took me about 4 hours to add memcached support to my caching class and to be up and running at blazing speeds. That was from the very start to finish. That included reading the documentation and installing memcached on our Ubuntu server. Not only was is very easy and straight forward, but it was extremely effective.

There have been technologies that once I’ve learned I never want to go back to the “old way.” Subversion, jQuery, XAMPP, and xDebug are a few of these. I am now adding memcached to that list. It is so simple and straight forward. There are no complex configuration files or loads of manuals to read. You basically pass it the parameters of the size of the cache, what IP to listen on, and what port to use. That is it, nothing more. Then, in your PHP code, you just pass the memcache class the server’s info and you’re done.

One useful script I found was for a memcached monitor. It allows for you to view the stats and easily flush your memcache instance. Here is a snap shot from this script on our memcached instance:

It gets up to 900 requests per second during peak times. It was amazing to this that before we had about 900 requests a second trying to read from our hard drive. This is so much more efficient.

If you’ve hesitated working with memcached, don’t! It is an amazing simple yet powerful tool. It can help any website. Maybe my next blog post will be on how we’ve made such an effective cache at 99.9%.

Justin is currently the Director of Development for the Deseret News. He is active in the Utah Open Source community. He is an advisory member of the Utah Open Source Foundation, and helps with the anual Utah Open Source Conference. He primarily focuses on PHP, MySQL, Redis, HTML, CSS, jQuery, and JavaScript. When he gets the time, he enjoys to play jazz piano. Read More

Tagged with: , ,
Posted in Programming, Technology, Web Design