redis壓測工具:redis-benchmark與memtier_benchmark
前言
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推出的一款命令列工具
安裝參考文章:
- 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不能同時使用(我測試是不能,若可以可以留下評論)