[转帖]redis-benchmark的使用总结
redis-benchmark的使用总结
Redis简介:
Redis是一个高性能的key-value数据库,redis与其他key-value缓存产品相比:
○ Redis支持数据的持久化,可以将内存中的数据保存在磁盘中,重启的时候可以再次加载进行使用。
○ Redis不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存储。
○ Redis支持数据的备份,即master-slave模式的数据备份。
○ Redis的优势:性能极高(读的QPS达到11w,写的QPS达到8w)
测试需求:
测试对象围绕Redis数据缓存功能,验证是否通过特定服务的情况下访问Redis服务的性能,本次性能测试考虑测性能指标包括QPS和延时;Redis测试范围包括:Redis操作单一key、操作多key及pipeline操作;测试场景覆盖通过特定服务及不通过特定服务两种情况下访问Redis。
测试环境架构
测试工具Redis-benchmark
Redis-benchmark是目前进行redis性能测试的主流工具,并且redis-benchmark是redis自带的工具,安装redis之后不需要安装即可直接使用
1 redis-benchmark使用方法
Redis-benchmark的使用非常简单,使用方法如下,Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests]> [-k <boolean>] 我们只需要了解redis-benchmark命令参数的作用即可执行性能测试
[root@XXX ~]# redis-benchmark -h
Invalid option "-h" or option argument missing
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
-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 2)
--dbnum <db> SELECT the specified db number (default 0)
-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
--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 <span class="token number">127.0</span>.0.1:6379:
$ redis-benchmark Use <span class="token number">20</span> parallel clients, <span class="token keyword">for</span> a total of 100k requests, against <span class="token number">192.168</span>.1.1:
$ redis-benchmark -h <span class="token number">192.168</span>.1.1 -p <span class="token number">6379</span> -n <span class="token number">100000</span> -c <span class="token number">20</span> Fill <span class="token number">127.0</span>.0.1:6379 with about <span class="token number">1</span> million keys only using the SET test:
$ redis-benchmark -t <span class="token builtin class-name">set</span> -n <span class="token number">1000000</span> -r <span class="token number">100000000</span> Benchmark <span class="token number">127.0</span>.0.1:6379 <span class="token keyword">for</span> a few commands producing CSV output:
$ redis-benchmark -t ping,set,get -n <span class="token number">100000</span> --csv Benchmark a specific <span class="token builtin class-name">command</span> line:
$ redis-benchmark -r <span class="token number">10000</span> -n <span class="token number">10000</span> <span class="token builtin class-name">eval</span> <span class="token string">'return redis.call("ping")'</span> <span class="token number">0</span> Fill a list with <span class="token number">10000</span> random elements:
$ redis-benchmark -r <span class="token number">10000</span> -n <span class="token number">10000</span> lpush mylist __rand_int__ On user specified <span class="token builtin class-name">command</span> lines __rand_int__ is replaced with a random integer
with a range of values selected by the -r option.
参数的作用
| 作用分类 | 参数及作用 |
|---|---|
| 连接 Redis 服务相关参数 | -h :Redis 服务主机地址,默认为 127.0.0.1 。 |
| -p :Redis 服务端口,默认为 6379 。 | |
| -s :指定连接的 Redis 服务地址,用于覆盖 -h 和 -p 参数。一般情况下,我们并不会使用。 | |
| -a :Redis 认证密码。 | |
| –dbnum :选择 Redis 数据库编号。 | |
| k :是否保持连接。默认会持续保持连接。 | |
| 请求相关参数 | -c :并发的客户端数 |
| -n :总共发起的操作(请求)数 | |
| -d :指定 SET/GET 操作的数据大小,单位:字节。 | |
| -r :SET/GET/INCR 使用随机 KEY ,SADD 使用随机值。通过设置-r参数,可以设置KEY的随机范围,比如-r 10生成的KEY范围为[0,9) | |
| -P :默认情况下,Redis 客户端一次请求只发起一个命令。通过 -P 参数,可以设置使用 pipeline功能,一次发起指定个请求,从而提升 QPS 。 | |
| -l :循环,一直执行基准测试。 | |
| -t :指定需要测试的 Redis 命令,多个命令通过逗号分隔。默认情况下,测试 PING_INLINE/PING_BULK/SET/GET 等等命令。若只想测试 SET/GET 命令,则可以 -t SET,GET 来指定。 | |
| -I :Idle 模式。仅仅打开 N 个 Redis Idle 个连接,然后等待,啥也不做。不是很理解这个参数的目的,目前猜测,仅仅用于占用 Redis 连接。 | |
| 结果输出相关参数 | -e :如果 Redis Server 返回错误,是否将错误打印出来。默认情况下不打印,通过该参数开启。 |
| -q :精简输出结果。即只展示每个命令的 QPS 测试结果 | |
| -csv :按照 CSV 的格式,输出结果 |
2 测试查看
测试脚本自动化
测试步骤:
1、测试Redis 单一key,设置-r参数为1
测试命令:redis-benchmark -h redis-XXX.com -r 1 -c 100 –n 150000 -t get,set
2、测试Redis 多key,设置-r参数为50
测试命令:redis-benchmark -h redis-XXX.com -r 50 -c 100 –n 150000 -t get,set
3、测试Redis pipeline,设置-P参数为当前系统核数
测试命令:redis-benchmark -h redis-XXX.com -r 50 -c 100 –n 150000 -t get,set -P 16
4、手动调试确定连接数和发起请求书的最优区间范围,通过多次增加连接数和请求数的数值,从结果中选择较优结果情况下的连接数和请求数(比如 连接数300,请求数10w)
5、基于以上获取的请求数,设置-n参数为15w,在连接数相近的区间内(200–500),编写获取最优连接数的测试脚本,如下:
#!/bin/bash connect=(200 250 300 350 400)
n=2000000
host1=redis-XXX.com
host2=ip for c in \(<span class="token punctuation">{<!-- --></span>connect<span class="token punctuation">[</span>@<span class="token punctuation">]</span><span class="token punctuation">}</span>:
<span class="token keyword">do</span>
<span class="token comment">## redis-onekey</span>
<span class="token function">echo</span> <span class="token string">"redis-benchmark -h <span class="token variable">\)host1 -r 1 -c \(c</span> -n <span class="token variable">\)n -t get,set" >> ./results/redis-onekey.log
redis-benchmark -h \(host1</span> <span class="token operator">-</span>r 1 <span class="token operator">-</span>c <span class="token variable">\)c -n \(n</span> <span class="token operator">-</span>t get<span class="token punctuation">,</span><span class="token function">set</span> >> <span class="token punctuation">.</span><span class="token operator">/</span>results<span class="token operator">/</span>redis<span class="token operator">-</span>onekey<span class="token punctuation">.</span>log
<span class="token comment">## redis-keys</span>
<span class="token function">echo</span> <span class="token string">"redis-benchmark -h <span class="token variable">\)host1 -r 100 -c \(c</span> -n <span class="token variable">\)n -t get,set" >>./results/redis-keys.log
redis-benchmark -h \(host1</span> <span class="token operator">-</span>r 100 <span class="token operator">-</span>c <span class="token variable">\)c -n \(n</span> <span class="token operator">-</span>t get<span class="token punctuation">,</span><span class="token function">set</span> >><span class="token punctuation">.</span><span class="token operator">/</span>results<span class="token operator">/</span>redis<span class="token operator">-</span>keys<span class="token punctuation">.</span>log
<span class="token comment">## redis-pipeline</span>
<span class="token function">echo</span> <span class="token string">"redis-benchmark -h <span class="token variable">\)host1 -r 1 -c \(c</span> -n <span class="token variable">\)n -t get,set -P 16" >>./results/redis-pipeline.log
redis-benchmark -h \(host1</span> <span class="token operator">-</span>r 1 <span class="token operator">-</span>c <span class="token variable">\)c -n \(n</span> <span class="token operator">-</span>t get<span class="token punctuation">,</span><span class="token function">set</span> <span class="token operator">-</span>P 16 >><span class="token punctuation">.</span><span class="token operator">/</span>results<span class="token operator">/</span>redis<span class="token operator">-</span>pipeline<span class="token punctuation">.</span>log
<span class="token comment">## server-onekey</span>
<span class="token function">echo</span> <span class="token string">"redis-benchmark -h <span class="token variable">\)host2 -r 1 -c \(c</span> -n <span class="token variable">\)n -t get,set" >>./results/server-onekey.log
redis-benchmark -h \(host2</span> <span class="token operator">-</span>r 1 <span class="token operator">-</span>c <span class="token variable">\)c -n \(n</span> <span class="token operator">-</span>t get<span class="token punctuation">,</span><span class="token function">set</span> >><span class="token punctuation">.</span><span class="token operator">/</span>results<span class="token operator">/</span>server<span class="token operator">-</span>onekey<span class="token punctuation">.</span>log
<span class="token comment">##server-keys</span>
<span class="token function">echo</span> <span class="token string">"#dsg-keys /n redis-benchmark -h <span class="token variable">\)host2 -r 100 -c \(c</span> -n <span class="token variable">\)n -t get,set ">>./results/server-keys.log
redis-benchmark -h \(host2</span> <span class="token operator">-</span>r 100 <span class="token operator">-</span>c <span class="token variable">\)c -n \(n</span> <span class="token operator">-</span>t get<span class="token punctuation">,</span><span class="token function">set</span> >><span class="token punctuation">.</span><span class="token operator">/</span>results<span class="token operator">/</span>server<span class="token operator">-</span>keys<span class="token punctuation">.</span>log
<span class="token comment">## server-pipeline</span>
<span class="token function">echo</span> <span class="token string">"redis-benchmark -h <span class="token variable">\)host2 -r 1 -c \(c</span> -n <span class="token variable">\)n -t get,set -P 16" >>./results/server-pipeline.log
redis-benchmark -h \(host2</span> <span class="token operator">-</span>r 1 <span class="token operator">-</span>c <span class="token variable">\)c -n $n -t get,set -P 16 -q >>./results/server-pipeline.log
done
6、执行脚本之后,通过log日志,记录不同连接数下的QPS和lantency的结果,如下所示:
| 并发数设置 | SET结果数据 | GET结果数据 |
|---|---|---|
| QPS/Lantency | QPS/Lantency | |
| 200 | 71123 / 13ms | 72358 /11ms |
| 250 | 81900 / 20ms | 83194 / 20ms |
| 300 | 89847 / 24ms | 90497 / 20ms |
| 350 | 93457 / 30ms | 93370 / 29ms |
| 400 | 95602 / 145ms | 97847 /135ms |
测试结果
使用pipeline可以大幅度提高redis服务器的处理能力,其基本原理是通过pipeline减少了网络传输的次数,因此降低了网络延迟的影响.
[转帖]redis-benchmark的使用总结的更多相关文章
- Azure Redis Cache (3) 在Windows 环境下使用Redis Benchmark
<Windows Azure Platform 系列文章目录> 熟悉Redis环境的读者都知道,我们可以在Linux环境里,使用Redis Benchmark,测试Redis的性能. ht ...
- [转帖]Redis持久化--Redis宕机或者出现意外删库导致数据丢失--解决方案
Redis持久化--Redis宕机或者出现意外删库导致数据丢失--解决方案 https://www.cnblogs.com/xlecho/p/11834011.html echo编辑整理,欢迎转载,转 ...
- [转帖]Redis、Memcache和MongoDB的区别
Redis.Memcache和MongoDB的区别 https://www.cnblogs.com/tuyile006/p/6382062.html >>Memcached Memcach ...
- [转帖]Redis性能解析--Redis为什么那么快?
Redis性能解析--Redis为什么那么快? https://www.cnblogs.com/xlecho/p/11832118.html echo编辑整理,欢迎转载,转载请声明文章来源.欢迎添加e ...
- [转帖]Redis未授权访问漏洞复现
Redis未授权访问漏洞复现 https://www.cnblogs.com/yuzly/p/11663822.html config set dirconfig set dbfile xxxx 一. ...
- [转帖]redis知识点总结
redis面试常问知识点总结 https://www.toutiao.com/i6740199554127233543/ 原创 波波说运维 2019-10-02 00:01:00 概述 今天主要分享一 ...
- [转帖]redis监控工具汇总
redis监控工具汇总 https://www.cnblogs.com/felixzh/p/11170143.html redis-stat redis-stat是一个比较有名的redis指标可视化的 ...
- Redis 的性能幻想与残酷现实
2011 年,当初选择 Redis 作为主要的内存数据存储,主要吸引我的是它提供多样的基础数据结构可以很方便的实现业务需求.另一方面又比较担心它的性能是否足以支撑,毕竟当时 Redis 还属于比较新的 ...
- 转载----How fast is Redis?
How fast is Redis? Redis includes the redis-benchmark utility that simulates running commands done b ...
- benchmark
redis benchmark How many requests per second can I get out of Redis? Using New Relic to Understand R ...
随机推荐
- k8s集群Node节点管理:节点信息查看及节点label标签管理
k8s集群Node节点管理:节点信息查看及节点label标签管理 Kubernetes集群Node管理 一.查看集群信息 [root@k8s-master1 ~]# kubectl cluster-i ...
- Cesium案例解析(九)——Rotatable2DMap旋转2D地图
目录 Cesium的Rotatable 2D Map示例展示了一个旋转的二维地图: 'use strict'; var viewer = new Cesium.Viewer('cesiumContai ...
- Istio与Kubernetes:资源管理与协同解析
本文分享自华为云社区<istio资源介绍以及和kubernetes资源扭转关系>,作者:可以交个朋友. 一.istio原理 Istio的原理是拦截 Kubernetes 中创建 Pod 的 ...
- 实战案例丨使用云连接CC和数据复制服务DRS实现跨区域RDS迁移和数据同步
摘要:实践案例展示如何使用云连接CC和数据复制服务DRS实现跨区域RDS迁移和数据同步. [业务场景及诉求] 希望将不同区域"华北-北京四"的rds与"亚太-新加坡&qu ...
- 华为云 UCS GitOps:轻松交付多集群云原生应用
摘要:使用华为云 UCS GitOps 配置管理来交付您的多云应用. 本文分享自华为云社区<华为云 UCS GitOps:轻松交付多集群云原生应用>,作者:华为云云原生团队. 随着业务的全 ...
- 为什么MySQL单表不能超过2000万行?
摘要:MySQL一张表最多能存多少数据? 本文分享自华为云社区<为什么MySQL单表不能超过2000万行?>,作者: GaussDB 数据库 . 最近看到一篇<我说MySQL每张表最 ...
- appuploader 入门使用
回想一下我们发布 iOS 应用,不仅步骤繁琐,非常耗时.一旦其中一步失误了,又得重新来.作为一名优秀的工程师不应该让这些重复的工作在浪费我们的人生.在软件工程里面,我们一直都推崇把重复.流程化的工作交 ...
- 补齐OLAP引擎短板!ByteHouse 是如何实现流批一体的?
更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,回复[1]进入官方交流群 计算机领域一直流传一句话--"没有银弹",这句话出自计算机科学家布鲁克斯<没有银弹& ...
- matplotlib 图表生成
条形颜色演示 import matplotlib.pyplot as plt ''' 将plt.subplots()函数的返回值赋值给fig和ax俩个变量 plt.subplots()是一个函数,返回 ...
- 多图预警,DreamBooth 微调黑客松结果发布啦!
去年 12 月底,我们面向全球的开发者举办了 DreamBooth 编程马拉松活动.通过 DreamBooth,你可以使用少量的图像对文生图模型进行微调,将你「喂给」模型的图片信息进行命名,就可以通过 ...
