[转帖]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 ...
随机推荐
- Python——第五章:模块(Module)、自定义模块、第3方开源模块、包(Package)
什么是模块(Module)? 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护. 为了编写可维护的代码,我们把很多代码按功能分组,分别放到不同的文件里,这 ...
- 使用 vve-i18n-cli 来一键式自动化实现国际化
[Github:vue-viewer-editor/vve-i18n-cli] 这是我同事开发的国际化自动处理脚本,我进行过一次扩展,让其也支持我们一个 jQuery 老项目的国际化日常维护 至此,我 ...
- Rust 学习笔记
rust 学习梳理 数据类型 基于已明确的类型,Rust会推断剩下大部分类型.基于类型推断Rust具备了与动态类型语言近似的易读性,并仍能在编译期捕获类型错误. 函数可以是泛型的:单个函数ujiu可以 ...
- 轻量化动态编译库 Natasha v8.0 正式发布!
.NET8.0 与 动态编译 Hello 各位小伙伴,我于 2024年1月10日 发布了 Natasha 一个全新的里程碑版本 v8.0,对于老用户而言,此次发布版本号跨度较大,是因为我决定使用新的版 ...
- JQuery&Ajax基础知识
JQuery&Ajax基础知识 1.Jquery简介 Query是一个快速.简洁的JavaScript框架,是继Prototype之后又一个优秀的JavaScript代码库(框架)于2006年 ...
- 云图说|应用编排服务AOS,助力应用上云自动化
如今,企业想要扩大业务.进行创新,上云已经成为了必经之路.应用编排服务AOS为企业提供应用上云的自动化能力,支持编排华为云上的主流云服务,将复杂的云服务资源配置和应用部署配置通过模板描述,从而实现在华 ...
- 看华为云Serverless 4大特性如何让软件架构更丝滑
摘要:Serverless可以看作是一种云计算服务模型,它允许开发者在不需要管理服务器的情况下通过事件驱动的方式运行应用代码. 软件架构的发展从原先的单体架构到近十几年的微服务架构,再到现在新兴的Se ...
- 华为云自研PB级分布式时序数据库揭秘第一期:初识GaussDB(for Influx)
摘要:GaussDB(for Influx)提供了独特的数据存储管理解决方案,云原生的存储与计算架构,可根据业务变化快速扩容缩容:高效的数据压缩能力和数据冷热分离设计,可大幅降低数据存储成本:高吞吐的 ...
- 整理混乱的头文件,我用include what you use
摘要:使用include-what-you-use(iwyu/IWYU)清理冗余头文件,补充必要头文件. 本文分享自华为云社区<用include what you use拯救混乱的头文件> ...
- 火山引擎DataTester智能发布:助力产品降低功能迭代风险
更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,回复[1]进入官方交流群 对企业而言,应用大规模AB实验,可以帮助企业提高决策效率.降低试错成本,而近期火山引擎AB测试 DataTes ...
