[转帖]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 ...
随机推荐
- @Value是个什么东西
对注解不了解的可以看一下: Java注解,看完就会用 首先我们要明确: @Value 是 Spring 框架的注解. 它有什么作用呢? 作用 @Value 通过注解将常量.配置文件中的值.其他bean ...
- 在CentOS安装BIND,把所有DNS请求日志转发到syslog服务器去
在CentOS安装BIND,把所有DNS请求日志转发到syslog服务器去 在vim /etc/named.conf里配置的内容 logging { channel default_debug { f ...
- Java反序列化漏洞-CC1利用链分析
@ 目录 一.前置知识 1. 反射 2. Commons Collections是什么 3. 环境准备 二.分析利用链 1. Transformer 2. InvokeTransformer 执行命令 ...
- 0X01 位运算笔记
位运算,经常可以用来处理一些数学或动归方面的问题,通常会在数据范围较小的情况下使用. 为方便起见,一个 \(\mathrm{n}\) 位二进制数从右到左分别为第 \(\mathrm{0 \sim n ...
- 技术实操丨使用ModelArts和HiLens Studio完成云端验证及部署
前言 HiLens Studio公测也出来一阵子了,亮点很多,我前些天也申请了公测,通过后赶快尝试了一下,不得不说真的很不错啊,特别是支持云端编辑代码,调试,甚至可以直接运行程序,即使自己的HiLen ...
- GaussDB技术解读系列之SQL Audit,面向应用开发的SQL审核工具
本文分享自华为云社区<GaussDB技术解读系列之SQL Audit,面向应用开发的SQL审核工具>,作者:华为云数据库和应用迁移专家. 前言 我们先从一个SQL语句说起(以某传统 ...
- 通过windows自带管理工具、系统命令行、快捷键等快速操作
windows自带管理工具 我们win+R 输入一些命令,可以快速打开一些界面,比如: sysdm.cpl win10.win11 我电脑,属性与之前win7不同了,我希望打开之前的属性打不开了 通过 ...
- 从下个月开始,App Store 要求使用 Xcode 14 构建的 iOS 16 兼容应用程序
Xcode 继向开发者发布第一个iOS 16.5 测试版后,苹果公司周二宣布了对开发者向 App Store 提交应用程序的新要求.从下个月开始,Apple 将要求每个应用程序都必须使用 Xcode ...
- 2023 年如何将您的应用提交到 App Store
您夜以继日地工作来创建您的梦想应用程序.最后,是时候向全世界宣布您的应用程序了.但不知道如何将您的应用提交到 App Store? 为您的商店获取现成的移动应用程序 将应用程序提交到 App Stor ...
- 用 Java?试试国产轻量的 Solon v1.10.1
相对于 Spring Boot 和 Spring Cloud 的项目: 启动快 5 - 10 倍. (更快) qps 高 2- 3 倍. (更高) 运行时内存节省 1/3 ~ 1/2. (更少) 打包 ...
