文章目录
1.查看性能
1)查看实例60秒内最大响应延迟
redis-cli -h 127.0.0.1 -p 6379 --intrinsic-latency 60
//
963552652 total runs (avg latency: 0.0623 microseconds / 62.27 nanoseconds per run).
Worst run took 31042x longer than the average latency.
//最大延迟为1.933ms,当该redis实例的运行时延为2ms,不算性能变慢
Max latency so far: 1 microseconds.
Max latency so far: 3 microseconds.
Max latency so far: 5 microseconds.
Max latency so far: 17 microseconds.
Max latency so far: 38 microseconds.
Max latency so far: 50 microseconds.
Max latency so far: 54 microseconds.
Max latency so far: 439 microseconds.
Max latency so far: 518 microseconds.
Max latency so far: 943 microseconds.
Max latency so far: 1172 microseconds.
Max latency so far: 1933 microseconds.
2)查看一段时间内redis的最小、最大、平均访问延迟
redis-cli -h 127.0.0.1 -p 6379 --latency-history -i 1
//平均访问延迟为0.06到0.12
min: 0, max: 1, avg: 0.04 (98 samples) -- 1.01 seconds range
min: 0, max: 1, avg: 0.06 (98 samples) -- 1.01 seconds range
min: 0, max: 1, avg: 0.07 (98 samples) -- 1.01 seconds range
min: 0, max: 1, avg: 0.04 (98 samples) -- 1.01 seconds range
min: 0, max: 1, avg: 0.06 (97 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.07 (98 samples) -- 1.01 seconds range
min: 0, max: 1, avg: 0.10 (98 samples) -- 1.01 seconds range
min: 0, max: 1, avg: 0.06 (98 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.09 (97 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.11 (97 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.12 (98 samples) -- 1.01 seconds range
min: 0, max: 1, avg: 0.07 (98 samples) -- 1.01 seconds range
min: 0, max: 1, avg: 0.06 (97 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.06 (98 samples) -- 1.01 seconds range
min: 0, max: 1, avg: 0.07 (97 samples) -- 1.00 seconds range
min: 0, max: 1, avg: 0.06 (98 samples) -- 1.00 seconds range
//Redis-cli --latency -h 127.0.0.1 -p 6379
min: 0, max: 1, avg: 0.07 (4590 samples) #访问延迟时间为70us
3)精简测试:看每秒set/get/incr命令在redis的操作效率
redis-benchmark -t set,get,incr -n 1000000 -q
- 通过 -t 参数,设置仅仅测试 SET/GET/INCR 命令
- 通过 -n 参数,设置每个测试执行 1000000 次操作。
- 通过 -q 参数,设置精简输出结果
//
SET: 53908.36 requests per second //每秒完成5W3数量的set请求的qps
GET: 54755.52 requests per second //
INCR: 54513.74 requests per second //
4)pipeline测试(通过 Redis pipeline 功能,批量提交命令给 Redis Server ,从而提升性能)
redis-benchmark -t set,get,incr -n 1000000 -q -P 10
- 通过 -P 参数,设置每个 pipeline 执行 10 次 Redis 命令。
//执行效果
SET: 452939.31 requests per second
GET: 537827.94 requests per second
INCR: 502765.22 requests per second
5)快速测试:用redis-benchmark测试redis性能
- redis-benchmark参数
以下参数被支持:
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)
-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).
-q Quiet. Just show query/sec values
--csv Output in CSV format
-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.
- 如果仔细观察,有效载荷大小是 3 个字节。这是默认设置,您可以使用-d参数进行自定义。以下测试针对 100k 请求,负载为 1mb。
(1Mb)
root@gf-lab:~# redis-benchmark -h 127.0.0.1 -p 6379 -n 100000 -d 1000000
====== PING_INLINE ======
100000 requests completed in 2.80 seconds
50 parallel clients
1000000 bytes payload
keep alive: 1
73.19% <= 1 milliseconds
99.95% <= 2 milliseconds
100.00% <= 2 milliseconds
35676.06 requests per second
redis-benchmark
//输出效果
====== PING_INLINE ======
100000 requests completed in 1.93 seconds //十万请求用1.93秒完成
50 parallel clients //50个客户端
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no //单线程
0.00% <= 0.1 milliseconds
2.93% <= 0.2 milliseconds
17.21% <= 0.3 milliseconds
33.84% <= 0.4 milliseconds
50.86% <= 0.5 milliseconds
68.00% <= 0.6 milliseconds
84.21% <= 0.7 milliseconds
94.67% <= 0.8 milliseconds
98.00% <= 0.9 milliseconds
99.02% <= 1.0 milliseconds
99.45% <= 1.1 milliseconds
99.66% <= 1.2 milliseconds
99.83% <= 1.3 milliseconds
99.90% <= 1.4 milliseconds
99.92% <= 1.5 milliseconds
99.94% <= 1.6 milliseconds
99.96% <= 1.7 milliseconds
99.97% <= 1.8 milliseconds
99.98% <= 1.9 milliseconds
99.98% <= 2 milliseconds
100.00% <= 2 milliseconds
51786.64 requests per second //5.2w的qps/s
====== PING_BULK ======
100000 requests completed in 1.93 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
99.10% <= 1 milliseconds
99.92% <= 2 milliseconds
99.98% <= 3 milliseconds
100.00% <= 3 milliseconds
51894.13 requests per second
====== SET ======
100000 requests completed in 1.94 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
98.72% <= 1 milliseconds
99.94% <= 2 milliseconds
99.98% <= 3 milliseconds
100.00% <= 3 milliseconds
51440.33 requests per second
====== GET ======
100000 requests completed in 1.96 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
98.86% <= 1 milliseconds
99.97% <= 2 milliseconds
99.99% <= 3 milliseconds
100.00% <= 3 milliseconds
51150.89 requests per second
====== INCR ======
100000 requests completed in 1.96 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
98.73% <= 1 milliseconds
99.96% <= 2 milliseconds
100.00% <= 3 milliseconds
100.00% <= 3 milliseconds
51150.89 requests per second
====== LPUSH ======
100000 requests completed in 1.96 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
98.13% <= 1 milliseconds
99.97% <= 2 milliseconds
100.00% <= 3 milliseconds
51072.52 requests per second
====== RPUSH ======
100000 requests completed in 1.89 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
99.38% <= 1 milliseconds
99.96% <= 2 milliseconds
99.99% <= 3 milliseconds
100.00% <= 3 milliseconds
53022.27 requests per second
====== LPOP ======
100000 requests completed in 2.08 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
94.68% <= 1 milliseconds
99.92% <= 2 milliseconds
100.00% <= 3 milliseconds
48169.56 requests per second
====== RPOP ======
100000 requests completed in 1.90 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
99.25% <= 1 milliseconds
99.96% <= 2 milliseconds
99.98% <= 3 milliseconds
100.00% <= 3 milliseconds
52742.62 requests per second
====== SADD ======
100000 requests completed in 1.91 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
99.38% <= 1 milliseconds
99.94% <= 2 milliseconds
100.00% <= 2 milliseconds
52465.90 requests per second
====== HSET ======
100000 requests completed in 1.90 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
99.22% <= 1 milliseconds
99.98% <= 2 milliseconds
100.00% <= 2 milliseconds
52659.29 requests per second
====== SPOP ======
100000 requests completed in 1.90 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
99.55% <= 1 milliseconds
99.94% <= 2 milliseconds
99.97% <= 3 milliseconds
100.00% <= 3 milliseconds
52742.62 requests per second
====== ZADD ======
100000 requests completed in 1.92 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
98.86% <= 1 milliseconds
99.94% <= 2 milliseconds
99.97% <= 3 milliseconds
100.00% <= 3 milliseconds
52137.64 requests per second
====== ZPOPMIN ======
100000 requests completed in 1.91 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
99.28% <= 1 milliseconds
99.94% <= 2 milliseconds
100.00% <= 3 milliseconds
100.00% <= 3 milliseconds
52246.60 requests per second
====== LPUSH (needed to benchmark LRANGE) ======
100000 requests completed in 1.91 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
98.91% <= 1 milliseconds
99.96% <= 2 milliseconds
100.00% <= 2 milliseconds
52465.90 requests per second
====== LRANGE_100 (first 100 elements) ======
100000 requests completed in 3.08 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
89.35% <= 1 milliseconds
99.89% <= 2 milliseconds
99.99% <= 3 milliseconds
100.00% <= 3 milliseconds
32467.53 requests per second
====== LRANGE_300 (first 300 elements) ======
100000 requests completed in 6.28 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
0.00% <= 1 milliseconds
93.42% <= 2 milliseconds
99.83% <= 3 milliseconds
100.00% <= 4 milliseconds
100.00% <= 4 milliseconds
15915.96 requests per second
====== LRANGE_500 (first 450 elements) ======
100000 requests completed in 9.32 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
0.00% <= 1 milliseconds
35.27% <= 2 milliseconds
82.62% <= 3 milliseconds
99.39% <= 4 milliseconds
99.97% <= 5 milliseconds
100.00% <= 5 milliseconds
10730.76 requests per second
====== LRANGE_600 (first 600 elements) ======
100000 requests completed in 10.62 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
0.00% <= 1 milliseconds
0.01% <= 2 milliseconds
91.79% <= 3 milliseconds
98.37% <= 4 milliseconds
99.76% <= 5 milliseconds
99.98% <= 6 milliseconds
99.99% <= 7 milliseconds
100.00% <= 7 milliseconds
9411.76 requests per second
====== MSET (10 keys) ======
100000 requests completed in 1.87 seconds
50 parallel clients
3 bytes payload
keep alive: 1
host configuration "save": 900 1 300 10 60 10000
host configuration "appendonly": no
multi-thread: no
96.90% <= 1 milliseconds
99.92% <= 2 milliseconds
99.95% <= 3 milliseconds
100.00% <= 3 milliseconds
53619.30 requests per second
6)随机key测试redis性能
未使用随机key
root@iZbp1do67v9l7zwkcs2b22Z:~/redis-6.0.8/src# redis-benchmark -t set -n 1000 -q
SET: 47619.05 requests per second
使用随机key
root@iZbp1do67v9l7zwkcs2b22Z:~/redis-6.0.8/src# redis-benchmark -t set -n 1000 -q -r 10
SET: 45454.55 requests per second
2.redis监控
1)Ping 判断客户端和服务器连接是否正常
返回Pong就表示连接正常
2)redis-cli info 获得 Redis 系统的状态报告:包括服务器、客户端、内存、持久化、主从复制、CPU集群情况
root@iZbp1do67v9l7zwkcs2b22Z:~/projects/Project1# redis-cli info
#服务器
# Server
redis_version:6.0.8 # redis版本
redis_git_sha1:00000000 # git上版本
redis_git_dirty:0 # git的版本是否修改
redis_build_id:f9f1fed6697271fc # 编译时id
redis_mode:standalone # redis运行模式
os:Linux 4.15.0-135-generic x86_64 # 服务器宿主操作系统
arch_bits:64 # 架构是64位的
multiplexing_api:epoll # redis基于epoll模型
atomicvar_api:atomic-builtin
gcc_version:7.5.0 # 编译redis的gcc版本
process_id:518 # 当前redis服务器进程id
run_id:974027d18c83c7ded724cf6c48068a0f634ca3cb # redis的随机标识符(用于 Sentinel 和集群)
tcp_port:6379 # redis的tcp端口
uptime_in_seconds:189856 # 运行时间(单位:秒)
uptime_in_days:2 # 运行时间(单位:天)
hz:10
configured_hz:10
lru_clock:587530 # 以分钟为单位进行自增的时钟,用于LRU管理
executable:/usr/local/bin/redis-server #
config_file:/etc/redis/6379.conf # 配置文件
io_threads_active:0
#客户端
# Clients
connected_clients:1 #连接的客户端数量,Redis默认允许客户端连接的最大数量是10000。若是看到连接数超过5000以上,那可能会影响Redis的性能,已连接客户端的数量(不包括通过从属服务器连接的客户端)
client_recent_max_input_buffer:2
client_recent_max_output_buffer:0
blocked_clients:0 # ##正在等待阻塞命令(BLPOP、BRPOP、BRPOPLPUSH)的客户端的数量
tracking_clients:0
clients_in_timeout_table:0
#内存
# Memory
used_memory:1370688 # redis使用的内存总量,由 Redis 分配器分配的内存总量,以字节(byte)为单位
used_memory_human:1.31M # 由Redis分配的内存的总量,单位G或M给人看的
used_memory_rss:5423104 # redis分配的内存总量(包括内存碎片),从操作系统上显示已经分配的内存总量
used_memory_rss_human:5.17M # redis进程从OS角度分配的物理内存,如key被删除后,malloc不一定把内存归还给OS,但可以Redis进程复用,代表redis使用的总内存,给人看的
used_memory_peak:17340992 # Redis使用内存的峰值,字节数 给机器看的
used_memory_peak_human:16.54M # redis所用内存的高峰值
used_memory_peak_perc:7.90%
used_memory_overhead:803744
used_memory_startup:803056
used_memory_dataset:566944
used_memory_dataset_perc:99.88%
allocator_allocated:1460800
allocator_active:1806336
allocator_resident:4194304
total_system_memory:2004525056
total_system_memory_human:1.87G
used_memory_lua:37888 #Lua脚本引擎所使用的内存大小。
used_memory_lua_human:37.00K
used_memory_scripts:0
used_memory_scripts_human:0B
number_of_cached_scripts:0
maxmemory:0 # redis可以使用的最大的内存,字节数,给机器看的
maxmemory_human:0B # redis可以使用的最大的内存,给人看的
maxmemory_policy:noeviction # 设置删除key的规则(有6种
# allkeys-lru:不管 key 是否设置了过期,淘汰最近最少访问的
# keyvolatile-lru:只淘汰最近最少访问、并设置了过期时间的
# keyallkeys-random:不管 key 是否设置了过期,随机淘汰
# keyvolatile-random:只随机淘汰设置了过期时间的
# keyallkeys-ttl:不管 key 是否设置了过期,淘汰即将过期的
# keynoeviction:不淘汰任何 key,实例内存达到
# maxmeory 后,再写入新数据直接返回错误
# allkeys-lfu:不管 key 是否设置了过期,淘汰访问频率最低的 key(4.0+版本支持)
# volatile-lfu:只淘汰访问频率最低、并设置了过期时间 key(4.0+版本支持)
allocator_frag_ratio:1.24
allocator_frag_bytes:345536
allocator_rss_ratio:2.32
allocator_rss_bytes:2387968
rss_overhead_ratio:1.29
rss_overhead_bytes:1228800
mem_fragmentation_ratio:4.15 #内存碎片比率
mem_fragmentation_bytes:4115872
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:0
mem_aof_buffer:0
mem_allocator:jemalloc-5.1.0 # 在编译时指定的Redis使用的内存分配器,可以是libc、jemalloc、tcmalloc,Redis内存管理器
active_defrag_running:0
lazyfree_pending_objects:0
# Persistence
loading:0 # 是否加载rdb文件,标志位,是否在载入数据文件,0代表没有,1代表正在载入
rdb_changes_since_last_save:0 # 上次保存数据库后,执行命令的次数;从最近一次dump快照后,未被dump的变更次数(和save里变更计数器类似)
rdb_bgsave_in_progress:0 # 标志位,记录当前是否在后台创建RDB快照保存任务
rdb_last_save_time:1627962982 # 最后一次成功rdb保存任务的时间点,以unix时间戳格式显示
rdb_last_bgsave_status:ok # 标志位,记录最近一次bgsave操作是否创建成功
rdb_last_bgsave_time_sec:0
rdb_current_bgsave_time_sec:-1 # 如果当前正在执行rdb保存任务,则为当前rdb任务已经消耗的时间,否则为-1
rdb_last_cow_size:421888 # 最后一次执行rdb保存任务消耗的内存
aof_enabled:0 # 0表示没开aof持久化,1表示开启aof持久化
aof_rewrite_in_progress:0 # 最近一次bgsave操作耗时秒数
aof_rewrite_scheduled:0 # 是否等待调度一次aof重写任务,如果触发了一次aof重写,但是后台正在执行rdb保存任务时会将该状态置为1
aof_last_rewrite_time_sec:-1 # 上次bgsave执行耗时秒数(-1 还没有执行)
aof_current_rewrite_time_sec:-1 #
aof_last_bgrewrite_status:ok # 最后一次执行aof缓冲区写入的状态
aof_last_write_status:ok
aof_last_cow_size:0
module_fork_in_progress:0
module_fork_last_cow_size:0
# Stats
total_connections_received:5535 # 运行以来连接过的客户端的总数量
total_commands_processed:41388572 # 运行以来执行过的命令的总数量
instantaneous_ops_per_sec:0 # 服务器每秒钟执行的命令数量
total_net_input_bytes:1975641730 # Redis每秒网络输入的字节数
total_net_output_bytes:3080132453 # Redis每秒网络输出的字节数
instantaneous_input_kbps:0.00 # 瞬间的Redis输入网络流量(kbps)
instantaneous_output_kbps:0.00 # 瞬间的Redis输出网络流量(kbps)
rejected_connections:0 # 因连接数达到maxclients上限后,被拒绝的连接个数
sync_full:0 # --累计Master full sync的次数;如果值比较大,说明常常出现全量复制,就得分析原因,或调整repl-backlog-size
sync_partial_ok:0 # 累计Master psync成功的次数
sync_partial_err:0 # 累计Master pysync 出错失败的次数
expired_keys:0 # 运行以来过期的 key 的数量
expired_stale_perc:0.00
expired_time_cap_reached_count:0 #
expire_cycle_cpu_milliseconds:2802 # 因为过期而被自动删除的数据库键数量
evicted_keys:0 # 运行以来删除过的key的数量,因内存used_memory达到maxmemory后,每秒被驱逐的key个数
keyspace_hits:12836252 # 查找键命中的次数
keyspace_misses:4 # 查找键未命中的次数
pubsub_channels:0 # 目前被订阅的频道数量
pubsub_patterns:0 # 目前被订阅的模式数量
latest_fork_usec:270 # --最近一次fork操作的耗时的微秒数(BGREWRITEAOF,BGSAVE,SYNC等都会触发fork),当并发场景fork耗时过长对服务影响较大
migrate_cached_sockets:0 # 迁移缓存的套接字
slave_expires_tracked_keys:0
active_defrag_hits:0
active_defrag_misses:0
active_defrag_key_hits:0
active_defrag_key_misses:0
tracking_total_keys:0
tracking_total_items:0
tracking_total_prefixes:0
unexpected_error_replies:0
total_reads_processed:13512707
total_writes_processed:13497119
io_threaded_reads_processed:0
io_threaded_writes_processed:0
# Replication
role:master # 当前Redis的主从状态,实例的角色master还是slave
connected_slaves:0 # 下面有几个slave
master_replid:3b2930656714d49b6aef2493905397c11e83e5b4
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0 # master复制的偏移量、
second_repl_offset:-1
repl_backlog_active:0 # 标志位,master是否开启了repl_backlog,有效地psync(2.8+)
repl_backlog_size:1048576 # --repl_backlog的长度(repl-backlog-size),网络环境不稳定的,建议调整大些。(主从之间如何网络延时过大可以调整此参数,避免重复的触发全量同步)
repl_backlog_first_byte_offset:0 # repl_backlog中首字节的复制偏移位
repl_backlog_histlen:0 # repl_backlog当前使用的字节数
# CPU
used_cpu_sys:163.911361 # Redis进程消耗的sys cpu
used_cpu_user:176.846898 # Redis进程消耗的user cpu
used_cpu_sys_children:0.006340 # 后台进程耗费的系统 CPU
used_cpu_user_children:0.014579 # 后台进程耗费的用户 CPU
# Modules
# Cluster
cluster_enabled:0 # #从服务
# Keyspace
db0:keys=14,expires=0,avg_ttl=0 # 各个数据库的 key 的数量,以及带有生存期的 key 的数量