I was testing memcached in one of my cluster. It is seems to be very useful to increase performance. As it is “Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.” , Read more about http://memcached.org/, and see who all are using memcached.

But the main thing is your application need memcached support otherwise it won’t work.

So Openx have a plugin for memcached support. This will help your openx faster delivery via delivery cache. To enable this plugin go to Global Settings > Banner Delivery Settings to choose memcached caching of banners. Don’t enable it if you are not installing the following packages.

Before enabling this plugin you must need to install a perfect memcached server in your openx server. So please proceed the following instructions.

Install memcached server

Download the memcached server from http://memcached.org/

 # wget -c  http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
 # tar -xzf  memcached-1.4.5.tar.gz
 # cd memcached-1.4.5/
 # yum -y install libevent libevent-devel
 # ./configure --prefix=/opt/memcached
 # make
 # make install

Now the installation finished. Let us use the following command to start memcached .

#  /opt/memcached/bin/memcached  -u nobody -d -m 128 -l 127.0.0.1 -p 11211

In the above command memcached will start as a daemon and listen on port 11211 on 127.0.0.1 . Here -m 128 means the amount of memory it can use, here 128 MB of RAM.
So let us create an init script for start/stop of memcached. /etc/init.d/memcached

#-------------------------------------#
------------
#!/bin/sh
#
# Memcached        This shell script takes care of starting and stopping
#               Memcached.
#
# chkconfig: 2345 95 55
# description: memcached is a memory caching server

# Source function library.
if [ -f /etc/init.d/functions ]; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
  . /etc/rc.d/init.d/functions
else
  echo "Could not find functions file, your system may be broken"
  exit 1
fi

# Source networking configuration.
if [ -f "/etc/sysconfig/network" ] ; then
        . /etc/sysconfig/network
fi

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -f /opt/memcached/bin/memcached  ] || exit 0

# See how we were called.
case "$1" in
  start)
        # Start daemons.
        echo -n "Starting memcached: "
        /opt/memcached/bin/memcached  -u nobody -d -m 128 -l 127.0.0.1 -p 11211
        echo_success
        echo
        touch /var/lock/subsys/memcached
        ;;
  stop)
        # Stop daemons.
        echo -n "Shutting down bandmin: "
        pkill -9 memcached
	pkill -9 memcached
        echo_success
        echo
        rm -f /var/lock/subsys/memcached
        ;;
  *)
        echo "Usage: memcached {start|stop}"
        exit 1
esac
exit 0
#-------------------------------#

Now give execute permission to init script as follows,

# chmod 755 /etc/init.d/memcached

If you need to start this server during reboot , please add the following line to /etc/rc.local

# /etc/init.d/memcached  start

So our server is ready. Now we need ton install the php-pecl memcached extension. Otherwise your application won’t work,

Install php-pecl memcached

Download the latest stable memcached from http://pecl.php.net/package/memcache

# wget -c http://pecl.php.net/get/memcache-2.2.5.tgz
# tar -xzf  memcache-2.2.5.tgz
# cd memcache-2.2.5/
# phpize
# ./configure
# make
# make install

Now restart apache and create a phpinfo page and test whether the memcache options is showing or not. If it is there go to Openx admin and enable the plugin.

Leave a Reply

Your email address will not be published. Required fields are marked *