本文主要是介绍112. Python语言 的 项目前导(上) 之 Redis 第十三章 :Redis 的 性能测试,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Redis 的 性能测试
- 本章主题
- 关键词
- 为什么需要性能测试?
- 性能测试的几种方式
- 基准测试实战
- 基本使用
- 精简测试
- 管道测试
- 基准测试的影响元素
- 总结小便条
本章主题
关键词
为什么需要性能测试?
性能测试的使用场景有很多,例如以下几个:
- 技术选型,比如测试 Memcached 和 Redis;
- 对比单机 Redis 和集群 Redis 的吞吐量;
- 评估不同类型的存储性能,例如集合和有序集合;
- 对比开启持久化和关闭持久化的吞吐量;
- 对比调优和未调优的吞吐量;
- 对比不同 Redis 版本的吞吐量,作为是否升级的一个参考标准。
等等,诸如此类的情况,我们都需要进行性能测试。
性能测试的几种方式
既然性能测试使用场景那么多,那要怎么进行性能测试呢?
目前比较主流的性能测试分为两种:
- 编写代码模拟并发进行性能测试;
- 使用 redis-benchmark 进行测试。
因为自己编写代码进行性能测试的方式不够灵活,且很难短时间内模拟大量的并发数,所以并不建议使用这种方式。幸运的是 Redis 本身给我们提供了性能测试工具 redis-benchmark(Redis 基准测试)
基准测试实战
redis-benchmark
位于 Redis 的 src 目录下,我们可以使用 ./redis-benchmark -h
来查看基准测试的使用,执行结果如下:
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 3)--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 SADDUsing this option the benchmark will expand the string __rand_int__inside an argument with a 12 digits number in the specified rangefrom 0 to keyspacelen-1. The substitution changes every time a commandis executed. Default tests use this to hit random keys in thespecified range.-P <numreq> Pipeline <numreq> requests. Default 1 (no pipe
这篇关于112. Python语言 的 项目前导(上) 之 Redis 第十三章 :Redis 的 性能测试的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!