4.最后一招:WatchDog

本文介绍了Redis中的WatchDog功能,该功能可在慢操作时记录函数执行栈,并将其打印到日志中。通过设置watchdog-period参数激活此功能,有助于诊断Redis性能问题。
官方说法提供的最后一招(last resort)就是WatchDog。它能够将慢操作的整个函数执行栈打印到Redis日志中。因为它与前面介绍过的将记录保存在内存中的延迟和满操作记录不同,所以记得使用前要在redis.conf中配置logfile日志路径:
  1. [root@vm redis-3.0.3]# src/redis-cli -h 127.0.0.1
  2. 127.0.0.1:6379> CONFIG SET watchdog-period 500
  3. OK
  4. 127.0.0.1:6379> debug sleep 1
  5. OK

  6. [root@vm redis-3.0.3]# tailf redis.log 
  7.       `-._    `-.__.-'    _.-'                                       
  8.           `-._        _.-'                                           
  9.               `-.__.-'                                               

  10. 51091:M 12 Aug 15:36:53.337 # Server started, Redis version 3.0.3
  11. 51091:M 12 Aug 15:36:53.338 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
  12. 51091:M 12 Aug 15:36:53.338 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
  13. 51091:M 12 Aug 15:36:53.343 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
  14. 51091:M 12 Aug 15:36:53.343 * DB loaded from disk: 0.000 seconds
  15. 51091:M 12 Aug 15:36:53.343 * The server is now ready to accept connections on port 6379

  16. 51091:signal-handler (1439365058) 
  17. --- WATCHDOG TIMER EXPIRED ---
  18. src/redis-server 127.0.0.1:6379(logStackTrace+0x43)[0x450363]
  19. /lib64/libpthread.so.0(__nanosleep+0x2d)[0x3c0740ef3d]
  20. /lib64/libpthread.so.0[0x3c0740f710]
  21. /lib64/libpthread.so.0[0x3c0740f710]
  22. /lib64/libpthread.so.0(__nanosleep+0x2d)[0x3c0740ef3d]
  23. src/redis-server 127.0.0.1:6379(debugCommand+0x58d)[0x45180d]
  24. src/redis-server 127.0.0.1:6379(call+0x72)[0x4201b2]
  25. src/redis-server 127.0.0.1:6379(processCommand+0x3e5)[0x4207d5]
  26. src/redis-server 127.0.0.1:6379(processInputBuffer+0x4f)[0x42c66f]
  27. src/redis-server 127.0.0.1:6379(readQueryFromClient+0xc2)[0x42c7b2]
  28. src/redis-server 127.0.0.1:6379(aeProcessEvents+0x13c)[0x41a52c]
  29. src/redis-server 127.0.0.1:6379(aeMain+0x2b)[0x41a7eb]
  30. src/redis-server 127.0.0.1:6379(main+0x2cd)[0x423c8d]
  31. /lib64/libc.so.6(__libc_start_main+0xfd)[0x3c0701ed5d]
  32. src/redis-server 127.0.0.1:6379[0x419b49]
  33. 51091:signal-handler (51091:signal-handler (1439365058) ) --------





本文作者:geelou
本文来自云栖社区合作伙伴rediscn,了解相关信息可以关注redis.cn网站。
解释当前log 分析原因,定位具体代码位置并提供解决办法 Dec 31 19:07:05 vcswificam user.notice root: DEBUG : WATCHDOG : Anyka running at PID 560 Dec 31 19:07:06 vcswificam user.notice root: DEBUG : WATCHDOG : Anyka CPU utilization at 36% Dec 31 19:07:06 vcswificam user.notice root: INFO : WATCHDOG : Running Anyka CPU check. (36%) Over: (0/4) Under: (/4) Dec 31 19:07:12 vcswificam user.notice root: DEBUG : WATCHDOG : Anyka running at PID 560 Dec 31 19:07:13 vcswificam user.notice root: DEBUG : WATCHDOG : Anyka CPU utilization at 26% Dec 31 19:07:13 vcswificam user.notice root: INFO : WATCHDOG : Running Anyka CPU check. (26%) Over: (0/4) Under: (/4) Dec 31 19:07:18 vcswificam user.notice root: DEBUG : WATCHDOG : Anyka running at PID 560 Dec 31 19:07:19 vcswificam user.notice root: DEBUG : WATCHDOG : Anyka CPU utilization at 31% Dec 31 19:07:19 vcswificam user.notice root: INFO : WATCHDOG : Running Anyka CPU check. (31%) Over: (0/4) Under: (/4) Dec 31 19:07:25 vcswificam user.notice root: DEBUG : WATCHDOG : Anyka running at PID 560 Dec 31 19:07:25 vcswificam daemon.debug thttpd[447]: spawned CGI process 2532 for file 'cgi-bin/get_signal' Dec 31 19:07:27 vcswificam user.notice root: DEBUG : WATCHDOG : Anyka CPU utilization at 38% Dec 31 19:07:27 vcswificam user.notice root: INFO : WATCHDOG : Running Anyka CPU check. (38%) Over: (0/4) Under: (/4) Dec 31 19:07:32 vcswificam user.notice root: DEBUG : WATCHDOG : Anyka running at PID 560 Dec 31 19:07:33 vcswificam user.notice root: DEBUG : WATCHDOG : Anyka CPU utilization at 22% Dec 31 19:07:33 vcswificam user.notice root: INFO : WATCHDOG : Running Anyka CPU check. (22%) Over: (0/4) Under: (/4) Dec 31 19:07:39 vcswificam user.notice root: DEBUG : WATCHDOG : Anyka running at PID 560 Dec 31 19:07:39 vcswificam user.notice root: DEBUG : WATCHDOG : Anyka CPU utilization at 26% Dec 31 19:07:39 vcswificam user.notice root: INFO : WATCHDOG : Running Anyka CPU check. (26%) Over: (0/4) Under: (/4) Dec 31 19:07:39 vcswificam user.notice root: INFO : WATCHDOG : Running 30 second process... (Firmware version: 48.8.1, Uptime: 19:07:39 up 7 min, load average: 5.15, 3.67, 1.80) Dec 31 19:07:39 vcswificam user.notice root: DEBUG : WATCHDOG : Checking if wifi is configured to station mode. running = station Dec 31 19:07:40 vcswificam user.notice root: DEBUG : WATCHDOG : Checking if wifi is connected. wificonnecttest = 00:0A:52:0A:DF:B6 Dec 31 19:07:40 vcswificam user.notice root: INFO : WATCHDOG : WiFi = Connected. (Current: -35 / Minimum: -75) Dec 31 19:07:42 vcswificam user.notice root: INFO : WATCHDOG : IP = 172.20.1.51, Gateway = 172.20.1.1, Ping Gateway = Fail Dec 31 19:07:42 vcswificam kern.debug kernel: [ 462.250000] ieee80211 phy0: [SCAN] Scan request for 0 SSIDs. Dec 31 19:07:42 vcswificam user.notice root: OK
06-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值