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. vulnhub - lazySysAdmin - writeup

    信息收集 可以看到目标开放了常见的22, 80, 139, 445, 3306这个6667的服务少见. root@kali tmp/lazySysAdmin » arp-scan -I eth1 -l ...

  2. pwd详解

    linux下pwd 命令详解 Linux中用 pwd 命令来查看"当前工作目录"的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确定当前位置时,就 ...

  3. JavaFx css样式(三)

    JavaFx css样式(三) JavaFX 从入门入门到入土系列 JavaFx css样式,前面我说过它类似html,他有css控制样式,不过最新的css标准并不支持,同时javafx的css样式都 ...

  4. MyBatis 的缓存处理

    作为常见的 ORM 框架,在使用 MyBatis 的过程中可以针对相关的查询进行缓存处理以提高查询的性能.本文将简要介绍一下 MyBatis 中默认的一级缓存和二级缓存,以及自定义缓存的处理 MyBa ...

  5. 这些常见的python编码习惯,你都会吗

    本文分享自华为云社区<不得不知的十个常见PY编码习惯>,作者:码乐. 简介 语言在发展和变化,编码习惯也在发生改变.这里简单聊聊 17个python中常见的编码习惯或者风格. 1,可变数据 ...

  6. 计算机网络分层结构--OSI模型、TCP/IP 模型、五层模型

    计算机网络分层结构 OSI参考模型与TCP/IP参考模型 五层参考模型

  7. 文心一言 VS 讯飞星火 VS chatgpt (25)-- 算法导论4.2 7题

    七.设计算法,仅使用三次实数乘法即可完成复数 a+bi和c+di 相乘.算法需接收a.b.c和d 为输入,分别生成实部 ac-bd 和虚部ad+bc. 文心一言: 可以使用如下算法来计算复数 a+bi ...

  8. 牛刀小试基本语法,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang基本语法和变量的使用EP02

    书接上回,Go lang1.18首个程序的运行犹如一声悠扬的长笛,标志着并发编程的Go lang巨轮正式开始起航.那么,在这艘巨轮之上,我们首先该做些什么呢?当然需要了解最基本的语法,那就是基础变量的 ...

  9. 如何上传你的组件到npm

    前言 以react为例子 webpack作为打包工具 准备工作 安装node npm上注册账号 https://www.npmjs.com/ 创建要上传组件 新建项目 生成package.json文件 ...

  10. PPT 商务报告,如何去表现客户LOGO

    PPT 商务报告,如何去表现客户LOGO LOGO 如何下载 LOGO 如何展示 矩阵排列 删除背景,变成白色 删除背景 设置透明度 AI 软件做成矢量图 LOGO 转色法