安裝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隨機。