Linux下停止和启动redis

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


 

猜你喜欢

转载自my.oschina.net/u/2494575/blog/1814771