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> &gt;&gt; <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> &gt;&gt;<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 &gt;&gt;<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> &gt;&gt;<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> &gt;&gt;<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的使用总结的更多相关文章

  1. Azure Redis Cache (3) 在Windows 环境下使用Redis Benchmark

    <Windows Azure Platform 系列文章目录> 熟悉Redis环境的读者都知道,我们可以在Linux环境里,使用Redis Benchmark,测试Redis的性能. ht ...

  2. [转帖]Redis持久化--Redis宕机或者出现意外删库导致数据丢失--解决方案

    Redis持久化--Redis宕机或者出现意外删库导致数据丢失--解决方案 https://www.cnblogs.com/xlecho/p/11834011.html echo编辑整理,欢迎转载,转 ...

  3. [转帖]Redis、Memcache和MongoDB的区别

    Redis.Memcache和MongoDB的区别 https://www.cnblogs.com/tuyile006/p/6382062.html >>Memcached Memcach ...

  4. [转帖]Redis性能解析--Redis为什么那么快?

    Redis性能解析--Redis为什么那么快? https://www.cnblogs.com/xlecho/p/11832118.html echo编辑整理,欢迎转载,转载请声明文章来源.欢迎添加e ...

  5. [转帖]Redis未授权访问漏洞复现

    Redis未授权访问漏洞复现 https://www.cnblogs.com/yuzly/p/11663822.html config set dirconfig set dbfile xxxx 一. ...

  6. [转帖]redis知识点总结

    redis面试常问知识点总结 https://www.toutiao.com/i6740199554127233543/ 原创 波波说运维 2019-10-02 00:01:00 概述 今天主要分享一 ...

  7. [转帖]redis监控工具汇总

    redis监控工具汇总 https://www.cnblogs.com/felixzh/p/11170143.html redis-stat redis-stat是一个比较有名的redis指标可视化的 ...

  8. Redis 的性能幻想与残酷现实

    2011 年,当初选择 Redis 作为主要的内存数据存储,主要吸引我的是它提供多样的基础数据结构可以很方便的实现业务需求.另一方面又比较担心它的性能是否足以支撑,毕竟当时 Redis 还属于比较新的 ...

  9. 转载----How fast is Redis?

    How fast is Redis? Redis includes the redis-benchmark utility that simulates running commands done b ...

  10. benchmark

    redis benchmark How many requests per second can I get out of Redis? Using New Relic to Understand R ...

随机推荐

  1. Java反序列化漏洞-URLDNS链分析

    目录 一.前置知识 反射 二.分析 1. URL 2. HashMap 3. 解决一些问题 反射修改字段值 三.POC 四.利用链 一.前置知识 菜鸟教程 Java 序列化 Java安全-反射 URL ...

  2. 虚拟化M搭建及基本操作

    虚拟化MH搭建 虚拟化概念: 虚拟机安装分为2块:RHEVM .RHEVH RHEVM:负责管理角色 RHEVH:负责运算角色 2016-09-23_0-52-54.png hypervisor: 提 ...

  3. k8s 标签-2

    目录 标签-2 node的角色 修改node节点的角色,将他的角色修改成他的主机名 标签的作用 Cordon,Drain以及污点 Cordon--告警警戒 Drain 驱逐演示 污点 污点的Cordo ...

  4. Guava常用工具类总结

    === -"我想写得更优雅,可是没人告诉我怎么写得更优雅" -"Null的含糊语义让人很不舒服.Null很少可以明确地表示某种语义,例如,Map.get(key)返回Nu ...

  5. 网络知识一箩筐:IP地址划分的那些知识点

    摘要:IP地址是怎么划分的呢?划分的依据是什么呢?本节小课将带你一起学习IP地址划分.子网划分.子网掩码.CIDR等网络基础概念,了解IP地址划分背后的那些故事. 首先,回忆一下,前面小课中我们有提到 ...

  6. CG行业云渲染服务的演进之路

    摘要:影视动画.特效制作等行业渲染需求量增多,4K/6K以及各高分辨率会陆续成为主流,本地算力与存储资源已无法满足现有任务量.而随着大环境的演变,CG行业发展已进入发展快车道.来自赞奇科技的CEO金伟 ...

  7. 【CVPR2022】用于域适应语义分割的域无关先验

    摘要:本文给大家分享一篇我们在CVPR 2022 上发表的paper:Domain-Agnostic Prior for Transfer Semantic Segmentation.文章提出了一种图 ...

  8. 分享个本地maven配置

    用阿里云的快有点受不了了,经常有包下载不了 settings.xml <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0&q ...

  9. 敏捷编辑器Sublime text 4中文配置Python3开发运行代码环境

    敏捷编辑器Sublime text 4中文配置Python3开发运行代码环境 首先来到Win11环境下,进入Sublime text 4官网的下载页面:https://www.sublimetext. ...

  10. ME51N 采购申请屏幕增强仅显示字段

    1.业务需求 通过委外工单生成的采购申请,需要将自定义"图号"字段显示在采购申请中,且只用于显示即可 2.增强实现 增强表EBAN的结构CI_EBANDB 增强点CMOD:MERE ...