1.中止redis (進入redis安裝目錄)
[root@JDu4e00u53f7 redis]# ./bin/redis-cli shutdown
2. 啓動redis
[root@JDu4e00u53f7 redis]# ./bin/redis-server /usr/local/redis/etc/redis.conf
3.使用redis
[root@JDu4e00u53f7 redis]# ./bin/redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> keys*
(error) ERR unknown command 'keys*'
127.0.0.1:6379>
4.redis的自帶的性能測試工具redis-benchmark
[root@JDu4e00u53f7 redis]# ./bin/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)
-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 2) 數據大小
-dbnum <db> SELECT the specified db number (default 0)
-k <boolean> 1=keep alive 0=reconnect (default 1) 是否採用keep alive模式
-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). 是否採用Pipeline模式請求,默認不採用
-e If server replies with errors, show them on stdout.
(no more than 1 error per second is displayed)
-q Quiet. Just show query/sec values 僅僅顯示查詢時間
--csv Output in CSV format 導出爲CSV格式
-l Loop. Run the tests forever 循環測試
-t <tests> Only run the comma separated list of tests. The test
names are the same as the ones produced as output.
-I Idle mode. Just open N idle connections and wait.
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.
實例:
指定測試項:
使用 pipelining
默認狀況下,每一個客戶端都是在一個請求完成以後才發送下一個請求 (benchmark 會模擬 50 個客戶端除非使用 -c 指定特別的數量), 這意味着服務器幾乎是按順序讀取每一個客戶端的命令。Also RTT is payed as well.
真實世界會更復雜,Redis 支持 /topics/pipelining,使得能夠一次性執行多條命令成爲可能。 Redis pipelining 能夠提升服務器的 TPS。 下面這個案例是在 Macbook air 11」 上使用 pipelining 組織 16 條命令的測試範例:
$ redis-benchmark -n 1000000 -t set,get -P 16 -q
SET: 403063.28 requests per second
GET: 508388.41 requests per second
記得在多條命令須要處理時候使用 pipelining
[root@JDu4e00u53f7 redis]# ./bin/redis-benchmark -q -n 100000
PING_INLINE: 76511.09 requests per second
PING_BULK: 79176.56 requests per second
SET: 46403.71 requests per second
GET: 47080.98 requests per second
INCR: 47014.57 requests per second
LPUSH: 50787.20 requests per second
RPUSH: 76745.97 requests per second
LPOP: 75131.48 requests per second
RPOP: 76452.60 requests per second
SADD: 77399.38 requests per second
SPOP: 79617.83 requests per second
LPUSH (needed to benchmark LRANGE): 76219.51 requests per second
LRANGE_100 (first 100 elements): 35868.00 requests per second
LRANGE_300 (first 300 elements): 15082.96 requests per second
LRANGE_500 (first 450 elements): 10714.67 requests per second
LRANGE_600 (first 600 elements): 8365.40 requests per second
MSET (10 keys): 62344.14 requests per second
[root@JDu4e00u53f7 redis]# ./bin/redis-benchmark -r 100000 -q -n 100000
PING_INLINE: 78988.94 requests per second
PING_BULK: 80971.66 requests per second
SET: 76394.20 requests per second
GET: 78125.00 requests per second
INCR: 77339.52 requests per second
LPUSH: 77220.08 requests per second
RPUSH: 77942.32 requests per second
LPOP: 76923.08 requests per second
RPOP: 78247.26 requests per second
SADD: 77041.60 requests per second
SPOP: 76745.97 requests per second
LPUSH (needed to benchmark LRANGE): 77101.00 requests per second
LRANGE_100 (first 100 elements): 36088.05 requests per second
LRANGE_300 (first 300 elements): 15015.02 requests per second
LRANGE_500 (first 450 elements): 10761.95 requests per second
LRANGE_600 (first 600 elements): 8385.74 requests per second
MSET (10 keys): 56465.27 requests per second
[root@JDu4e00u53f7 redis]# ./bin/redis-benchmark -c 100 -r 100000 -q -n 100000
PING_INLINE: 77459.34 requests per second
PING_BULK: 79113.92 requests per second
SET: 74738.41 requests per second
GET: 76687.12 requests per second
INCR: 75528.70 requests per second
LPUSH: 75872.54 requests per second
RPUSH: 76745.97 requests per second
LPOP: 75930.14 requests per second
RPOP: 76628.36 requests per second
SADD: 75585.79 requests per second
SPOP: 75414.78 requests per second
LPUSH (needed to benchmark LRANGE): 73367.57 requests per second
LRANGE_100 (first 100 elements): 36010.08 requests per second
LRANGE_300 (first 300 elements): 15021.78 requests per second
LRANGE_500 (first 450 elements): 10662.12 requests per second
LRANGE_600 (first 600 elements): 8308.41 requests per second
MSET (10 keys): 54854.64 requests per second
[root@JDu4e00u53f7 redis]# ./bin/redis-benchmark -r 100000 -q -n 100000 -P 16
PING_INLINE: 632911.38 requests per second
PING_BULK: 787401.56 requests per second
SET: 371747.22 requests per second
GET: 602409.69 requests per second
INCR: 571428.56 requests per second
LPUSH: 558659.19 requests per second
RPUSH: 606060.56 requests per second
LPOP: 558659.19 requests per second
RPOP: 606060.56 requests per second
SADD: 561797.75 requests per second
SPOP: 555555.56 requests per second
LPUSH (needed to benchmark LRANGE): 558659.19 requests per second
LRANGE_100 (first 100 elements): 61236.99 requests per second
LRANGE_300 (first 300 elements): 12853.47 requests per second
LRANGE_500 (first 450 elements): 7959.25 requests per second
LRANGE_600 (first 600 elements): 5845.56 requests per second
MSET (10 keys): 154083.20 requests per second