当前位置:   article > 正文

压测工具:redis-benchmark与memtier_benchmark

memtier

前言

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. -h <hostname> Server hostname (default 127.0.0.1)
  4. -p <port> Server port (default 6379)
  5. -s <socket> Server socket (overrides host and port)
  6. -a <password> Password for Redis Auth
  7. --user <username> Used to send ACL style 'AUTH username pass'. Needs -a.
  8. -c <clients> Number of parallel connections (default 50)
  9. -n <requests> Total number of requests (default 100000)
  10. -d <size> Data size of SET/GET value in bytes (default 3)
  11. --dbnum <db> SELECT the specified db number (default 0)
  12. --threads <num> Enable multi-thread mode.
  13. --cluster Enable cluster mode.
  14. --enable-tracking Send CLIENT TRACKING on before starting benchmark.
  15. -k <boolean> 1=keep alive 0=reconnect (default 1)
  16. -r <keyspacelen> Use random keys for SET/GET/INCR, random values for SADD
  17. Using this option the benchmark will expand the string __rand_int__
  18. inside an argument with a 12 digits number in the specified range
  19. from 0 to keyspacelen-1. The substitution changes every time a command
  20. is executed. Default tests use this to hit random keys in the
  21. specified range.
  22. -P <numreq> Pipeline <numreq> requests. Default 1 (no pipeline).
  23. -e If server replies with errors, show them on stdout.
  24. (no more than 1 error per second is displayed)
  25. -q Quiet. Just show query/sec values
  26. --precision Number of decimal places to display in latency output (default 0)
  27. --csv Output in CSV format
  28. -l Loop. Run the tests forever
  29. -t <tests> Only run the comma separated list of tests. The test
  30. names are the same as the ones produced as output.
  31. -I Idle mode. Just open N idle connections and wait.
  32. Examples:
  33. Run the benchmark with the default configuration against 127.0.0.1:6379:
  34. $ redis-benchmark
  35. Use 20 parallel clients, for a total of 100k requests, against 192.168.1.1:
  36. $ redis-benchmark -h 192.168.1.1 -p 6379 -n 100000 -c 20
  37. Fill 127.0.0.1:6379 with about 1 million keys only using the SET test:
  38. $ redis-benchmark -t set -n 1000000 -r 100000000
  39. Benchmark 127.0.0.1:6379 for a few commands producing CSV output:
  40. $ redis-benchmark -t ping,set,get -n 100000 --csv
  41. Benchmark a specific command line:
  42. $ redis-benchmark -r 10000 -n 10000 eval 'return redis.call("ping")' 0
  43. Fill a list with 10000 random elements:
  44. $ redis-benchmark -r 10000 -n 10000 lpush mylist __rand_int__
  45. On user specified command lines __rand_int__ is replaced with a random integer
  46. 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. yum install -y pcre-devel zlib-devel libmemcached-devel wget git
  6. 2. 编译安装libevent
  7. cd /Downloads
  8. wget https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz
  9. tar xvzf libevent-2.0.22-stable.tar.gz
  10. cd libevent-2.0.22-stable
  11. ./configure
  12. make && make install
  13. 3. 更新库文件配置
  14. echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:\${PKG_CONFIG_PATH}" >> /etc/profile
  15. source /etc/profile
  16. ldconfig /usr/local/lib
  17. 4. 编译安装memtier_benchmark工具
  18. cd /Downloads
  19. git clone https://github.com/RedisLabs/memtier_benchmark.git
  20. cd memtier_benchmark
  21. autoreconf -ivf
  22. ./configure --prefix=/usr/local/memtier
  23. make && make install
  24. echo "export PATH=/usr/local/memtier/bin:\${PATH}" >> /etc/profile
  25. source /etc/profile
  26. 5. 验证安装
  27. 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. Connection and General Options:
  5. -s, --server=ADDR Server address (default: localhost)
  6. -p, --port=PORT Server port (default: 6379)
  7. -S, --unix-socket=SOCKET UNIX Domain socket name (default: none)
  8. -P, --protocol=PROTOCOL Protocol to use (default: redis). Other
  9. supported protocols are memcache_text,
  10. memcache_binary.
  11. -a, --authenticate=CREDENTIALS Authenticate using specified credentials.
  12. A simple password is used for memcache_text
  13. and Redis <= 5.x. <USER>:<PASSWORD> can be
  14. specified for memcache_binary or Redis 6.x
  15. or newer with ACL user support.
  16. --tls Enable SSL/TLS transport security
  17. --cert=FILE Use specified client certificate for TLS
  18. --key=FILE Use specified private key for TLS
  19. --cacert=FILE Use specified CA certs bundle for TLS
  20. --tls-skip-verify Skip verification of server certificate
  21. --sni=STRING Add an SNI header
  22. -x, --run-count=NUMBER Number of full-test iterations to perform
  23. -D, --debug Print debug output
  24. --client-stats=FILE Produce per-client stats file
  25. --out-file=FILE Name of output file (default: stdout)
  26. --json-out-file=FILE Name of JSON output file, if not set, will not print to json
  27. --show-config Print detailed configuration before running
  28. --hide-histogram Don't print detailed latency histogram
  29. --cluster-mode Run client in cluster mode
  30. --help Display this help
  31. --version Display version information
  32. Test Options:
  33. -n, --requests=NUMBER Number of total requests per client (default: 10000)
  34. use 'allkeys' to run on the entire key-range
  35. -c, --clients=NUMBER Number of clients per thread (default: 50)
  36. -t, --threads=NUMBER Number of threads (default: 4)
  37. --test-time=SECS Number of seconds to run the test
  38. --ratio=RATIO Set:Get ratio (default: 1:10)
  39. --pipeline=NUMBER Number of concurrent pipelined requests (default: 1)
  40. --reconnect-interval=NUM Number of requests after which re-connection is performed
  41. --multi-key-get=NUM Enable multi-key get commands, up to NUM keys (default: 0)
  42. --select-db=DB DB number to select, when testing a redis server
  43. --distinct-client-seed Use a different random seed for each client
  44. --randomize random seed based on timestamp (default is constant value)
  45. Arbitrary command:
  46. --command=COMMAND Specify a command to send in quotes.
  47. Each command that you specify is run with its ratio and key-pattern options.
  48. For example: --command="set __key__ 5" --command-ratio=2 --command-key-pattern=G
  49. To use a generated key or object, enter:
  50. __key__: Use key generated from Key Options.
  51. __data__: Use data generated from Object Options.
  52. --command-ratio The number of times the command is sent in sequence.(default: 1)
  53. --command-key-pattern Key pattern for the command (default: R):
  54. G for Gaussian distribution.
  55. R for uniform Random.
  56. S for Sequential.
  57. P for Parallel (Sequential were each client has a subset of the key-range).
  58. Object Options:
  59. -d --data-size=SIZE Object data size (default: 32)
  60. --data-offset=OFFSET Actual size of value will be data-size + data-offset
  61. Will use SETRANGE / GETRANGE (default: 0)
  62. -R --random-data Indicate that data should be randomized
  63. --data-size-range=RANGE Use random-sized items in the specified range (min-max)
  64. --data-size-list=LIST Use sizes from weight list (size1:weight1,..sizeN:weightN)
  65. --data-size-pattern=R|S Use together with data-size-range
  66. when set to R, a random size from the defined data sizes will be used,
  67. when set to S, the defined data sizes will be evenly distributed across
  68. the key range, see --key-maximum (default R)
  69. --expiry-range=RANGE Use random expiry values from the specified range
  70. Imported Data Options:
  71. --data-import=FILE Read object data from file
  72. --data-verify Enable data verification when test is complete
  73. --verify-only Only perform --data-verify, without any other test
  74. --generate-keys Generate keys for imported objects
  75. --no-expiry Ignore expiry information in imported data
  76. Key Options:
  77. --key-prefix=PREFIX Prefix for keys (default: "memtier-")
  78. --key-minimum=NUMBER Key ID minimum value (default: 0)
  79. --key-maximum=NUMBER Key ID maximum value (default: 10000000)
  80. --key-pattern=PATTERN Set:Get pattern (default: R:R)
  81. G for Gaussian distribution.
  82. R for uniform Random.
  83. S for Sequential.
  84. P for Parallel (Sequential were each client has a subset of the key-range).
  85. --key-stddev The standard deviation used in the Gaussian distribution
  86. (default is key range / 6)
  87. --key-median The median point used in the Gaussian distribution
  88. (default is the center of the key range)
  89. WAIT Options:
  90. --wait-ratio=RATIO Set:Wait ratio (default is no WAIT commands - 1:0)
  91. --num-slaves=RANGE WAIT for a random number of slaves in the specified range
  92. --wait-timeout=RANGE WAIT for a random number of milliseconds in the specified range (normal
  93. 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不能同时使用(我测试是不能,若可以可以留下评论)

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/703726
推荐阅读
相关标签
  

闽ICP备14008679号