http://www.4wei.cn/archives/1002605
http://redis.io/commands/INFO
info命令
# Memory
used_memory:11570933696
used_memory_human:10.78G
used_memory_rss:11895382016
used_memory_peak:12194989280
used_memory_peak_human:11.36G
used_memory_lua:33792
mem_fragmentation_ratio:1.03
mem_allocator:jemalloc-3.2.0
used_memory:
实际缓存占用的内存和Redis自身运行所占用的内存(如元数据、lua)
它是由Redis使用内存分配器分配的内存,所以这个数据并没有把内存碎片浪费掉的内存给统计进去
total number of bytes allocated by Redis using its allocator (either standard libc, jemalloc, or an alternative allocator such as tcmalloc
如果used_memory大于物理内存,表明系统使用了swap交换
used_memory_rss:
操作系统上显示已经分配的内存总量, 包括碎片
Number of bytes that Redis allocated as seen by the operating system (a.k.a resident set size). This is the number reported by tools such as top(1) and ps(1)
mem_fragmentation_ratio=used_memory_rss/used_memory
内存碎片率稍大于1是合理的,这个值表示内存碎片率比较低,也说明redis没有发生内存交换。
但如果内存碎片率超过1.5,那就说明Redis消耗了实际需要物理内存的150%,其中50%是内存碎片率
若是内存碎片率低于1的话,说明Redis内存分配超出了物理内存,操作系统正在进行内存交换。内存交换会引起非常明显的响应延迟
重置redis计数器.
CONFIG RESETSTAT
http://redisdoc.com/server/config_resetstat.html
重置 INFO 命令中的某些统计数据,包括:
Keyspace hits (键空间命中次数)
Keyspace misses (键空间不命中次数)
Number of commands processed (执行命令的次数)
Number of connections received (连接服务器的次数)
Number of expired keys (过期key的数量)
Number of rejected connections (被拒绝的连接数量)
Latest fork(2) time(最后执行 fork(2) 的时间)
The aof_delayed_fsync counter(aof_delayed_fsync 计数器的值)
Bigkeys
持续采样,实时输出当时得到的 value 占用空间最大的 key
./redis-cli --bigkeys
# Scanning the entire keyspace to find biggest keys as well as
# average sizes per key type. You can use -i 0.1 to sleep 0.1 sec
# per 100 SCAN commands (not usually needed).
[00.00%] Biggest string found so far 'A' with 110 bytes
[00.00%] Biggest string found so far 'B' with 111 bytes
[00.00%] Biggest string found so far 'C' with 137 bytes
......
-------- summary -------
Sampled 860830 keys in the keyspace!
Total key length in bytes is 43384761 (avg len 50.40)
Biggest string found 'X' has 194 bytes
860830 strings with 96957492 bytes (100.00% of keys, avg size 112.63)
0 lists with 0 items (00.00% of keys, avg size 0.00)
0 sets with 0 members (00.00% of keys, avg size 0.00)
0 hashs with 0 fields (00.00% of keys, avg size 0.00)
0 zsets with 0 members (00.00% of keys, avg size 0.00)
命令统计(配合重置计数器)
./redis-cli info commandstats
# Commandstats
cmdstat_set:calls=78911,usec=558105,usec_per_call=7.07
cmdstat_setex:calls=292806,usec=2172915,usec_per_call=7.42
cmdstat_strlen:calls=860830,usec=1195826,usec_per_call=1.39
cmdstat_del:calls=35035,usec=132577,usec_per_call=3.78
cmdstat_incr:calls=12417,usec=39987,usec_per_call=3.22
cmdstat_lpush:calls=68806,usec=301346,usec_per_call=4.38
cmdstat_ltrim:calls=12024,usec=56763,usec_per_call=4.72
cmdstat_lrem:calls=55246,usec=568687,usec_per_call=10.29
cmdstat_zadd:calls=450,usec=6991,usec_per_call=15.54
cmdstat_zremrangebyscore:calls=93,usec=1153,usec_per_call=12.40
cmdstat_zremrangebyrank:calls=272,usec=2586,usec_per_call=9.51
cmdstat_hset:calls=753,usec=5235,usec_per_call=6.95
cmdstat_hdel:calls=379,usec=2173,usec_per_call=5.73
cmdstat_incrby:calls=5034,usec=18849,usec_per_call=3.74
cmdstat_select:calls=195364,usec=174016,usec_per_call=0.89
cmdstat_expire:calls=13775,usec=41087,usec_per_call=2.98
cmdstat_scan:calls=82681,usec=2272315,usec_per_call=27.48
cmdstat_dbsize:calls=1,usec=2,usec_per_call=2.00
cmdstat_auth:calls=7,usec=14,usec_per_call=2.00
cmdstat_ping:calls=6305,usec=14882,usec_per_call=2.36
cmdstat_type:calls=860830,usec=1246794,usec_per_call=1.45
cmdstat_multi:calls=2524,usec=669,usec_per_call=0.27
cmdstat_exec:calls=2524,usec=5888,usec_per_call=2.33
cmdstat_info:calls=607,usec=44198,usec_per_call=72.81
cmdstat_config:calls=1,usec=20836,usec_per_call=20836.00
cmdstat_subscribe:calls=3,usec=9,usec_per_call=3.00
cmdstat_publish:calls=5748,usec=53970,usec_per_call=9.39
cmdstat_client:calls=3,usec=5,usec_per_call=1.67
调试.查看Redis执行的所有命令.
./redis-cli monitor
内存占用分析
yum install python-pip
pip install rdbtools
rdb -c memory dump.rdb > memory.csv
优化与禁忌
解决保存快照失败后redis无法写入的问题
>config set stop-writes-on-bgsave-error no
定期日志重写,减小aof重载时的时间开销
>auto-aof-rewrite-percentage 100
>auto-aof-rewrite-min-size 64mb
使用scan ... MATCH .. 代替 keys *
http://redis.io/commands/INFO
info命令
# Memory
used_memory:11570933696
used_memory_human:10.78G
used_memory_rss:11895382016
used_memory_peak:12194989280
used_memory_peak_human:11.36G
used_memory_lua:33792
mem_fragmentation_ratio:1.03
mem_allocator:jemalloc-3.2.0
used_memory:
实际缓存占用的内存和Redis自身运行所占用的内存(如元数据、lua)
它是由Redis使用内存分配器分配的内存,所以这个数据并没有把内存碎片浪费掉的内存给统计进去
total number of bytes allocated by Redis using its allocator (either standard libc, jemalloc, or an alternative allocator such as tcmalloc
如果used_memory大于物理内存,表明系统使用了swap交换
used_memory_rss:
操作系统上显示已经分配的内存总量, 包括碎片
Number of bytes that Redis allocated as seen by the operating system (a.k.a resident set size). This is the number reported by tools such as top(1) and ps(1)
mem_fragmentation_ratio=used_memory_rss/used_memory
内存碎片率稍大于1是合理的,这个值表示内存碎片率比较低,也说明redis没有发生内存交换。
但如果内存碎片率超过1.5,那就说明Redis消耗了实际需要物理内存的150%,其中50%是内存碎片率
若是内存碎片率低于1的话,说明Redis内存分配超出了物理内存,操作系统正在进行内存交换。内存交换会引起非常明显的响应延迟
重置redis计数器.
CONFIG RESETSTAT
http://redisdoc.com/server/config_resetstat.html
重置 INFO 命令中的某些统计数据,包括:
Keyspace hits (键空间命中次数)
Keyspace misses (键空间不命中次数)
Number of commands processed (执行命令的次数)
Number of connections received (连接服务器的次数)
Number of expired keys (过期key的数量)
Number of rejected connections (被拒绝的连接数量)
Latest fork(2) time(最后执行 fork(2) 的时间)
The aof_delayed_fsync counter(aof_delayed_fsync 计数器的值)
Bigkeys
持续采样,实时输出当时得到的 value 占用空间最大的 key
./redis-cli --bigkeys
# Scanning the entire keyspace to find biggest keys as well as
# average sizes per key type. You can use -i 0.1 to sleep 0.1 sec
# per 100 SCAN commands (not usually needed).
[00.00%] Biggest string found so far 'A' with 110 bytes
[00.00%] Biggest string found so far 'B' with 111 bytes
[00.00%] Biggest string found so far 'C' with 137 bytes
......
-------- summary -------
Sampled 860830 keys in the keyspace!
Total key length in bytes is 43384761 (avg len 50.40)
Biggest string found 'X' has 194 bytes
860830 strings with 96957492 bytes (100.00% of keys, avg size 112.63)
0 lists with 0 items (00.00% of keys, avg size 0.00)
0 sets with 0 members (00.00% of keys, avg size 0.00)
0 hashs with 0 fields (00.00% of keys, avg size 0.00)
0 zsets with 0 members (00.00% of keys, avg size 0.00)
命令统计(配合重置计数器)
./redis-cli info commandstats
# Commandstats
cmdstat_set:calls=78911,usec=558105,usec_per_call=7.07
cmdstat_setex:calls=292806,usec=2172915,usec_per_call=7.42
cmdstat_strlen:calls=860830,usec=1195826,usec_per_call=1.39
cmdstat_del:calls=35035,usec=132577,usec_per_call=3.78
cmdstat_incr:calls=12417,usec=39987,usec_per_call=3.22
cmdstat_lpush:calls=68806,usec=301346,usec_per_call=4.38
cmdstat_ltrim:calls=12024,usec=56763,usec_per_call=4.72
cmdstat_lrem:calls=55246,usec=568687,usec_per_call=10.29
cmdstat_zadd:calls=450,usec=6991,usec_per_call=15.54
cmdstat_zremrangebyscore:calls=93,usec=1153,usec_per_call=12.40
cmdstat_zremrangebyrank:calls=272,usec=2586,usec_per_call=9.51
cmdstat_hset:calls=753,usec=5235,usec_per_call=6.95
cmdstat_hdel:calls=379,usec=2173,usec_per_call=5.73
cmdstat_incrby:calls=5034,usec=18849,usec_per_call=3.74
cmdstat_select:calls=195364,usec=174016,usec_per_call=0.89
cmdstat_expire:calls=13775,usec=41087,usec_per_call=2.98
cmdstat_scan:calls=82681,usec=2272315,usec_per_call=27.48
cmdstat_dbsize:calls=1,usec=2,usec_per_call=2.00
cmdstat_auth:calls=7,usec=14,usec_per_call=2.00
cmdstat_ping:calls=6305,usec=14882,usec_per_call=2.36
cmdstat_type:calls=860830,usec=1246794,usec_per_call=1.45
cmdstat_multi:calls=2524,usec=669,usec_per_call=0.27
cmdstat_exec:calls=2524,usec=5888,usec_per_call=2.33
cmdstat_info:calls=607,usec=44198,usec_per_call=72.81
cmdstat_config:calls=1,usec=20836,usec_per_call=20836.00
cmdstat_subscribe:calls=3,usec=9,usec_per_call=3.00
cmdstat_publish:calls=5748,usec=53970,usec_per_call=9.39
cmdstat_client:calls=3,usec=5,usec_per_call=1.67
调试.查看Redis执行的所有命令.
./redis-cli monitor
内存占用分析
yum install python-pip
pip install rdbtools
rdb -c memory dump.rdb > memory.csv
优化与禁忌
解决保存快照失败后redis无法写入的问题
>config set stop-writes-on-bgsave-error no
定期日志重写,减小aof重载时的时间开销
>auto-aof-rewrite-percentage 100
>auto-aof-rewrite-min-size 64mb
使用scan ... MATCH .. 代替 keys *
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29254281/viewspace-2105885/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29254281/viewspace-2105885/