112. Python语言 的 项目前导(上) 之 Redis 第十三章 :Redis 的 性能测试

本章主题

  

关键词

  

为什么需要性能测试?

性能测试的使用场景有很多,例如以下几个:

  1. 技术选型,比如测试 Memcached 和 Redis;
  2. 对比单机 Redis 和集群 Redis 的吞吐量;
  3. 评估不同类型的存储性能,例如集合和有序集合;
  4. 对比开启持久化和关闭持久化的吞吐量;
  5. 对比调优和未调优的吞吐量;
  6. 对比不同 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 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<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值