前言
redis-benchmark与memtier_benchmark两个工具都可以用来做压测
一、redis-benchmark
redis-benchmark在redis6.0.6提供的工具.具有了多线程的功能,执行redis-benchmark --help可以具体的使用信息
-
root@4e1c5c3a1f9d:/data# redis-benchmark --help -
Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests>] [-k <boolean>] -
-
-h <hostname> Server hostname (default 127.0.0.1) -
-p <port> Server port (default 6379) -
-s <socket> Server socket (overrides host and port) -
-a <password> Password for Redis Auth -
--user <username> Used to send ACL style 'AUTH username pass'. Needs -a. -
-c <clients> Number of parallel connections (default 50) -
-n <requests> Total number of requests (default 100000) -
-d <size> Data size of SET/GET value in bytes (default 3) -
--dbnum <db> SELECT the specified db number (default 0) -
--threads <num> Enable multi-thread mode. -
--cluster Enable cluster mode. -
--enable-tracking Send CLIENT TRACKING on before starting benchmark. -
-k <boolean> 1=keep alive 0=reconnect (default 1) -
-r <keyspacelen> Use random keys for SET/GET/INCR, random values for SADD -
Using this option the benchmark will expand the string __rand_int__ -
inside an argument with a 12 digits number in the specified range -
from 0 to keyspacelen-1. The substitution changes every time a command -
is executed. Default tests use this to hit random keys in the -
specified range. -
-P <numreq> Pipeline <numreq> requests. Default 1 (no pipeline). -
-e If server replies with errors, show them on stdout. -
(no more than 1 error per second is displayed) -
-q Quiet. Just show query/sec values -
--precision Number of decimal places to display in latency output (default 0) -
--csv Output in CSV format -
-l Loop. Run the tests forever -
-t <tests> Only run the comma separated list of tests. The test -
names are the same as the ones produced as output. -
-I Idle mode. Just open N idle connections and wait. -
-
Examples: -
Run the benchmark with the default configuration against 127.0.0.1:6379: -
$ redis-benchmark -
Use 20 parallel clients, for a total of 100k requests, against 192.168.1.1: -
$ redis-benchmark -h 192.168.1.1 -p 6379 -n 100000 -c 20 -
Fill 127.0.0.1:6379 with about 1 million keys only using the SET test: -
$ redis-benchmark -t set -n 1000000 -r 100000000 -
Benchmark 127.0.0.1:6379 for a few commands producing CSV output: -
$ redis-benchmark -t ping,set,get -n 100000 --csv -
Benchmark a specific command line: -
$ redis-benchmark -r 10000 -n 10000 eval 'return redis.call("ping")' 0 -
Fill a list with 10000 random elements: -
$ redis-benchmark -r 10000 -n 10000 lpush mylist __rand_int__ -
On user specified command lines __rand_int__ is replaced with a random integer -
with a range of values selected by the -r option.
简单说明:
-
-q 仅仅显示redis-benchmark的requests per second信息 -
-P 代表每个请求pipeline的数据量(默认为1) -
-k 代表客户端是否使用keepalive, 1为使用, 0为不使用, 默认值为1 -
-t 可以对指定命令进行基准测试 例如:redis-benchmark -t get,set -
--csv 选项会将结果按照csv格式输出, 便于后续处理, 如导出到Excel
使用:
redis-benchmark -h 127.0.0.1 -p 6379 -a 123456 -c 100 --cluster -n 100000 -r 1000 -d 100 -q --threads 16 -t get,set,incr,hset
解释:对redis集群(ip:127.0.0.1 port: 6379 pwd:123456 )进行压测.启动16个线程,100个客户端,1000000个key(千位之内随机数)每个key100字节,测试set/get/incr/hset命令执行的qps结果
二、memtier_benchmark
memtier_benchmark是Redis Labs推出的一款命令行工具
安装参考文章:http://ghoulich.xninja.org/2016/12/11/how-to-use-memtier-benchmark-to-measure-redis-performance/
-
1. 安装编译环境和依赖包 -
## 安装编译环境 -
yum install -y autoconf automake make gcc-c++ -
-
## 安装依赖包 -
yum install -y pcre-devel zlib-devel libmemcached-devel wget git -
-
2. 编译安装libevent -
cd /Downloads -
wget https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz -
tar xvzf libevent-2.0.22-stable.tar.gz -
cd libevent-2.0.22-stable -
./configure -
make && make install -
-
3. 更新库文件配置 -
echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:\${PKG_CONFIG_PATH}" >> /etc/profile -
source /etc/profile -
ldconfig /usr/local/lib -
-
4. 编译安装memtier_benchmark工具 -
cd /Downloads -
git clone https://github.com/RedisLabs/memtier_benchmark.git -
cd memtier_benchmark -
autoreconf -ivf -
./configure --prefix=/usr/local/memtier -
make && make install -
echo "export PATH=/usr/local/memtier/bin:\${PATH}" >> /etc/profile -
source /etc/profile -
-
5. 验证安装 -
memtier_benchmark --help
查看命令使用说明
-
[root@sza232073 ~]# memtier_benchmark --help -
Usage: memtier_benchmark [options] -
A memcache/redis NoSQL traffic generator and performance benchmarking tool. -
-
Connection and General Options: -
-s, --server=ADDR Server address (default: localhost) -
-p, --port=PORT Server port (default: 6379) -
-S, --unix-socket=SOCKET UNIX Domain socket name (default: none) -
-P, --protocol=PROTOCOL Protocol to use (default: redis). Other -
supported protocols are memcache_text, -
memcache_binary. -
-a, --authenticate=CREDENTIALS Authenticate using specified credentials. -
A simple password is used for memcache_text -
and Redis <= 5.x. <USER>:<PASSWORD> can be -
specified for memcache_binary or Redis 6.x -
or newer with ACL user support. -
--tls Enable SSL/TLS transport security -
--cert=FILE Use specified client certificate for TLS -
--key=FILE Use specified private key for TLS -
--cacert=FILE Use specified CA certs bundle for TLS -
--tls-skip-verify Skip verification of server certificate -
--sni=STRING Add an SNI header -
-x, --run-count=NUMBER Number of full-test iterations to perform -
-D, --debug Print debug output -
--client-stats=FILE Produce per-client stats file -
--out-file=FILE Name of output file (default: stdout) -
--json-out-file=FILE Name of JSON output file, if not set, will not print to json -
--show-config Print detailed configuration before running -
--hide-histogram Don't print detailed latency histogram -
--cluster-mode Run client in cluster mode -
--help Display this help -
--version Display version information -
-
Test Options: -
-n, --requests=NUMBER Number of total requests per client (default: 10000) -
use 'allkeys' to run on the entire key-range -
-c, --clients=NUMBER Number of clients per thread (default: 50) -
-t, --threads=NUMBER Number of threads (default: 4) -
--test-time=SECS Number of seconds to run the test -
--ratio=RATIO Set:Get ratio (default: 1:10) -
--pipeline=NUMBER Number of concurrent pipelined requests (default: 1) -
--reconnect-interval=NUM Number of requests after which re-connection is performed -
--multi-key-get=NUM Enable multi-key get commands, up to NUM keys (default: 0) -
--select-db=DB DB number to select, when testing a redis server -
--distinct-client-seed Use a different random seed for each client -
--randomize random seed based on timestamp (default is constant value) -
-
Arbitrary command: -
--command=COMMAND Specify a command to send in quotes. -
Each command that you specify is run with its ratio and key-pattern options. -
For example: --command="set __key__ 5" --command-ratio=2 --command-key-pattern=G -
To use a generated key or object, enter: -
__key__: Use key generated from Key Options. -
__data__: Use data generated from Object Options. -
--command-ratio The number of times the command is sent in sequence.(default: 1) -
--command-key-pattern Key pattern for the command (default: R): -
G for Gaussian distribution. -
R for uniform Random. -
S for Sequential. -
P for Parallel (Sequential were each client has a subset of the key-range). -
-
Object Options: -
-d --data-size=SIZE Object data size (default: 32) -
--data-offset=OFFSET Actual size of value will be data-size + data-offset -
Will use SETRANGE / GETRANGE (default: 0) -
-R --random-data Indicate that data should be randomized -
--data-size-range=RANGE Use random-sized items in the specified range (min-max) -
--data-size-list=LIST Use sizes from weight list (size1:weight1,..sizeN:weightN) -
--data-size-pattern=R|S Use together with data-size-range -
when set to R, a random size from the defined data sizes will be used, -
when set to S, the defined data sizes will be evenly distributed across -
the key range, see --key-maximum (default R) -
--expiry-range=RANGE Use random expiry values from the specified range -
-
Imported Data Options: -
--data-import=FILE Read object data from file -
--data-verify Enable data verification when test is complete -
--verify-only Only perform --data-verify, without any other test -
--generate-keys Generate keys for imported objects -
--no-expiry Ignore expiry information in imported data -
-
Key Options: -
--key-prefix=PREFIX Prefix for keys (default: "memtier-") -
--key-minimum=NUMBER Key ID minimum value (default: 0) -
--key-maximum=NUMBER Key ID maximum value (default: 10000000) -
--key-pattern=PATTERN Set:Get pattern (default: R:R) -
G for Gaussian distribution. -
R for uniform Random. -
S for Sequential. -
P for Parallel (Sequential were each client has a subset of the key-range). -
--key-stddev The standard deviation used in the Gaussian distribution -
(default is key range / 6) -
--key-median The median point used in the Gaussian distribution -
(default is the center of the key range) -
-
WAIT Options: -
--wait-ratio=RATIO Set:Wait ratio (default is no WAIT commands - 1:0) -
--num-slaves=RANGE WAIT for a random number of slaves in the specified range -
--wait-timeout=RANGE WAIT for a random number of milliseconds in the specified range (normal -
distribution with the center in the middle of the range)
使用1:对集群压测
memtier_benchmark -s 127.0.0.1 -p 6379 -a 123456 --cluster-mode -c 100 -R -d 100 -t 16 --ratio=1:1 -n 1000 --out-file=result.txt
解释:对redis集群(ip:127.0.0.1 port: 6379 pwd:123456 )进行压测.启动16个线程,100个客户端,(随机数)每个key对应的value100字节,执行16*100*1000个key,测试set/get命令执行结果输出到result.txt文件中
memtier_benchmark -s 127.0.0.1 -p 6379 -a 123456 --cluster-mode -c 100 -R -d 100 -t 16 --ratio=1:1 --test-time=60 --out-file=result.txt
解释:对redis集群(ip:127.0.0.1 port: 6379 pwd:123456 )进行压测.启动16个线程,100个客户端,(随机数)每个key对应的value100字节,执行1分钟,测试set/get命令执行结果输出到result.txt文件中
使用2:对单机压测
唯一与上边不同的是可以通过--command指定命令,-key-prefix定义key的前缀,--key-minimum --key-maximum定义随机数的范围,也可以不指定,按照上边压测去掉--cluster-mode
memtier_benchmark -s 127.0.0.1 -p 6379 -a 123456 -t 16 -c 100 -n 1000 --distinct-client-seed --command="set __key__ __data__" --key-prefix="kv_" --key-minimum=1 --key-maximum=10000 -R -d 100
注:
1. -n 与 --test-time 两个参数不能同时使用,要么指定数量要么指定时间
2.--cluster-mode与--command不能同时使用(我测试是不能,若可以可以留下评论)