1. Analyse redis slowlog
Sous-commande SLOWLOG [argument]
Voici les paramètres de configuration des requêtes lentes de redis .conf :
slowlog-log-slower-than 10000 #查询时间超过10ms的会被记录 slowlog-max-len 128 #最多记录128个慢查询
Les paramètres ci-dessus peuvent être interrogés dynamiquement ou définis dans redis : utilisez les commandes config get et config set
pour lire les requêtes lentes : vous pouvez obtenir les quelques requêtes lentes spécifiées
🎜>
127.0.0.1:6320> slowlog get 1 1) 1) (integer) 394689 #slowlog的唯一编号 2) (integer) 1480851711 #此次slowlog事件的发生时间 3) (integer) 10639 #耗时 4) 1) "HGET" #slowlog事件所对应的redis 命令 2) "hash:submit_sent_150004" 3) "15000429648122734363745165312"
SLOWLOG RESET
2. Comment utiliser les commandes SCAN, SSCAN, HSCAN et ZSCAN
SCAN est un itérateur basé sur un curseur. Cela signifie qu'à chaque appel à la commande, le serveur renvoie un curseur mis à jour que l'utilisateur doit utiliser comme paramètre de curseur lors du prochain appel. L'itération commence lorsque le curseur est mis à 0, et se termine lorsque le curseur renvoyé par le serveur est 0. Voici un exemple d'itération SCAN :127.0.0.1:6319> scan 0 1) "65536" 2) 1) "list:submit_sent_2016-12-02-13:50_130806" 2) "list:submit_sent_2016-12-01-15:01_130479" 3) "list:submit_sent_2016-12-01-13:21_178888" 4) "list:submit_sent_2016-12-02-10:46_186064" 5) "list:submit_sent_2016-12-01-16:48_135546" 6) "list:submit_sent_2016-12-02-14:27_185158" 7) "list:submit_sent_2016-12-02-09:57_186532" 8) "list:submit_sent_2016-12-01-13:24_183217" 9) "list:submit_sent_2016-12-02-08:29_189316" 10) "list:submit_sent_2016-12-01-13:46_177645" 127.0.0.1:6319> scan 65536 1) "884736" 2) 1) "list:submit_sent_2016-12-01-17:55_175010" 2) "list:submit_sent_2016-12-02-18:28_138052" 3) "list:submit_sent_2016-12-01-18:17_150243" 4) "list:submit_sent_2016-12-01-11:22_137606" 5) "list:submit_sent_2016-12-01-21:15_183748" 6) "list:submit_sent_2016-12-02-11:47_155212" 7) "list:submit_sent_2016-12-01-11:01_137065" 8) "list:submit_sent_2016-12-02-08:03_181202" 9) "list:submit_sent_2016-12-02-12:16_136096" 10) "list:submit_sent_2016-12-01-18:12_159893"
127.0.0.1:6319> scan 0 count 20 1) "884736" 2) 1) "list:submit_sent_2016-12-02-13:50_130806" 2) "list:submit_sent_2016-12-01-15:01_130479" 3) "list:submit_sent_2016-12-01-13:21_178888" 4) "list:submit_sent_2016-12-02-10:46_186064" 5) "list:submit_sent_2016-12-01-16:48_135546" 6) "list:submit_sent_2016-12-02-14:27_185158" 7) "list:submit_sent_2016-12-02-09:57_186532" 8) "list:submit_sent_2016-12-01-13:24_183217" 9) "list:submit_sent_2016-12-02-08:29_189316" 10) "list:submit_sent_2016-12-01-13:46_177645" 11) "list:submit_sent_2016-12-01-17:55_175010" 12) "list:submit_sent_2016-12-02-18:28_138052" 13) "list:submit_sent_2016-12-01-18:17_150243" 14) "list:submit_sent_2016-12-01-11:22_137606" 15) "list:submit_sent_2016-12-01-21:15_183748" 16) "list:submit_sent_2016-12-02-11:47_155212" 17) "list:submit_sent_2016-12-01-11:01_137065" 18) "list:submit_sent_2016-12-02-08:03_181202" 19) "list:submit_sent_2016-12-02-12:16_136096" 20) "list:submit_sent_2016-12-01-18:12_159893"
127.0.0.1:6319> scan 0 match *submit_sent* 1) "65536" 2) 1) "list:submit_sent_2016-12-02-13:50_130806" 2) "list:submit_sent_2016-12-01-15:01_130479" 3) "list:submit_sent_2016-12-01-13:21_178888" 4) "list:submit_sent_2016-12-02-10:46_186064" 5) "list:submit_sent_2016-12-01-16:48_135546" 6) "list:submit_sent_2016-12-02-14:27_185158" 7) "list:submit_sent_2016-12-02-09:57_186532" 8) "list:submit_sent_2016-12-01-13:24_183217" 9) "list:submit_sent_2016-12-02-08:29_189316" 10) "list:submit_sent_2016-12-01-13:46_177645" 127.0.0.1:6319> scan 0 count 15 match *submit_sent* #查找匹配的数据并返回15个 1) "2031616" 2) 1) "list:submit_sent_2016-12-02-13:50_130806" 2) "list:submit_sent_2016-12-01-15:01_130479" 3) "list:submit_sent_2016-12-01-13:21_178888" 4) "list:submit_sent_2016-12-02-10:46_186064" 5) "list:submit_sent_2016-12-01-16:48_135546" 6) "list:submit_sent_2016-12-02-14:27_185158" 7) "list:submit_sent_2016-12-02-09:57_186532" 8) "list:submit_sent_2016-12-01-13:24_183217" 9) "list:submit_sent_2016-12-02-08:29_189316" 10) "list:submit_sent_2016-12-01-13:46_177645" 11) "list:submit_sent_2016-12-01-17:55_175010" 12) "list:submit_sent_2016-12-02-18:28_138052" 13) "list:submit_sent_2016-12-01-18:17_150243" 14) "list:submit_sent_2016-12-01-11:22_137606" 15) "list:submit_sent_2016-12-01-21:15_183748"
redis 127.0.0.1:6379> sadd myset 1 2 3 foo foobar feelsgood (integer) 6 redis 127.0.0.1:6379> sscan myset 0 match f* 1) "0" 2) 1) "foo" 2) "feelsgood" 3) "foobar" redis 127.0.0.1:6379>
redis 127.0.0.1:6379> hmset hash name Jack age 33 OK redis 127.0.0.1:6379> hscan hash 0 1) "0" 2) 1) "name" 2) "Jack" 3) "age" 4) "33"
echo never > /sys/kernel/mm/transparent_hugepage/enabled
3. Vérifiez si redis est affecté par l'utilisation du swap par le système :
查找redis进程id: redis-cli -p 6319 info|grep process_id process_id:32139 查看redis进程的内存使用信息: cd /proc/32139 查看该进程使用swap分区的统计信息,以不使用或只有少量的4kB为佳: cat smaps | grep 'Swap:' 同时打印出内存映射和swap使用信息:查看那些较大的内存消耗是否引发了大的swap使用 cat smaps | egrep '^(Swap:Size)'
Redis software watchdog 该功能只能动态启用,使用以下命令: CONFIG SET watchdog-period 500 注:redis会开始频繁监控自身的延时问题,并把问题输出到日志文件中去。 关闭watchdog: CONFIG SET watchdog-period 0 注:打开watchdog功能,会对redis服务性能产生影响。
CONFIG SET latency-monitor-threshold 100
127.0.0.1:6319> latency latest 1) 1) "command" #event name 2) (integer) 1480865648 #发生时间 3) (integer) 207 #耗时,毫秒 4) (integer) 239 #从redis启动或上次latency reset以来,这种事件的最大延时记录
127.0.0.1:6319> latency history command 1) 1) (integer) 1480865710 2) (integer) 207 2) 1) (integer) 1480865711 2) (integer) 217 3) 1) (integer) 1480865712 2) (integer) 198 4) 1) (integer) 1480865713 2) (integer) 226 5) 1) (integer) 1480865714 2) (integer) 224
LATENCY GRAPH event-name 127.0.0.1:6379> latency graph command command - high 500 ms, low 101 ms (all time high 500 ms) -------------------------------------------------------------------------------- #_ _|| _||| _|||| 11186 542ss sss
127.0.0.1:6379> latency doctor Dave, I have observed latency spikes in this Redis instance. You don't mind talking about it, do you Dave? 1. command: 5 latency spikes (average 300ms, mean deviation 120ms, period 73.40 sec). Worst all time event 500ms. I have a few advices for you: - Your current Slow Log configuration only logs events that are slower than your configured latency monitor threshold. Please use 'CONFIG SET slowlog-log-slower-than 1000'. - Check your Slow Log to understand what are the commands you are running which are too slow to execute. Please check http://redis.io/commands/slowlog for more information. - Deleting, expiring or evicting (becaus
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!