Sample Linux Memcached Daemon Configuration – Unix Sockets
Taken from here:- https://www.drupal.org/node/1181968
This is useful, rather than creating difference instances on the localhost 127.0.0.1 with different ports, you can create UNIX sockets instead which are faster as they bypass the TCP/IP stack in linux, and windows as well so i’m told. In this example, drupal has been split up, and each object in the framework is cached and saved to a different memcached instance and socket. I’d like to try this on a future project by caching a network game servers functions using memcached, and do lazy bulk database updates. Obviously if the server crashes, you lose a period of time, but in an online game, performance is everything and if you lose the last 30s or minute, oh well. I’d probably make it dynamic depending on load, so if you had a 1000 players on at once, it would bulk save from memecache to mysql slower than if you only had 10. Essentially, if you have CPU to spare, might as well use it.
Just keeping the below code in case I use this on my own memcached instances later this year.
#! /bin/sh # # chkconfig: - 55 45 # description: The memcached-multi daemon is a network memory cache service. # processname: memcached-multi # config: /etc/sysconfig/memcached # pidfile: /var/run/memcached/memcached.*.pid # Standard LSB functions #. /lib/lsb/init-functions # Source function library. . /etc/init.d/functions PORT=11211 UDP=0 SOCKET=/tmp/memcached.socket VAR=0 USER=memcached MAXCONN=300 CACHESIZE=64 OPTIONS="" if [ -f /etc/sysconfig/memcached ];then . /etc/sysconfig/memcached fi # Check that networking is up. . /etc/sysconfig/network if [ "$NETWORKING" = "no" ] then exit 0 fi RETVAL=0 prog="memcached" start_instance() { echo -n $"Starting $prog ($1): " # daemon --pidfile /var/run/memcached/memcached.$1.pid memcached -d -p $PORT -u $USER -m $2 -c $MAXCONN -P /var/run/memcached/memcached.$1.pid $OPTIONS daemon --pidfile /var/run/memcached/memcached.$1.pid memcached -d -s $3 -a 766 -L -t 8 -u $USER -m $2 -c $MAXCONN -P /var/run/memcached/memcached.$1.pid $OPTIONS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached.$1 } stop_instance() { echo -n $"Stopping $prog ($1): " killproc -p /var/run/memcached/memcached.$1.pid /usr/bin/memcached RETVAL=$? echo if [ $RETVAL -eq 0 ] ; then rm -f /var/lock/subsys/memcached.$1 rm -f /var/run/memcached.$1.pid fi } start() { # insure that /var/run/memcached has proper permissions if [ "`stat -c %U /var/run/memcached`" != "$USER" ]; then chown $USER /var/run/memcached fi # we start 12 socket streams for memcached start_instance default 64 /tmp/memcached.socket0; start_instance block 64 /tmp/memcached.socket1; start_instance content 64 /tmp/memcached.socket2; start_instance filter 64 /tmp/memcached.socket3; start_instance form 64 /tmp/memcached.socket4; start_instance menu 64 /tmp/memcached.socket5; start_instance page 64 /tmp/memcached.socket6; start_instance update 64 /tmp/memcached.socket7; start_instance views 64 /tmp/memcached.socket8; start_instance session 64 /tmp/memcached.socket9; start_instance users 64 /tmp/memcached.socket10; start_instance pbold 64 /tmp/memcached.socket11; } stop () { stop_instance default; stop_instance block; stop_instance content; stop_instance filter; stop_instance form; stop_instance menu; stop_instance page; stop_instance update; stop_instance views; stop_instance session; stop_instance users; stop_instance pbold; } restart () { stop start } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status memcached ;; restart|reload|force-reload) restart ;; *) echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}" exit 1 esac exit $?