I'm facing issues with my memcache recently as we received lot of data requests. So, I used telnet command to get some stats around the memcache.
For the production environment, I saw that there are lot of evictions which tells me that the memcache is low on memory. Also, from the stats it looks like cache size is just 67MB(limit_maxbytes 67108864) or default 64MB we can say.
This is the data from my production memcache server
stats
STAT pid 1579
STAT uptime 252639
STAT time 1600976110
STAT version 1.4.13
STAT libevent 1.4.13-stable
STAT pointer_size 64
STAT rusage_user 44411.308454
STAT rusage_system 56278.501367
STAT curr_connections 10
STAT total_connections 533
STAT connection_structures 11
STAT reserved_fds 20
STAT cmd_get 2397846230
STAT cmd_set 1913899024
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 482417633
STAT get_misses 1915428597
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 221369814023
STAT bytes_written 53089737887
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 50691561
STAT hash_power_level 19
STAT hash_bytes 4194304
STAT hash_is_expanding 0
STAT expired_unfetched 0
STAT evicted_unfetched 1614719615
STAT bytes 60253067
STAT curr_items 557392
STAT total_items 1911222415
STAT evictions 1910665023
STAT reclaimed 0
END
This is one other thing
$cat /etc/sysconfig/memcached
SERVERS=-lIPADDRESS:-p11211
CACHESIZE=1024
I don't have file /etc/memcached.conf. But here is the memcached file from init.d folder.
$ cat /etc/init.d/memcached
#!/bin/bash
#
# memcached This shell script takes care of starting and stopping
# the Memcached distributed memory object cache.
#
# chkconfig: - 60 40
# description: Memcached is a distributed memory object cache system.
# processname: memcached
# config: /etc/sysconfig/memcached
# pidfile: /var/run/memcached/memcached.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 1
# Defines
DESC="the distributed memory object cache (memcached)"
PROG="memcached"
EXEC="/usr/sbin/${PROG}"
LOCK="/var/lock/subsys/${PROG}"
PIDF="/var/run/${PROG}/${PROG}.pid"
CONF="/etc/sysconfig/${PROG}"
# Include config
if [ -s /etc/sysconfig/${PROG} ]; then
. /etc/sysconfig/${PROG}
fi
# Further defines
FSMAX="${FSMAX:-1024}"
RUN_AS="${RUN_AS:-memcached}"
SERVERS="${SERVERS:--l127.0.0.1:-p11211}"
OPTIONS="${OPTIONS} -u ${RUN_AS}"
# Check for binaries and configs
[ -x ${EXEC} ] || exit 5
[ -f ${CONF} ] || exit 6
start() {
# Start daemon(s).
COUNT=0
ERR=0
# Set max. filehandles
ulimit -HSn ${FSMAX}
for SRV in ${SERVERS}; do
echo -n $"Starting ${DESC}: "
OPTS=`echo ${SRV} | tr ':' ' '`
let COUNT=${COUNT}+1
daemon ${EXEC} -d -P ${PIDF} ${OPTS} ${OPTIONS}
RETVAL=${?}
[ ${RETVAL} -eq 0 ] || ERR=${COUNT}
echo
done
[ ${ERR} -eq 0 ] && touch ${LOCK}
return ${ERR}
}
stop() {
# Stop daemon(s).
echo -n $"Shutting down ${DESC}: "
killproc ${PROG}
RETVAL=${?}
[ ${RETVAL} -eq 0 ] && rm -f ${LOCK} ${PIDF}
echo
return ${RETVAL}
}
restart() {
stop
sleep 2
start
}
force_reload() {
restart
}
rh_status() {
status ${PROG}
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
# See how we were called.
case "${1}" in
start)
rh_status_q && exit 0
${1}
;;
stop)
rh_status_q || exit 0
${1}
;;
restart)
${1}
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: ${PROG} {start|stop|status|restart|try-restart|force-reload}"
exit 2
esac
exit ${?}
For the non-production environment, I saw that there are 0 evictions and also it looks like cache size is set to 1GB(limit_maxbytes 1073741824) or 1024 MB. This is my non-production server memcache stats
stats
STAT pid 1127
STAT uptime 50350278
STAT time 1600976701
STAT version 1.4.24
STAT libevent 1.4.13-stable
STAT pointer_size 64
STAT rusage_user 1384.501523
STAT rusage_system 1001.181797
STAT curr_connections 11
STAT total_connections 162
STAT connection_structures 16
STAT reserved_fds 20
STAT cmd_get 33072
STAT cmd_set 12565
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 20501
STAT get_misses 12571
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 2298750
STAT bytes_written 9016176
STAT limit_maxbytes 1073741824
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT malloc_fails 0
STAT bytes 1342698
STAT curr_items 12533
STAT total_items 12533
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT evictions 0
STAT reclaimed 0
STAT crawler_reclaimed 0
STAT crawler_items_checked 0
STAT lrutail_reflocked 0
END
This is one other thing
$cat /etc/sysconfig/memcached
SERVERS=-lIPADDRESS:-p11211
CACHESIZE=1024
I don't have file /etc/memcached.conf. But here is the memcached file from init.d folder.
$ cat /etc/init.d/memcached
#! /bin/sh
#
# chkconfig: - 55 45
# description: The memcached daemon is a network memory cache service.
# processname: memcached
# 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
USER=memcached
MAXCONN=1024
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"
pidfile=${PIDFILE-/var/run/memcached/memcached.pid}
lockfile=${LOCKFILE-/var/lock/subsys/memcached}
start () {
echo -n $"Starting $prog: "
# Ensure that $pidfile directory has proper permissions and exists
piddir=`dirname $pidfile`
if [ ! -d $piddir ]; then
mkdir $piddir
fi
if [ "`stat -c %U $piddir`" != "$USER" ]; then
chown $USER $piddir
fi
daemon --pidfile ${pidfile} memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P ${pidfile} $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch ${lockfile}
}
stop () {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} /usr/bin/memcached
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f ${lockfile} ${pidfile}
fi
}
restart () {
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} memcached
RETVAL=$?
;;
restart|reload|force-reload)
restart
;;
condrestart|try-restart)
[ -f ${lockfile} ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart|try-restart}"
RETVAL=2
;;
esac
exit $RETVAL
I'm bit confused with the cache size values and where exactly to update them. Because in non-prod, it seems like the cache size is 1GB from the stats, 1024MB (1GB) from the /etc/sysconfig/memcached but 64MB from /etc/init.d/memcached. And when I check prod values, cache size is 67MB from the stats, 1024MB (1GB) from the /etc/sysconfig/memcached and no value in /etc/init.d/memcached which makes me to assume that the value is defaulted to 64MB.
Or is it like just running the command will take care of increasing the cache size to 1GB.
memcached -m 1024
But I would want to know what file is used exactly for the configs.
Thanks for the help.