Redis 性能測(cè)試是通過(guò)同時(shí)執(zhí)行多個(gè)命令實(shí)現(xiàn)的。
redis 性能測(cè)試的基本命令如下:
redis-benchmark [option] [option value]
以下實(shí)例同時(shí)執(zhí)行 10000 個(gè)請(qǐng)求來(lái)檢測(cè)性能:
redis-benchmark -n 100000 PING_INLINE: 141043.72 requests per second PING_BULK: 142857.14 requests per second SET: 141442.72 requests per second GET: 145348.83 requests per second INCR: 137362.64 requests per second LPUSH: 145348.83 requests per second LPOP: 146198.83 requests per second SADD: 146198.83 requests per second SPOP: 149253.73 requests per second LPUSH (needed to benchmark LRANGE): 148588.42 requests per second LRANGE_100 (first 100 elements): 58411.21 requests per second LRANGE_300 (first 300 elements): 21195.42 requests per second LRANGE_500 (first 450 elements): 14539.11 requests per second LRANGE_600 (first 600 elements): 10504.20 requests per second MSET (10 keys): 93283.58 requests per second
redis 性能測(cè)試工具可選參數(shù)如下所示:
序號(hào) | 選項(xiàng) | 描述 | 默認(rèn)值 |
---|---|---|---|
1 | -h | 指定服務(wù)器主機(jī)名 | 127.0.0.1 |
2 | -p | 指定服務(wù)器端口 | 6379 |
3 | -s | 指定服務(wù)器 socket | |
4 | -c | 指定并發(fā)連接數(shù) | 50 |
5 | -n | 指定請(qǐng)求數(shù) | 10000 |
6 | -d | 以字節(jié)的形式指定 SET/GET 值的數(shù)據(jù)大小 | 2 |
7 | -k | 1=keep alive 0=reconnect | 1 |
8 | -r | SET/GET/INCR 使用隨機(jī) key, SADD 使用隨機(jī)值 | |
9 | -P | 通過(guò)管道傳輸 <numreq> 請(qǐng)求 | 1 |
10 | -q | 強(qiáng)制退出 redis。僅顯示 query/sec 值 | |
11 | --csv | 以 CSV 格式輸出 | |
12 | -l | 生成循環(huán),永久執(zhí)行測(cè)試 | |
13 | -t | 僅運(yùn)行以逗號(hào)分隔的測(cè)試命令列表。 | |
14 | -I | Idle 模式。僅打開 N 個(gè) idle 連接并等待。 |
以下實(shí)例我們使用了多個(gè)參數(shù)來(lái)測(cè)試 redis 性能:
redis-benchmark -h 127.0.0.1 -p 6379 -t set,lpush -n 100000 -q SET: 146198.83 requests per second LPUSH: 145560.41 requests per second
以上實(shí)例中主機(jī)為 127.0.0.1,端口號(hào)為 6379,執(zhí)行的命令為 set,lpush,請(qǐng)求數(shù)為 10000,通過(guò) -q 參數(shù)讓結(jié)果只顯示每秒執(zhí)行的請(qǐng)求數(shù)。
更多建議: