本文主要介绍及演示一些Redis相关的状态监控和性能调优的命令及使用方法:
1、redis-benchmark
redis基准信息,redis服务器性能检测
例如:
检测redis服务器性能,本机6379端口的实例,100个并发连接,100000个请求
redis-benchmark -h localhost -p -c -n
[root@redis-server ~]# redis-benchmark -h localhost -p -c -n
====== PING_INLINE ======
requests completed in 1.29 seconds
parallel clients
bytes payload
keep alive: 81.97% <= milliseconds
97.69% <= milliseconds
99.79% <= milliseconds
99.94% <= milliseconds
99.97% <= milliseconds
100.00% <= milliseconds
77639.75 requests per second ====== PING_BULK ======
requests completed in 1.49 seconds
parallel clients
bytes payload
keep alive: 73.04% <= milliseconds
97.46% <= milliseconds
99.62% <= milliseconds
99.97% <= milliseconds
100.00% <= milliseconds
100.00% <= milliseconds
67204.30 requests per second ====== SET ======
requests completed in 1.30 seconds
parallel clients
bytes payload
keep alive: 81.09% <= milliseconds
97.16% <= milliseconds
99.43% <= milliseconds
99.75% <= milliseconds
99.80% <= milliseconds
99.82% <= milliseconds
99.83% <= milliseconds
99.85% <= milliseconds
99.87% <= milliseconds
99.89% <= milliseconds
99.89% <= milliseconds
99.90% <= milliseconds
99.90% <= milliseconds
99.90% <= milliseconds
99.91% <= milliseconds
99.93% <= milliseconds
99.94% <= milliseconds
99.95% <= milliseconds
99.96% <= milliseconds
99.98% <= milliseconds
99.99% <= milliseconds
100.00% <= milliseconds
100.00% <= milliseconds
76687.12 requests per second ====== GET ======
requests completed in 1.91 seconds
parallel clients
bytes payload
keep alive: 49.74% <= milliseconds
93.92% <= milliseconds
99.37% <= milliseconds
99.95% <= milliseconds
99.97% <= milliseconds
99.98% <= milliseconds
100.00% <= milliseconds
52273.91 requests per second ====== INCR ======
requests completed in 1.60 seconds
parallel clients
bytes payload
keep alive: 66.32% <= milliseconds
96.55% <= milliseconds
99.61% <= milliseconds
99.96% <= milliseconds
100.00% <= milliseconds
62344.14 requests per second ====== LPUSH ======
requests completed in 1.27 seconds
parallel clients
bytes payload
keep alive: 73.84% <= milliseconds
95.61% <= milliseconds
99.36% <= milliseconds
99.96% <= milliseconds
99.99% <= milliseconds
100.00% <= milliseconds
78492.93 requests per second ====== RPUSH ======
requests completed in 1.31 seconds
parallel clients
bytes payload
keep alive: 80.47% <= milliseconds
96.93% <= milliseconds
99.56% <= milliseconds
99.98% <= milliseconds
100.00% <= milliseconds
100.00% <= milliseconds
76103.50 requests per second ====== LPOP ======
requests completed in 1.30 seconds
parallel clients
bytes payload
keep alive: 74.91% <= milliseconds
95.50% <= milliseconds
99.29% <= milliseconds
99.95% <= milliseconds
100.00% <= milliseconds
100.00% <= milliseconds
77101.00 requests per second ====== RPOP ======
requests completed in 1.40 seconds
parallel clients
bytes payload
keep alive: 77.99% <= milliseconds
97.07% <= milliseconds
99.61% <= milliseconds
99.97% <= milliseconds
99.98% <= milliseconds
100.00% <= milliseconds
100.00% <= milliseconds
71377.59 requests per second ====== SADD ======
requests completed in 1.32 seconds
parallel clients
bytes payload
keep alive: 80.83% <= milliseconds
97.14% <= milliseconds
99.57% <= milliseconds
99.95% <= milliseconds
100.00% <= milliseconds
100.00% <= milliseconds
75757.57 requests per second ====== HSET ======
requests completed in 1.30 seconds
parallel clients
bytes payload
keep alive: 80.25% <= milliseconds
96.83% <= milliseconds
99.49% <= milliseconds
99.97% <= milliseconds
100.00% <= milliseconds
76923.08 requests per second ====== SPOP ======
requests completed in 1.48 seconds
parallel clients
bytes payload
keep alive: 73.97% <= milliseconds
96.91% <= milliseconds
99.55% <= milliseconds
99.96% <= milliseconds
100.00% <= milliseconds
100.00% <= milliseconds
67567.57 requests per second ====== LPUSH (needed to benchmark LRANGE) ======
requests completed in 1.35 seconds
parallel clients
bytes payload
keep alive: 71.03% <= milliseconds
95.36% <= milliseconds
99.29% <= milliseconds
99.97% <= milliseconds
100.00% <= milliseconds
100.00% <= milliseconds
73909.83 requests per second ====== LRANGE_100 (first elements) ======
requests completed in 2.91 seconds
parallel clients
bytes payload
keep alive: 14.30% <= milliseconds
80.30% <= milliseconds
94.42% <= milliseconds
96.88% <= milliseconds
98.34% <= milliseconds
99.39% <= milliseconds
99.78% <= milliseconds
99.93% <= milliseconds
99.97% <= milliseconds
99.98% <= milliseconds
100.00% <= milliseconds
100.00% <= milliseconds
34317.09 requests per second ====== LRANGE_300 (first elements) ======
requests completed in 5.88 seconds
parallel clients
bytes payload
keep alive: 0.00% <= milliseconds
85.83% <= milliseconds
94.17% <= milliseconds
96.10% <= milliseconds
97.90% <= milliseconds
98.68% <= milliseconds
98.70% <= milliseconds
99.30% <= milliseconds
99.49% <= milliseconds
99.76% <= milliseconds
99.79% <= milliseconds
99.83% <= milliseconds
99.85% <= milliseconds
99.87% <= milliseconds
99.89% <= milliseconds
99.91% <= milliseconds
99.92% <= milliseconds
99.93% <= milliseconds
99.94% <= milliseconds
99.95% <= milliseconds
99.96% <= milliseconds
99.97% <= milliseconds
99.99% <= milliseconds
99.99% <= milliseconds
100.00% <= milliseconds
17006.80 requests per second ====== LRANGE_500 (first elements) ======
requests completed in 8.16 seconds
parallel clients
bytes payload
keep alive: 0.00% <= milliseconds
0.01% <= milliseconds
80.98% <= milliseconds
90.89% <= milliseconds
95.60% <= milliseconds
97.20% <= milliseconds
98.23% <= milliseconds
98.53% <= milliseconds
99.06% <= milliseconds
99.09% <= milliseconds
99.46% <= milliseconds
99.53% <= milliseconds
99.65% <= milliseconds
99.75% <= milliseconds
99.79% <= milliseconds
99.81% <= milliseconds
99.82% <= milliseconds
99.84% <= milliseconds
99.85% <= milliseconds
99.86% <= milliseconds
99.87% <= milliseconds
99.88% <= milliseconds
99.89% <= milliseconds
99.90% <= milliseconds
99.91% <= milliseconds
99.93% <= milliseconds
99.93% <= milliseconds
99.94% <= milliseconds
99.95% <= milliseconds
99.96% <= milliseconds
99.98% <= milliseconds
99.98% <= milliseconds
99.99% <= milliseconds
99.99% <= milliseconds
100.00% <= milliseconds
100.00% <= milliseconds
12260.91 requests per second ====== LRANGE_600 (first elements) ======
requests completed in 10.15 seconds
parallel clients
bytes payload
keep alive: 0.00% <= milliseconds
0.01% <= milliseconds
84.84% <= milliseconds
93.41% <= milliseconds
96.43% <= milliseconds
97.71% <= milliseconds
97.75% <= milliseconds
98.32% <= milliseconds
98.79% <= milliseconds
99.19% <= milliseconds
99.22% <= milliseconds
99.25% <= milliseconds
99.48% <= milliseconds
99.56% <= milliseconds
99.60% <= milliseconds
99.68% <= milliseconds
99.74% <= milliseconds
99.77% <= milliseconds
99.79% <= milliseconds
99.82% <= milliseconds
99.83% <= milliseconds
99.85% <= milliseconds
99.86% <= milliseconds
99.86% <= milliseconds
99.87% <= milliseconds
99.88% <= milliseconds
99.89% <= milliseconds
99.90% <= milliseconds
99.90% <= milliseconds
99.91% <= milliseconds
99.91% <= milliseconds
99.92% <= milliseconds
99.94% <= milliseconds
99.95% <= milliseconds
99.95% <= milliseconds
99.96% <= milliseconds
99.96% <= milliseconds
99.96% <= milliseconds
99.97% <= milliseconds
99.98% <= milliseconds
99.98% <= milliseconds
99.99% <= milliseconds
99.99% <= milliseconds
99.99% <= milliseconds
100.00% <= milliseconds
100.00% <= milliseconds
9851.25 requests per second ====== MSET ( keys) ======
requests completed in 1.89 seconds
parallel clients
bytes payload
keep alive: 0.00% <= milliseconds
75.00% <= milliseconds
89.85% <= milliseconds
95.38% <= milliseconds
98.52% <= milliseconds
99.34% <= milliseconds
99.60% <= milliseconds
99.83% <= milliseconds
99.98% <= milliseconds
100.00% <= milliseconds
52994.17 requests per second [root@redis-server ~]#
2、redis-cli
例1:监控本机6379端口的实例的数据操作,redis的连接及读写操作
redis-cli -h localhost -p monitor
先开启一个终端1,用于redis监控
[root@redis-server ~]# redis-cli -h localhost -p monitor
OK
1504689350.635365 [ 127.0.0.1:] "COMMAND"
1504689361.944610 [ 127.0.0.1:] "set" "a" ""
1504689369.782029 [ 127.0.0.1:] "get" "a"
然后在开启一个redis终端2进行操作
[root@redis-server ~]# redis-cli -p
127.0.0.1:> set a
OK
127.0.0.1:> get a
""
127.0.0.1:>
可以看到终端2上面进行的数据操作会在终端1上面被记录下来
例2:查询本机redis实例的信息,端口6379
redis-cli -h localhost -p info
备注:该命令也可以在redis终端里面进行查询
[root@redis-server ~]# redis-cli -h localhost -p info
# Server
redis_version:3.2.
redis_git_sha1:
redis_git_dirty:
redis_build_id:eae5a0b8746eb6ce
redis_mode:standalone
os:Linux 2.6.-.el6.x86_64 x86_64
arch_bits:
multiplexing_api:epoll
gcc_version:4.4.
process_id:
run_id:0057d03b2e908ee036c2aa1c3531e8aa051d7468
tcp_port:
uptime_in_seconds:
uptime_in_days:
hz:
lru_clock:
executable:/usr/local/redis/bin/redis-server
config_file:/usr/local/redis/conf/redis.conf # Clients
connected_clients:
client_longest_output_list:
client_biggest_input_buf:
blocked_clients: # Memory
used_memory:
used_memory_human:1.74M
used_memory_rss:
used_memory_rss_human:3.86M
used_memory_peak:
used_memory_peak_human:8.05M
total_system_memory:
total_system_memory_human:.83G
used_memory_lua:
used_memory_lua_human:.00K
maxmemory:
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:2.22
mem_allocator:jemalloc-4.0. # Persistence
loading:
rdb_changes_since_last_save:
rdb_bgsave_in_progress:
rdb_last_save_time:
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:
rdb_current_bgsave_time_sec:-
aof_enabled:
aof_rewrite_in_progress:
aof_rewrite_scheduled:
aof_last_rewrite_time_sec:-
aof_current_rewrite_time_sec:-
aof_last_bgrewrite_status:ok
aof_last_write_status:ok # Stats
total_connections_received:
total_commands_processed:
instantaneous_ops_per_sec:
total_net_input_bytes:
total_net_output_bytes:
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:
sync_full:
sync_partial_ok:
sync_partial_err:
expired_keys:
evicted_keys:
keyspace_hits:
keyspace_misses:
pubsub_channels:
pubsub_patterns:
latest_fork_usec:
migrate_cached_sockets: # Replication
role:master
connected_slaves:
master_repl_offset:
repl_backlog_active:
repl_backlog_size:
repl_backlog_first_byte_offset:
repl_backlog_histlen: # CPU
used_cpu_sys:99.45
used_cpu_user:108.88
used_cpu_sys_children:0.01
used_cpu_user_children:0.01 # Cluster
cluster_enabled: # Keyspace
db0:keys=,expires=,avg_ttl=
[root@redis-server ~]#
# 完毕,呵呵呵