redis压测工具:redis-benchmark与memtier_benchmark

前言

redis-benchmark与memtier_benchmark两个工具都可以用来做压测

一、redis-benchmark

redis-benchmark在redis6.0.6提供的工具.具有了多线程的功能,执行redis-benchmark --help可以具体的使用信息

  1.   root@4e1c5c3a1f9d:/data# redis-benchmark --help
  2.   Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests>] [-k <boolean>]
  3.    
  4.   -h <hostname> Server hostname (default 127.0.0.1)
  5.   -p <port> Server port (default 6379)
  6.   -s <socket> Server socket (overrides host and port)
  7.   -a <password> Password for Redis Auth
  8.   --user <username> Used to send ACL style 'AUTH username pass'. Needs -a.
  9.   -c <clients> Number of parallel connections (default 50)
  10.   -n <requests> Total number of requests (default 100000)
  11.   -d <size> Data size of SET/GET value in bytes (default 3)
  12.   --dbnum <db> SELECT the specified db number (default 0)
  13.   --threads <num> Enable multi-thread mode.
  14.   --cluster Enable cluster mode.
  15.   --enable-tracking Send CLIENT TRACKING on before starting benchmark.
  16.   -k <boolean> 1=keep alive 0=reconnect (default 1)
  17.   -r <keyspacelen> Use random keys for SET/GET/INCR, random values for SADD
  18.   Using this option the benchmark will expand the string __rand_int__
  19.   inside an argument with a 12 digits number in the specified range
  20.   from 0 to keyspacelen-1. The substitution changes every time a command
  21.   is executed. Default tests use this to hit random keys in the
  22.   specified range.
  23.   -P <numreq> Pipeline <numreq> requests. Default 1 (no pipeline).
  24.   -e If server replies with errors, show them on stdout.
  25.   (no more than 1 error per second is displayed)
  26.   -q Quiet. Just show query/sec values
  27.   --precision Number of decimal places to display in latency output (default 0)
  28.   --csv Output in CSV format
  29.   -l Loop. Run the tests forever
  30.   -t <tests> Only run the comma separated list of tests. The test
  31.   names are the same as the ones produced as output.
  32.   -I Idle mode. Just open N idle connections and wait.
  33.    
  34.   Examples:
  35.   Run the benchmark with the default configuration against 127.0.0.1:6379:
  36.   $ redis-benchmark
  37.   Use 20 parallel clients, for a total of 100k requests, against 192.168.1.1:
  38.   $ redis-benchmark -h 192.168.1.1 -p 6379 -n 100000 -c 20
  39.   Fill 127.0.0.1:6379 with about 1 million keys only using the SET test:
  40.   $ redis-benchmark -t set -n 1000000 -r 100000000
  41.   Benchmark 127.0.0.1:6379 for a few commands producing CSV output:
  42.   $ redis-benchmark -t ping,set,get -n 100000 --csv
  43.   Benchmark a specific command line:
  44.   $ redis-benchmark -r 10000 -n 10000 eval 'return redis.call("ping")' 0
  45.   Fill a list with 10000 random elements:
  46.   $ redis-benchmark -r 10000 -n 10000 lpush mylist __rand_int__
  47.   On user specified command lines __rand_int__ is replaced with a random integer
  48.   with a range of values selected by the -r option.

简单说明:

  1.   -q 仅仅显示redis-benchmark的requests per second信息
  2.   -P 代表每个请求pipeline的数据量(默认为1)
  3.   -k 代表客户端是否使用keepalive, 1为使用, 0为不使用, 默认值为1
  4.   -t 可以对指定命令进行基准测试 例如:redis-benchmark -t get,set
  5.   --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.   1. 安装编译环境和依赖包
  2.   ## 安装编译环境
  3.   yum install -y autoconf automake make gcc-c++
  4.    
  5.   ## 安装依赖包
  6.   yum install -y pcre-devel zlib-devel libmemcached-devel wget git
  7.    
  8.   2. 编译安装libevent
  9.   cd /Downloads
  10.   wget https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz
  11.   tar xvzf libevent-2.0.22-stable.tar.gz
  12.   cd libevent-2.0.22-stable
  13.   ./configure
  14.   make && make install
  15.    
  16.   3. 更新库文件配置
  17.   echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:\${PKG_CONFIG_PATH}" >> /etc/profile
  18.   source /etc/profile
  19.   ldconfig /usr/local/lib
  20.    
  21.   4. 编译安装memtier_benchmark工具
  22.   cd /Downloads
  23.   git clone https://github.com/RedisLabs/memtier_benchmark.git
  24.   cd memtier_benchmark
  25.   autoreconf -ivf
  26.   ./configure --prefix=/usr/local/memtier
  27.   make && make install
  28.   echo "export PATH=/usr/local/memtier/bin:\${PATH}" >> /etc/profile
  29.   source /etc/profile
  30.    
  31.   5. 验证安装
  32.   memtier_benchmark --help

查看命令使用说明

  1.   [root@sza232073 ~]# memtier_benchmark --help
  2.   Usage: memtier_benchmark [options]
  3.   A memcache/redis NoSQL traffic generator and performance benchmarking tool.
  4.    
  5.   Connection and General Options:
  6.   -s, --server=ADDR Server address (default: localhost)
  7.   -p, --port=PORT Server port (default: 6379)
  8.   -S, --unix-socket=SOCKET UNIX Domain socket name (default: none)
  9.   -P, --protocol=PROTOCOL Protocol to use (default: redis). Other
  10.   supported protocols are memcache_text,
  11.   memcache_binary.
  12.   -a, --authenticate=CREDENTIALS Authenticate using specified credentials.
  13.   A simple password is used for memcache_text
  14.   and Redis <= 5.x. <USER>:<PASSWORD> can be
  15.   specified for memcache_binary or Redis 6.x
  16.   or newer with ACL user support.
  17.   --tls Enable SSL/TLS transport security
  18.   --cert=FILE Use specified client certificate for TLS
  19.   --key=FILE Use specified private key for TLS
  20.   --cacert=FILE Use specified CA certs bundle for TLS
  21.   --tls-skip-verify Skip verification of server certificate
  22.   --sni=STRING Add an SNI header
  23.   -x, --run-count=NUMBER Number of full-test iterations to perform
  24.   -D, --debug Print debug output
  25.   --client-stats=FILE Produce per-client stats file
  26.   --out-file=FILE Name of output file (default: stdout)
  27.   --json-out-file=FILE Name of JSON output file, if not set, will not print to json
  28.   --show-config Print detailed configuration before running
  29.   --hide-histogram Don't print detailed latency histogram
  30.   --cluster-mode Run client in cluster mode
  31.   --help Display this help
  32.   --version Display version information
  33.    
  34.   Test Options:
  35.   -n, --requests=NUMBER Number of total requests per client (default: 10000)
  36.   use 'allkeys' to run on the entire key-range
  37.   -c, --clients=NUMBER Number of clients per thread (default: 50)
  38.   -t, --threads=NUMBER Number of threads (default: 4)
  39.   --test-time=SECS Number of seconds to run the test
  40.   --ratio=RATIO Set:Get ratio (default: 1:10)
  41.   --pipeline=NUMBER Number of concurrent pipelined requests (default: 1)
  42.   --reconnect-interval=NUM Number of requests after which re-connection is performed
  43.   --multi-key-get=NUM Enable multi-key get commands, up to NUM keys (default: 0)
  44.   --select-db=DB DB number to select, when testing a redis server
  45.   --distinct-client-seed Use a different random seed for each client
  46.   --randomize random seed based on timestamp (default is constant value)
  47.    
  48.   Arbitrary command:
  49.   --command=COMMAND Specify a command to send in quotes.
  50.   Each command that you specify is run with its ratio and key-pattern options.
  51.   For example: --command="set __key__ 5" --command-ratio=2 --command-key-pattern=G
  52.   To use a generated key or object, enter:
  53.   __key__: Use key generated from Key Options.
  54.   __data__: Use data generated from Object Options.
  55.   --command-ratio The number of times the command is sent in sequence.(default: 1)
  56.   --command-key-pattern Key pattern for the command (default: R):
  57.   G for Gaussian distribution.
  58.   R for uniform Random.
  59.   S for Sequential.
  60.   P for Parallel (Sequential were each client has a subset of the key-range).
  61.    
  62.   Object Options:
  63.   -d --data-size=SIZE Object data size (default: 32)
  64.   --data-offset=OFFSET Actual size of value will be data-size + data-offset
  65.   Will use SETRANGE / GETRANGE (default: 0)
  66.   -R --random-data Indicate that data should be randomized
  67.   --data-size-range=RANGE Use random-sized items in the specified range (min-max)
  68.   --data-size-list=LIST Use sizes from weight list (size1:weight1,..sizeN:weightN)
  69.   --data-size-pattern=R|S Use together with data-size-range
  70.   when set to R, a random size from the defined data sizes will be used,
  71.   when set to S, the defined data sizes will be evenly distributed across
  72.   the key range, see --key-maximum (default R)
  73.   --expiry-range=RANGE Use random expiry values from the specified range
  74.    
  75.   Imported Data Options:
  76.   --data-import=FILE Read object data from file
  77.   --data-verify Enable data verification when test is complete
  78.   --verify-only Only perform --data-verify, without any other test
  79.   --generate-keys Generate keys for imported objects
  80.   --no-expiry Ignore expiry information in imported data
  81.    
  82.   Key Options:
  83.   --key-prefix=PREFIX Prefix for keys (default: "memtier-")
  84.   --key-minimum=NUMBER Key ID minimum value (default: 0)
  85.   --key-maximum=NUMBER Key ID maximum value (default: 10000000)
  86.   --key-pattern=PATTERN Set:Get pattern (default: R:R)
  87.   G for Gaussian distribution.
  88.   R for uniform Random.
  89.   S for Sequential.
  90.   P for Parallel (Sequential were each client has a subset of the key-range).
  91.   --key-stddev The standard deviation used in the Gaussian distribution
  92.   (default is key range / 6)
  93.   --key-median The median point used in the Gaussian distribution
  94.   (default is the center of the key range)
  95.    
  96.   WAIT Options:
  97.   --wait-ratio=RATIO Set:Wait ratio (default is no WAIT commands - 1:0)
  98.   --num-slaves=RANGE WAIT for a random number of slaves in the specified range
  99.   --wait-timeout=RANGE WAIT for a random number of milliseconds in the specified range (normal
  100.   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不能同时使用(我测试是不能,若可以可以留下评论)

 

上一篇:Transparent Object Tracking Benchmark


下一篇:folly库之Benchmark.h