![对 memcache 大小增加的困惑](https://linux22.com/image/757899/%E5%AF%B9%20memcache%20%E5%A4%A7%E5%B0%8F%E5%A2%9E%E5%8A%A0%E7%9A%84%E5%9B%B0%E6%83%91.png)
最近我的 memcache 出现了问题,因为我们收到了很多数据请求。因此,我使用 telnet 命令获取了有关 memcache 的一些统计数据。
对于生产环境,我看到有很多驱逐,这告诉我 memcache 内存不足。此外,从统计数据来看,缓存大小似乎只有 67MB(limit_maxbytes 67108864)或默认的 64MB。
这是来自我的生产 memcache 服务器的数据
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
这是另一件事
$cat /etc/sysconfig/memcached
SERVERS=-lIPADDRESS:-p11211
CACHESIZE=1024
我没有文件 /etc/memcached.conf。但是这是来自 init.d 文件夹的 memcached 文件。
$ 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 ${?}
对于非生产环境,我看到驱逐次数为 0,而且缓存大小似乎设置为 1GB(limit_maxbytes 1073741824)或 1024 MB。这是我的非生产服务器 memcache 统计数据
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
这是另一件事
$cat /etc/sysconfig/memcached
SERVERS=-lIPADDRESS:-p11211
CACHESIZE=1024
我没有文件 /etc/memcached.conf。但是这是来自 init.d 文件夹的 memcached 文件。
$ 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
我对缓存大小值以及确切更新位置感到有些困惑。因为在非生产环境中,从统计数据来看缓存大小似乎是 1GB,从 /etc/sysconfig/memcached 来看是 1024MB (1GB),但从 /etc/init.d/memcached 来看是 64MB。当我检查生产环境值时,从统计数据来看缓存大小是 67MB,从 /etc/sysconfig/memcached 来看是 1024MB (1GB),而 /etc/init.d/memcached 中没有值,这让我假设该值默认为 64MB。
或者仅仅运行命令就会将缓存大小增加到 1GB。
memcached -m 1024
但我想知道配置究竟使用了哪个文件。
谢谢您的帮助。