Site/App Performance

Memcached

What is caching?

Servers have limited resources, and at any given time of high traffic, one or more of these resource limitations may create a bottleneck. A server–no matter the size–can only handle so many requests at a time. But what if there was a way to ease the burden when a server is asked to serve up the same information over and over?

Think about a WordPress site. Each page a user visits is not a single file, but rather an amalgamation of the theme, widgets, posts, footers, headers, etc. Each time a page is accessed, PHP will generate the page requested on the fly from the database. It takes time to query the database to create the page. These database queries put a strain on the resources of your server.

However, what if instead of continually generating a new page–the same page–for every visitor, you turned those pages into static HTML files? No database querying would be needed for new visitors. And a static file can be served up much faster and with significantly less resource consumption. Your visitors see their requested page sooner, and you save on CPU cycles. Everyone is happy. This is what caching does.

Memcached

Memcached is a general-purpose, free and open-source distributed memory caching system. It is one of the most popular caching tools and is used in such popular sites as YouTube, Reddit, Zynga, Facebook, and Twitter. If you also run dynamic, database-driven sites, Memcached may reduce resource consumption and speed up page delivery on your server as well.

Installing Memcached (daemon)

The quickest and easiest method is to install Memcached via Yum on the command line of your server.

  1. Grab the RPM that matches your OS:

CentOS 6 (64 bit):

su -c 'rpm -Uvh http://mirrors.kernel.org/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm'

CentOS 6 (32 bit):

su -c 'rpm -Uvh http://mirrors.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm'

CentOS 5 (64 bit):

su -c 'rpm -Uvh http://mirrors.kernel.org/fedora-epel/5/x86_64/epel-release-5-4.noarch.rpm'

CentOS 5 (32 bit):

su -c 'rpm -Uvh http://mirrors.kernel.org/fedora-epel/5/i386/epel-release-5-4.noarch.rpm'
  1. Install it with Yum:
yum install memcached
  1. Start the memcached service:
/etc/init.d/memcached start
  1. Configure the memcached service to start when the server boots:
chkconfig memcached on
  1. Finally, disable the RPM so that it is not used for future Yum functions:
perl -pi -e "s/enabled=1/enabled=0/g;" /etc/yum.repos.d/epel.repo

Of course, if you think Memcached may be right for your server, but you’re not ready to install it yourself, just open up a support ticket in your customer portal and the MST will be happy to help.

Configuring Memcached

A main benefit of Memcached is also a drawback. It is language independent so it can work in many environments. But specifically because of this, it needs to be coded into the site to do its job. If you’re not fluent in PHP, a qualified web developer can do this for you.

Alternatively, check the sites of any third-party software running on your server to see if they have a plugin that allows you to use Memcached without further coding.

Check back next time, we we discuss how to install the PHP memcache extension.

Find out more about ServInt solutions

Starting at $25

Comments
  1. I understand this is an introductory post about Memcached, although one important issue that should be noted and implemented is security. Memcached does not provide any built-in security, so any requests to port 11211 (the default) will be accepted. A quick solution is to add a rule to the firewall running your Memcached instance to only allow connections to your web application's host.
  2. [...] written for the ServInt blog as part of the ‘Tech bench’ series. You can view it on the ServInt blog here. Used with permission. Related Posts:How to install Icecast centos 5, centos 6, [...]
    How to install Memcached on CentOS | BoomShadow.net /
  3. @Bill >>what if you’re running on CentOS 4.9? We hadn't included CentOS 4 because it is going to be End of Life (EOL) this coming Feb. 29th. You can install memcached for CentOS 4 by getting it's EPEL RPM: su -c 'rpm -Uvh http://mirror.symnds.com/distributions/fedora-epel//4/i386/epel-release-4-10.noarch.rpm'
    Jacob "Boom Shadow" Tirey /
  4. >>Yes, Memcached can work with suPHP, but your site has to be coded correctly. That's a bit too cryptic :-) Could you please explain in a little more detail?
  • Hosting Advice
  • The New York Times
  • The Hill
  • Bloomberg
  • The Seattle Times
  • Computer World
  • Ars Technica
  • MSNBC

To engage with the ServInt Sales Team use the following chat icon. Normal sales hours are Monday-Friday 9am-5pm EST but feel free to leave a message and we will follow up as soon as possible.

Sales Chat



To engage with the ServInt Support Team you must be logged into our Customer Portal for identity verification and have a ticket opened about your request or there will only be limited support offered.

Support Chat

CLOSE