安装libevent
#先到http://libevent.org/下载libevent
cd /usr/local/soft
wget https://github.com/downloads/libevent/libevent/libevent-1.4.14b-stable.tar.gz
tar zxvf libevent-1.4.14b-stable.tar.gz
cd libevent-1.4.14b-stable
./configure --prefix=/usr/local/soft/libevent-1.4.14b-stable
make
make install
安装memcache
#先到https://memcached.org下载memcached.
cd /usr/local/soft
wget https://memcached.org/files/memcached-1.4.36.tar.gz
tar memcached-1.4.36.tar.gz
cd memcached-1.4.36
./configure --prefix=/usr/local/memcached-1.4.36 --with-libevent=/usr/local/soft/libevent-1.4.14b-stable
make
make install
安装压力测试工具
#参考https://github.com/twitter/twemperf
cd /usr/local/soft
wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/twemperf/mcperf-0.1.1.tar.gz
tar zxvf mcperf-0.1.1.tar.gz
cd mcperf-0.1.1
CFLAGS="-ggdb3 -O0"
./configure --enable-debug
make
make install
运行memcache
cd /usr/local/memcached-1.4.36/memcached -d -m 1024 -u root -p 12000 -c 256 -P /tmp/memcached.pid
#参数详解
#-m:表示分配多大的内存,以M为单位。上面分配了1G的内存。
#-u:运行Memcache的用户。上面用root运行。
#-p:表示启动的端口。
#-c:表示支持的并发数。
#-P:表示写入的进程号。
测试memcache的性能
mcperf --linger=0 --timeout=5 --conn-rate=1000 --call-rate=1000 --num-calls=10 --num-conns=1000 --sizes=u1,16 --server=127.0.0.1 --port=12000 --method=set
#参数详解。
#--timeout:超时时间定义。单位:秒。
#--conn-rate:链接频率。上面表示:1000个链接每秒。
#--call-rate:调用频率。上面表示:1000次调用每秒。
#--num-calls:每一个链接的调用次数。
#--num-conns:测试链接数。
#--server:服务器IP。
#--port:服务器端口。
#--method:测试的方法名,默认:set.能够用get等等。
#--sizes:数据的大小。默认1byte。上面表示1-16byte随机。