文章永久连接:https://tech.souyunku.com/4807
Redis 服务通过同时执行多个命令来测试性能表现
Redis 性能测试语法
Redis 性能测试的基本命令如下
redis-benchmark [option] [option value]
范例
以下范例同时执行 10000 个请求来检测性能
$ redis-benchmark -n 10000 -q
PING_INLINE: 40000.00 requests per second
PING_BULK: 54347.82 requests per second
SET: 50251.26 requests per second
GET: 51813.47 requests per second
INCR: 52631.58 requests per second
LPUSH: 48309.18 requests per second
RPUSH: 47846.89 requests per second
LPOP: 49261.09 requests per second
RPOP: 44247.79 requests per second
SADD: 51020.41 requests per second
HSET: 42372.88 requests per second
SPOP: 50505.05 requests per second
LPUSH (needed to benchmark LRANGE): 52083.33 requests per second
LRANGE_100 (first 100 elements): 13927.58 requests per second
LRANGE_300 (first 300 elements): 6443.30 requests per second
LRANGE_500 (first 450 elements): 4587.16 requests per second
LRANGE_600 (first 600 elements): 3507.54 requests per second
MSET (10 keys): 25906.73 requests per second
你可以去掉 -q
查看详细测试
可选参数如下所示
选项 | 描述 | 默认值 |
---|---|---|
-h | 指定服务器主机名 | 127.0.0.1 |
-p | 指定服务器端口 | 6379 |
-s | 指定服务器 socket | |
-c | 指定并发连接数 | 50 |
-n | 指定请求数 | 10000 |
-d | 以字节的形式指定 SET/GET 值的数据大小 | 2 |
-k | 1=keep alive 0=reconnect | 1 |
-r | SET/GET/INCR 使用随机 key, SADD 使用随机值 | |
-P | 通过管道传输 <numreq> 请求 | 1 |
-q | 强制退出 redis。仅显示 query/sec 值 | |
–csv | 以 CSV 格式输出 | |
-l | 生成循环,永久执行测试 | |
-t | 仅运行以逗号分隔的测试命令列表 | |
-I | Idle 模式。仅打开 N 个 idle 连接并等待 |
范例
下面的 Shell 命令使用了多个参数来测试 redis 性能
$ redis-benchmark -h 127.0.0.1 -p 6379 -t set,lpush -n 10000 -q
SET: 49751.24 requests per second
LPUSH: 49261.09 requests per second
这个测试命令设置 主机为 127.0.0.1 端口号为 6379 测试的 Redis 命令为 set,lpush 请求数为 10000, 通过 -q 参数让结果只显示每秒执行的请求数
干货推荐
附录:Redis 教程:系列文章
- 一、Redis 基础教程
- 二、Redis 简介
- 三、Redis 安装
- 四、Redis 配置
- 五、Redis redis.conf 配置选项
- 六、Redis 数据类型
- 七、Redis 命令
- 八、Redis 键(key) 命令
- 九、Redis 字符串(String) 命令
- 十、Redis 哈希(Hash) 命令
- 十一、Redis 列表(List) 命令
- 十二、Redis 集合(Set) 命令
- 十三、Redis 有序集合(sorted set) 命令
- 十四、Redis HyperLogLog 命令
- 十五、Redis 发布订阅
- 十六、Redis 事务
- 十七、Redis Script( 脚本 ) 命令
- 十八、Redis 连接命令
- 十九、Redis 服务器
- 二十、Java 使用 Redis
- 二十一、PHP 和 Redis
- 二十二、Redis 数据备份与恢复
- 二十三、Redis 服务安全
- 【当前读到】二十四、Redis 性能测试
- 二十五、Redis 客户端连接
- 二十六、Redis 管道技术
- 二十七、Redis 分区