1 概述
memtier_benchmark是一种高吞吐量的性能基准测试工具,主要用于Redis和Memcached。它是 Redis官方开发团队开发的,旨在生成各种流量模式,以便测试和优化以上两个数据库的性能。
memtier_benchmark的一些关键特点如下:
多协议支持
memtier_benchmark 支持 Redis 和 Memcached(包括二进制和文本协议),可以用于比较不同场景下的性能表现。
多线程与多客户端
该工具能够启动多个工作线程,每个线程可以驱动配置数量的客户端,从而更好地利用硬件资源,生成高负载流量。
可定制的测试选项
用户可以通过选项来控制 GET 和 SET 操作的比例、键的使用模式(随机或顺序)、键的过期时间范围等,以模拟不同的访问模式。
报告生成
memtier_benchmark 能够在多次测试迭代后自动生成最佳、最差和平均结果的报告,帮助用户深入了解系统性能。
2 环境
benchmark服务器(华为云),8C8G,centos 7.9,编译安装memtier_benchmark。
redis服务器(X实例并开启redis加速),8C16G,centos 7.9,IP是10.0.24.81。
两台服务器都处于同一个az和同一个子网中。
3 部署memtier_benchmark
安装编译memtier_benchmark需要的依赖文件,以及下载源码。
yum install git -y
yum install autoconf automake make gcc-c++ pcre-devel zlib-devel libmemcached-devel libevent-devel openssl-devel -y
cd /opt
git clone https://github.com/RedisLabs/memtier_benchmark.git
cd memtier_benchmark
编译程序,命令如下:
autoreconf -ivf
./configure
make && make install
which memtier_benchmark
memtier_benchmark -v
命令行的常用参数:
- -s, --server=ADDR: 服务器地址。
- -p, --port=PORT: 服务器端口(默认值:6379)。
- -n, --requests=NUMBER: 每个客户端的总请求数(默认值:10000)。使用 allkeys 在整个键范围内运行。
- --rate-limiting=NUMBER: 每个连接每秒最大请求数(默认无限制)。
- -c, --clients=NUMBER: 每个线程的客户端数(默认值:50)。
- -t, --threads=NUMBER: 线程数(默认值:4)。
- --test-time=SECS: 测试运行的秒数。
- --ratio=RATIO: Set:Get 比例(默认值:1:10)。
- --pipeline=NUMBER: 并发流水线请求数(默认值:1)。
- --reconnect-interval=NUM: 执行多少请求后重新连接。
- --multi-key-get=NUM: 启用多键获取命令,最多获取 NUM 键(默认值:0)。
- --select-db=DB: 选择数据库编号(测试 Redis 服务器时)。
- --distinct-client-seed: 为每个客户端使用不同的随机种子。
- --randomize: 基于时间戳的随机种子(默认值为固定值)。
4 部署redis
在华为云上购买X实例服务器,选择欧拉系统(使用此系统才有redis加速效果),并开启redis加速。
开启redis加速的X实例服务器是自动安装了redis rpm包,需要修改redis.conf文件以使得redis监听在所有网卡上,执行如下命令:
echo "bind 0.0.0.0" >> /etc/redis/redis.conf
systemctl restart redis
5 压测
目标redis的IP是10.0.24.81,-t表示压测工具开启的线程数,-c表示一个线程启动的客户端数量,-d表示请求消息的大小(单位为字节),-n表示一个客户端发送的请求数量。
memtier_benchmark -s 10.0.24.81 -p 6379 -t 32 -c 32 -d 1024 -n 100000
压测输出报告如下,重点关注Ops/sec和p99 Latency。
Writing results to stdout
[RUN #1] Preparing benchmark client...
[RUN #1] Launching threads now...
[RUN #1 100%, 498 secs] 0 threads: 102400000 ops, 292495 (avg: 205595) ops/sec, 37.19MB/sec (avg: 26.36MB/sec), 3.50 (avg: 4.98) msec latency
32 Threads
32 Connections per thread
100000 Requests per client
ALL STATS
============================================================================================================================
Type Ops/sec Hits/sec Misses/sec Avg. Latency p50 Latency p99 Latency p100 Latency KB/sec
----------------------------------------------------------------------------------------------------------------------------
Sets 18741.10 --- --- 4.98549 4.89500 9.91900 22.78300 19635.84
Gets 187408.95 134.00 187274.95 4.97699 4.89500 9.91900 22.65500 7434.61
Waits 0.00 --- --- --- --- --- --- ---
Totals 206150.05 134.00 187274.95 4.97776 4.89500 9.91900 22.65500 27070.45
Request Latency Distribution
Type <= msec Percent
------------------------------------------------------------------------
SET 0.063 0.000
SET 4.511 5.000
SET 4.575 10.000
SET 4.607 15.000
SET 4.639 20.000
SET 4.671 25.000
SET 4.767 30.000
SET 4.831 35.000
SET 4.863 40.000
SET 4.863 45.000
SET 4.895 50.000
SET 4.895 52.500
SET 4.895 55.000
SET 4.895 57.500
SET 4.927 60.000
SET 4.927 62.500
SET 4.927 65.000
SET 4.927 67.500
SET 4.927 70.000
SET 4.959 72.500
SET 4.959 75.000
SET 4.959 76.250
SET 4.959 77.500
SET 4.959 78.750
SET 4.959 80.000
SET 4.991 81.250
SET 4.991 82.500
SET 4.991 83.750
SET 4.991 85.000
SET 4.991 86.250
SET 5.023 87.500
SET 5.023 88.125
SET 5.023 88.750
SET 5.023 89.375
SET 5.023 90.000
SET 5.023 90.625
SET 5.055 91.250
SET 5.055 91.875
SET 5.055 92.500
SET 5.087 93.125
SET 5.119 93.750
SET 5.119 94.062
SET 5.151 94.375
SET 5.183 94.688
SET 5.311 95.000
SET 5.375 95.312
SET 5.407 95.625
SET 5.439 95.938
SET 5.503 96.250
SET 5.823 96.562
SET 8.319 96.875
SET 9.087 97.031
SET 9.151 97.188
SET 9.215 97.344
SET 9.279 97.500
SET 9.407 97.656
SET 9.663 97.812
SET 9.727 97.969
SET 9.727 98.125
SET 9.791 98.281
SET 9.791 98.438
SET 9.855 98.516
SET 9.855 98.594
SET 9.855 98.672
SET 9.855 98.750
SET 9.919 98.828
SET 9.919 98.906
SET 9.919 98.984
SET 9.983 99.062
SET 9.983 99.141
SET 10.047 99.219
SET 10.175 99.258
SET 10.303 99.297
SET 10.687 99.336
SET 11.007 99.375
SET 11.647 99.414
SET 12.351 99.453
SET 13.119 99.492
SET 13.823 99.531
SET 14.591 99.570
SET 15.359 99.609
SET 15.743 99.629
SET 16.127 99.648
SET 16.639 99.668
SET 17.023 99.688
SET 17.407 99.707
SET 17.791 99.727
SET 18.303 99.746
SET 18.687 99.766
SET 19.199 99.785
SET 19.711 99.805
SET 19.967 99.814
SET 20.223 99.824
SET 20.607 99.834
SET 20.863 99.844
SET 21.119 99.854
SET 21.503 99.863
SET 21.759 99.873
SET 22.143 99.883
SET 22.527 99.893
SET 22.911 99.902
SET 23.167 99.907
SET 23.423 99.912
SET 23.679 99.917
SET 23.935 99.922
SET 24.191 99.927
SET 24.447 99.932
SET 24.703 99.937
SET 24.959 99.941
SET 25.215 99.946
SET 25.599 99.951
SET 25.727 99.954
SET 25.855 99.956
SET 26.111 99.958
SET 26.239 99.961
SET 26.367 99.963
SET 26.623 99.966
SET 26.751 99.968
SET 27.007 99.971
SET 27.263 99.973
SET 27.391 99.976
SET 27.519 99.977
SET 27.647 99.978
SET 27.775 99.979
SET 27.903 99.980
SET 28.031 99.982
SET 28.159 99.983
SET 28.287 99.984
SET 28.415 99.985
SET 28.671 99.987
SET 28.799 99.988
SET 28.799 99.988
SET 28.927 99.989
SET 29.055 99.990
SET 29.183 99.990
SET 29.183 99.991
SET 29.311 99.991
SET 29.439 99.992
SET 29.567 99.993
SET 29.695 99.993
SET 29.823 99.994
SET 29.823 99.994
SET 29.951 99.995
SET 29.951 99.995
SET 30.079 99.995
SET 30.207 99.995
SET 30.207 99.996
SET 30.335 99.996
SET 30.335 99.996
SET 30.463 99.997
SET 30.591 99.997
SET 30.719 99.997
SET 30.719 99.997
SET 30.847 99.997
SET 30.847 99.998
SET 30.975 99.998
SET 30.975 99.998
SET 31.103 99.998
SET 31.231 99.998
SET 31.359 99.998
SET 31.487 99.998
SET 31.487 99.999
SET 31.615 99.999
SET 31.615 99.999
SET 31.743 99.999
SET 31.743 99.999
SET 31.871 99.999
SET 31.871 99.999
SET 31.999 99.999
SET 32.127 99.999
SET 32.255 99.999
SET 32.383 99.999
SET 32.383 99.999
SET 32.511 99.999
SET 32.639 99.999
SET 32.639 99.999
SET 32.767 99.999
SET 32.767 100.000
SET 33.023 100.000
SET 33.023 100.000
SET 33.279 100.000
SET 33.279 100.000
SET 33.279 100.000
SET 33.279 100.000
SET 33.279 100.000
SET 33.535 100.000
SET 33.535 100.000
SET 33.535 100.000
SET 33.791 100.000
SET 33.791 100.000
SET 33.791 100.000
SET 33.791 100.000
SET 34.047 100.000
SET 34.047 100.000
SET 34.047 100.000
SET 34.047 100.000
SET 34.047 100.000
SET 34.047 100.000
SET 34.303 100.000
SET 34.303 100.000
SET 34.815 100.000
SET 34.815 100.000
SET 34.815 100.000
SET 34.815 100.000
SET 34.815 100.000
SET 35.071 100.000
SET 35.071 100.000
SET 35.071 100.000
SET 35.071 100.000
SET 35.071 100.000
SET 35.071 100.000
SET 35.071 100.000
SET 35.327 100.000
SET 35.327 100.000
SET 35.327 100.000
SET 35.327 100.000
SET 35.327 100.000
SET 35.583 100.000
SET 35.583 100.000
SET 35.583 100.000
SET 35.583 100.000
SET 35.583 100.000
SET 35.583 100.000
SET 35.583 100.000
SET 35.583 100.000
SET 35.583 100.000
SET 35.583 100.000
SET 35.583 100.000
SET 35.583 100.000
SET 35.583 100.000
SET 35.583 100.000
SET 35.583 100.000
SET 36.351 100.000
SET 36.351 100.000
---
GET 0.063 0.000
GET 4.511 5.000
GET 4.575 10.000
GET 4.607 15.000
GET 4.639 20.000
GET 4.671 25.000
GET 4.767 30.000
GET 4.831 35.000
GET 4.863 40.000
GET 4.863 45.000
GET 4.895 50.000
GET 4.895 52.500
GET 4.895 55.000
GET 4.895 57.500
GET 4.927 60.000
GET 4.927 62.500
GET 4.927 65.000
GET 4.927 67.500
GET 4.927 70.000
GET 4.959 72.500
GET 4.959 75.000
GET 4.959 76.250
GET 4.959 77.500
GET 4.959 78.750
GET 4.959 80.000
GET 4.991 81.250
GET 4.991 82.500
GET 4.991 83.750
GET 4.991 85.000
GET 4.991 86.250
GET 5.023 87.500
GET 5.023 88.125
GET 5.023 88.750
GET 5.023 89.375
GET 5.023 90.000
GET 5.023 90.625
GET 5.055 91.250
GET 5.055 91.875
GET 5.055 92.500
GET 5.087 93.125
GET 5.119 93.750
GET 5.119 94.062
GET 5.151 94.375
GET 5.183 94.688
GET 5.279 95.000
GET 5.343 95.312
GET 5.375 95.625
GET 5.407 95.938
GET 5.439 96.250
GET 5.503 96.562
GET 7.295 96.875
GET 8.895 97.031
GET 9.151 97.188
GET 9.215 97.344
GET 9.279 97.500
GET 9.343 97.656
GET 9.599 97.812
GET 9.727 97.969
GET 9.727 98.125
GET 9.791 98.281
GET 9.791 98.438
GET 9.855 98.516
GET 9.855 98.594
GET 9.855 98.672
GET 9.855 98.750
GET 9.919 98.828
GET 9.919 98.906
GET 9.919 98.984
GET 9.983 99.062
GET 9.983 99.141
GET 10.047 99.219
GET 10.111 99.258
GET 10.239 99.297
GET 10.559 99.336
GET 10.879 99.375
GET 11.327 99.414
GET 12.031 99.453
GET 12.799 99.492
GET 13.567 99.531
GET 14.271 99.570
GET 15.039 99.609
GET 15.423 99.629
GET 15.807 99.648
GET 16.255 99.668
GET 16.639 99.688
GET 17.023 99.707
GET 17.535 99.727
GET 17.919 99.746
GET 18.431 99.766
GET 18.943 99.785
GET 19.455 99.805
GET 19.711 99.814
GET 19.967 99.824
GET 20.223 99.834
GET 20.607 99.844
GET 20.863 99.854
GET 21.247 99.863
GET 21.631 99.873
GET 21.887 99.883
GET 22.399 99.893
GET 22.783 99.902
GET 23.039 99.907
GET 23.167 99.912
GET 23.423 99.917
GET 23.679 99.922
GET 23.935 99.927
GET 24.191 99.932
GET 24.447 99.937
GET 24.831 99.941
GET 25.087 99.946
GET 25.471 99.951
GET 25.599 99.954
GET 25.727 99.956
GET 25.983 99.958
GET 26.111 99.961
GET 26.367 99.963
GET 26.495 99.966
GET 26.751 99.968
GET 26.879 99.971
GET 27.135 99.973
GET 27.391 99.976
GET 27.391 99.977
GET 27.519 99.978
GET 27.647 99.979
GET 27.775 99.980
GET 27.903 99.982
GET 28.031 99.983
GET 28.159 99.984
GET 28.415 99.985
GET 28.543 99.987
GET 28.671 99.988
GET 28.799 99.988
GET 28.799 99.989
GET 28.927 99.990
GET 29.055 99.990
GET 29.183 99.991
GET 29.311 99.991
GET 29.311 99.992
GET 29.439 99.993
GET 29.567 99.993
GET 29.695 99.994
GET 29.823 99.994
GET 29.951 99.995
GET 29.951 99.995
GET 30.079 99.995
GET 30.079 99.995
GET 30.207 99.996
GET 30.335 99.996
GET 30.463 99.996
GET 30.591 99.997
GET 30.591 99.997
GET 30.719 99.997
GET 30.719 99.997
GET 30.847 99.997
GET 30.975 99.998
GET 30.975 99.998
GET 31.103 99.998
GET 31.231 99.998
GET 31.231 99.998
GET 31.359 99.998
GET 31.487 99.998
GET 31.615 99.999
GET 31.615 99.999
GET 31.743 99.999
GET 31.743 99.999
GET 31.871 99.999
GET 31.999 99.999
GET 31.999 99.999
GET 32.127 99.999
GET 32.255 99.999
GET 32.383 99.999
GET 32.383 99.999
GET 32.511 99.999
GET 32.511 99.999
GET 32.639 99.999
GET 32.767 99.999
GET 32.767 99.999
GET 33.023 100.000
GET 33.023 100.000
GET 33.023 100.000
GET 33.279 100.000
GET 33.279 100.000
GET 33.279 100.000
GET 33.535 100.000
GET 33.535 100.000
GET 33.535 100.000
GET 33.791 100.000
GET 33.791 100.000
GET 33.791 100.000
GET 34.047 100.000
GET 34.047 100.000
GET 34.047 100.000
GET 34.047 100.000
GET 34.303 100.000
GET 34.303 100.000
GET 34.303 100.000
GET 34.303 100.000
GET 34.303 100.000
GET 34.559 100.000
GET 34.559 100.000
GET 34.559 100.000
GET 34.559 100.000
GET 34.815 100.000
GET 34.815 100.000
GET 34.815 100.000
GET 34.815 100.000
GET 35.071 100.000
GET 35.071 100.000
GET 35.071 100.000
GET 35.327 100.000
GET 35.327 100.000
GET 35.327 100.000
GET 35.583 100.000
GET 35.583 100.000
GET 35.583 100.000
GET 35.583 100.000
GET 35.583 100.000
GET 35.583 100.000
GET 35.839 100.000
GET 35.839 100.000
GET 35.839 100.000
GET 35.839 100.000
GET 36.095 100.000
GET 36.095 100.000
GET 36.095 100.000
GET 36.095 100.000
GET 36.095 100.000
GET 36.095 100.000
GET 36.351 100.000
GET 36.351 100.000
GET 36.351 100.000
GET 36.351 100.000
GET 36.351 100.000
GET 36.351 100.000
GET 36.351 100.000
GET 36.351 100.000
GET 36.607 100.000
GET 36.607 100.000
GET 36.607 100.000
GET 36.607 100.000
GET 36.863 100.000
GET 36.863 100.000
GET 36.863 100.000
GET 36.863 100.000
GET 36.863 100.000
GET 36.863 100.000
GET 37.119 100.000
GET 37.119 100.000
GET 37.119 100.000
GET 37.119 100.000
GET 37.375 100.000
GET 37.375 100.000
GET 37.375 100.000
GET 37.375 100.000
GET 37.375 100.000
GET 37.375 100.000
GET 37.375 100.000
GET 37.375 100.000
GET 37.375 100.000
GET 37.375 100.000
GET 37.375 100.000
GET 37.375 100.000
GET 37.375 100.000
GET 37.375 100.000
GET 37.375 100.000
GET 37.375 100.000
GET 37.631 100.000
GET 37.631 100.000
---
WAIT 0.000 100.000
6 小结
通过memtier-benchmark压测工具实现redis服务的压测,memtier-benchmark会输出报告,重点redis关心op数和延时。