新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
RedisBenchmark性能測試
為了解 Redis 在不同配置環(huán)境下的性能表現(xiàn),Redis 提供了一種行性能測試工具 redis-benchmark(也稱壓力測試工具),它通過同時(shí)執(zhí)行多組命令實(shí)現(xiàn)對 Redis 的性能測試。
圖1:Redis Benchmark性能測試

性能測試的作用是讓我們了解 Redis 服務(wù)器的性能優(yōu)劣。在實(shí)際的業(yè)務(wù)場景中,性能測試是必不可少的。在業(yè)務(wù)系統(tǒng)上線之前,我們都需要清楚地了解 Redis 服務(wù)器的性能,從而避免發(fā)生某些意外情況,比如數(shù)據(jù)量過大會(huì)導(dǎo)致服務(wù)器宕機(jī)等。
測試命令格式
執(zhí)行測試命令,要在 Redis 的安裝目錄下執(zhí)行,命令如下所示:
redis-benchmark [option] [option value]
其中 option 為可選參數(shù), option value 為具體的參數(shù)值。 redis-benchmark 命令的可選參數(shù)如下所示:
| 參數(shù)選項(xiàng) | 說明 |
|---|---|
| -h | 指定服務(wù)器主機(jī)名。 |
| -p | 指定服務(wù)器端口。 |
| -s | 指定服務(wù)器 socket。 |
| -c | 指定并發(fā)連接數(shù)。 |
| -n | 指定請求的具體數(shù)量。 |
| -d | 以字節(jié)的形式指定 SET/GET 值的數(shù)據(jù)大小。 |
| -k | 1 表示 keep alive;0 表示 reconnect,默認(rèn)為 1。 |
| -r | SET/GET/INCR 使用隨機(jī) key, SADD 使用隨機(jī)值。 |
| -P | Pipeline 請求 |
| -q | 強(qiáng)制退出 Redis,僅顯示 query/sec 值。 |
| --csv | 以 CSV 格式輸出。 |
| -l | 生成循環(huán),永久執(zhí)行測試。 |
| -t | 僅運(yùn)行以逗號(hào)分隔的測試命令列表。 |
| -I(大寫i) | 空閑模式,打開 N 個(gè)空閑連接并等待連接。 |
在 Windows 系統(tǒng)下,其目錄文件如圖所示:
圖1:Redis Benchmark性能測試
執(zhí)行測試命令
1) Windows環(huán)境
在 Windows 10 系統(tǒng)環(huán)境下,同時(shí)執(zhí)行了 10000 個(gè)命令來檢測 Redis 服務(wù)器的性能,示例如下:
D:\Redis-x64-5.0.10>redis-benchmark.exe -n 10000 -q PING_INLINE: 21786.49 requests per second PING_BULK: 21231.42 requests per second #每秒執(zhí)行22935.78個(gè)請求 SET: 22935.78 requests per second GET: 22573.36 requests per second INCR: 19011.41 requests per second LPUSH: 7473.84 requests per second RPUSH: 20618.56 requests per second LPOP: 17793.60 requests per second RPOP: 21367.52 requests per second SADD: 15847.86 requests per second HSET: 21551.72 requests per second SPOP: 19531.25 requests per second LPUSH (needed to benchmark LRANGE): 18348.62 requests per second LRANGE_100 (first 100 elements): 6835.27 requests per second LRANGE_300 (first 300 elements): 4535.15 requests per second LRANGE_500 (first 450 elements): 3913.89 requests per second LRANGE_600 (first 600 elements): 3177.63 requests per second MSET (10 keys): 15128.59 requests per second
注意:若是 Linux 系統(tǒng),其每秒鐘執(zhí)行的請求數(shù)量是 Windows 系統(tǒng)的好幾倍。
2) Linux環(huán)境
Linux 環(huán)境下,Redis 的性能測試結(jié)果,如下所示:
$ redis-benchmark -n 10000 -q PING_INLINE: 141043.72 requests per second PING_BULK: 142857.14 requests per second #服務(wù)器每秒執(zhí)行的請求數(shù)量 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
3) 執(zhí)行指定的測試命令
帶參數(shù)的命令,使用示例如下:
D:\Redis-x64-5.0.10>redis-benchmark.exe -h 127.0.0.1 -p 6379 -n 10000 -t set,get,lpush -q SET: 17064.85 requests per second GET: 16051.36 requests per second LPUSH: 14224.75 requests per second
文章名稱:RedisBenchmark性能測試
當(dāng)前鏈接:http://m.fisionsoft.com.cn/article/ccdjcjp.html


咨詢
建站咨詢
