I was building a website of my own and was onmy testing phase when I noticed its a little bit slow. It might be because i have too many graphics loading and heavy database when doing some searching. I searched Google ways to speed up websites and i found out about memcached and found some article on how to install the said application. I tried it and I noticed a big difference on my website’s performance.
Memcached is a distributed, high-performance, in-memory caching system that is primarily used to speed up sites that make heavy use of databases. It can however be used to store objects of any kind. Nearly every popular CMS has a plugin or module to take advantage of memcached, and many programming languages have a memcached library, including PHP, Perl, Ruby, and Python. Memcached runs in-memory and is thus quite speedy, since it does not need
to write to disk.
Here’s how to install it on CentOS 6:
Memcached does have some dependencies that need to be in place. Install libevent using yum:
yum install libevent libevent-devel
The memcached install itself starts with
To start installing memcached, change your working directory to /usr/local/src and download the latest memcached source:
cd /usr/local/srcwget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
Uncompress the tarball you downloaded and change into the directory that is created:
tar xvzf memcached-1.4.15.tar.gz cd memcached-1.4.15
Check memcached.org for a newer version before proceeding with the installation. Their might be newer version existing after the publication of this post. Please note the tarball version we are using is
Next, configure your Makefile. The simplest way is to run:
Additional configure flags are available and can improve performance if your server is capable. For 64-bit OSes, you can enable memcached to utilize a larger memory allocation than is possible with 32-bit OSes:
If your server has multiple CPUs or uses multi-core CPUs, enable threading:
If your server supports it, you can use both flags:
./configure --enable-threads --enable-64bit
n.b.: if the configure script does not run, you may have to install compiling tools on your server. That is as simple as
yum install gcc yum install make
Once the configure script completes, build and install memcached:
make && make install
Last but not least, start a memcached server:
memcached -d -u nobody -m 512 -p 11211 127.0.0.1
Put another way, the previous command can be laid out like this:
memcached -d -u [user] -m [memory size] -p [port] [listening IP]
Let’s go over what each switch does in the above command:
- Tell memcached to start up as a backgrounded daemon process
- Specify the user that you want to run memcached
- Set the memory that you want to be allocated my memcached
- The port on which memcached will listen.
Now your site is ready for a fast run literally.