nosql redis資料庫壓力測試基準工具redis-benchmark

wisdomone1發表於2018-04-18
1,檢視基準測試工具的用法
[root@langfang src]# pwd
/redis_dir/redis-4.0.9/src
[root@langfang src]# ./redis-benchmark  -help
Invalid option "-help" or option argument missing


Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests>] [-k <boolean>]


 -h <hostname>      Server hostname (default 127.0.0.1) -h 連線REDIS伺服器IP,預設為127.0.0.1
 -p <port>          Server port (default 6379)    -P REDIS伺服器埠 ,預設為6379
 -s <socket>        Server socket (overrides host and port)  -S 伺服器套接字(覆蓋主機和埠)
 -a <password>      Password for Redis Auth --A REDIS AUTH的認證密碼
 -c <clients>       Number of parallel connections (default 50)  --c 表示併發連線數量,預設50個
 -n <requests>      Total number of requests (default 100000)  ---n 請求的總數量,預設為100000,即10萬
 -d <size>          Data size of SET/GET value in bytes (default 3) --D 表示SET GET的大小,預設大小為3
 --dbnum <db>       SELECT the specified db number (default 0)  --dbnum 指定連線哪個資料庫,預設為0號資料庫
 -k <boolean>       1=keep alive 0=reconnect (default 1)  -k 布林型別,1為保持連線,預設值;0為重連
 -r <keyspacelen>   Use random keys for SET/GET/INCR, random values for SADD --r 為SET GET INCR操作使用隨機的鍵,為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).  --P 與管道技術有關,請求的次數,預設為1,即禁用管道技術,假如伺服器報錯,顯示報錯資訊
 -e                 If server replies with errors, show them on stdout.  
                    (no more than 1 error per second is displayed) --僅僅每秒顯示1個報錯
 -q                 Quiet. Just show query/sec values  -Q 安靜,僅僅顯示 每秒 查詢值
 --csv              Output in CSV format --CSV 以CSV格式輸出
 -l                 Loop. Run the tests forever -L 一直壓測,不停止
 -t <tests>         Only run the comma separated list of tests. The test -T   -L 執行以 逗 號分隔的測試列表,指定具體的壓力測試場景,比如是set or mget or get and so on
                    names are the same as the ones produced as output.
 -I                 Idle mode. Just open N idle connections and wait. --L 空閒模式,只是開啟N個空閒連線然後等待


Examples: ---示例


 Run the benchmark with the default configuration against 127.0.0.1:6379:
   $ redis-benchmark


 Use 20 parallel clients, for a total of 100k requests, against 192.168.1.1:
   $ redis-benchmark -h 192.168.1.1 -p 6379 -n 100000 -c 20


 Fill 127.0.0.1:6379 with about 1 million keys only using the SET test:
   $ redis-benchmark -t set -n 1000000 -r 100000000


 Benchmark 127.0.0.1:6379 for a few commands producing CSV output:
   $ redis-benchmark -t ping,set,get -n 100000 --csv


 Benchmark a specific command line:
   $ redis-benchmark -r 10000 -n 10000 eval 'return redis.call("ping")' 0


 Fill a list with 10000 random elements:
   $ redis-benchmark -r 10000 -n 10000 lpush mylist __rand_int__


 On user specified command lines __rand_int__ is replaced with a random integer
 with a range of values selected by the -r option.
[root@langfang src]# 










2,redis-benchmark預設壓力測試
--壓力測試結論包括  壓力測試消耗時間及每秒最大處理的請求數以及各種的壓力測試場景的不同子節
[root@langfang src]# ./redis-benchmark 
====== PING_INLINE ======    ---概述的名稱
  100000 requests completed in 1.51 seconds  --概要結論,消耗 1.51秒 完成 10萬次請求
  50 parallel clients
  3 bytes payload
  keep alive: 1


96.26% <= 1 milliseconds
99.96% <= 2 milliseconds
100.00% <= 2 milliseconds
66181.34 requests per second   --每秒完成 6.6萬左右請求


====== PING_BULK ======
  100000 requests completed in 1.70 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


93.00% <= 1 milliseconds
99.98% <= 2 milliseconds
100.00% <= 2 milliseconds
58788.95 requests per second


====== SET ======
  100000 requests completed in 1.69 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


92.51% <= 1 milliseconds
99.95% <= 2 milliseconds
100.00% <= 2 milliseconds
59241.71 requests per second


====== GET ======
  100000 requests completed in 1.53 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


96.22% <= 1 milliseconds
99.97% <= 2 milliseconds
100.00% <= 2 milliseconds
65402.22 requests per second


====== INCR ======
  100000 requests completed in 1.55 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


95.60% <= 1 milliseconds
100.00% <= 2 milliseconds
100.00% <= 2 milliseconds
64683.05 requests per second


====== LPUSH ======
  100000 requests completed in 1.52 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


94.17% <= 1 milliseconds
99.99% <= 2 milliseconds
100.00% <= 2 milliseconds
65573.77 requests per second


====== RPUSH ======
  100000 requests completed in 1.57 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


94.06% <= 1 milliseconds
99.97% <= 2 milliseconds
100.00% <= 2 milliseconds
63734.86 requests per second


====== LPOP ======
  100000 requests completed in 1.51 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


94.25% <= 1 milliseconds
99.98% <= 2 milliseconds
100.00% <= 2 milliseconds
66269.05 requests per second


====== RPOP ======
  100000 requests completed in 1.52 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


95.01% <= 1 milliseconds
99.95% <= 2 milliseconds
100.00% <= 2 milliseconds
65919.58 requests per second



====== LPUSH (needed to benchmark LRANGE) ======
  100000 requests completed in 1.50 seconds
  50 parallel clients




====== LRANGE_500 (first 450 elements) ======
  100000 requests completed in 10.29 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


3.16% <= 1 milliseconds
22.80% <= 2 milliseconds
46.08% <= 3 milliseconds
65.75% <= 4 milliseconds
81.96% <= 5 milliseconds
94.78% <= 6 milliseconds




====== MSET (10 keys) ======
  100000 requests completed in 2.06 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


57.05% <= 1 milliseconds
98.41% <= 2 milliseconds
99.98% <= 3 milliseconds
100.00% <= 3 milliseconds
48567.27 requests per second




[root@langfang src]# 




3,還是各種壓測場景,不過是20個併發,10萬次請求,連線指定REDIS伺服器
[root@langfang src]# ./redis-benchmark -h 127.0.0.1 -p 6379 -n 100000 -c 20
====== PING_INLINE ======
  100000 requests completed in 1.63 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1


99.69% <= 1 milliseconds
100.00% <= 1 milliseconds
61312.08 requests per second


====== PING_BULK ======
  100000 requests completed in 1.67 seconds
  20 parallel clients
  3 bytes payload
  keep alive: 1




4,指定測試場景比如 GET AND SET 以及隨機鍵的數量以及請求個數
[root@langfang src]# ./redis-benchmark  -t set,get -n 100000 -r 1000
====== SET ======
  100000 requests completed in 1.60 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


94.68% <= 1 milliseconds
99.93% <= 2 milliseconds
100.00% <= 2 milliseconds
62656.64 requests per second


====== GET ======
  100000 requests completed in 1.68 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


93.91% <= 1 milliseconds
99.93% <= 2 milliseconds
100.00% <= 2 milliseconds
59488.40 requests per second




5,csv格式輸出
[root@langfang src]# ./redis-benchmark -t ping,get,set -n 1000 --csv
"PING_INLINE","52631.58"
"PING_BULK","55555.56"
"SET","52631.58"
"GET","52631.58"


6,執行特定的命令列
[root@langfang src]# ./redis-benchmark  -r 1000 -n 100000 eval 'return redis.call("ping")'
====== eval return redis.call("ping") ======
  100000 requests completed in 1.56 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


95.66% <= 1 milliseconds
99.93% <= 2 milliseconds
100.00% <= 2 milliseconds
63979.53 requests per second




7, Fill a list with 10000 random elements  以隨機指定的範圍元素填充list
[root@langfang src]# ./redis-benchmark  -r 10000 -n 1000 lpush mylist _rand_init__
====== lpush mylist _rand_init__ ======
  1000 requests completed in 0.02 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


87.20% <= 1 milliseconds
99.50% <= 2 milliseconds
100.00% <= 2 milliseconds
47619.05 requests per second




[root@langfang src]# ./redis-benchmark  -r 10000 -n 1000 set mylist _rand_init__
====== set mylist _rand_init__ ======
  1000 requests completed in 0.02 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


86.40% <= 1 milliseconds
100.00% <= 1 milliseconds
47619.05 requests per second




8,靜默方式壓力測試
[root@langfang src]# ./redis-benchmark  -t set,get -n 100000 -r 1000
====== SET ======
  100000 requests completed in 1.58 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


94.99% <= 1 milliseconds
99.96% <= 2 milliseconds
100.00% <= 2 milliseconds
63211.12 requests per second


====== GET ======
  100000 requests completed in 1.60 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


95.21% <= 1 milliseconds
99.99% <= 2 milliseconds
100.00% <= 2 milliseconds
62617.41 requests per second


--可見靜默方式只顯示每次處理的請求數以及壓力測試場景
[root@langfang src]# ./redis-benchmark  -t set,get -n 100000 -r 1000 -q
SET: 63091.48 requests per second
GET: 64724.92 requests per second




9,redis-cli可以直接附上操作命令
[root@langfang src]# ./redis-cli flushall
OK
[root@langfang src]# ./redis-cli dbsize
(integer) 0
[root@langfang src]# 




10,--r表示產生的隨機鍵的數量,數量大可以模擬 鍵不命中情況
[root@langfang src]# ./redis-cli dbsize
(integer) 0
[root@langfang src]# ./redis-benchmark  -t set -r 8888 -n 100000
====== SET ======
  100000 requests completed in 1.61 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1


94.16% <= 1 milliseconds
99.93% <= 2 milliseconds
99.95% <= 3 milliseconds
100.00% <= 3 milliseconds
62305.30 requests per second




[root@langfang src]# ./redis-cli dbsize
(integer) 8888
[root@langfang src]# 




11,預設情況是處理1個請求然後順序接著處理下1個請求,但可以透過-P 管道技術,併發處理多個請求,下述效果非常明顯,成9倍左右的差異
(同時處理多條命令需要PIPELINE管道技術)


[root@langfang src]# ./redis-benchmark -t get,set -n 100000 -q
SET: 64516.13 requests per second
GET: 64516.13 requests per second






[root@langfang src]# ./redis-benchmark -t get,set -n 100000 -P 16 -q
SET: 452488.69 requests per second
GET: 529100.56 requests per second








來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-2153074/,如需轉載,請註明出處,否則將追究法律責任。

相關文章