那些年遇到的坑—EPOLL(cpu100%/卡死)
最近在定位BUG时发现了这么一个问题
程序跑的设备上4个CPU只有一个CPU是跑满的状态,其他CPU的占用率都非常低,且此设备上几乎无业务。
通过火焰图定位是哪个模块出现问题之后,通过pstack 看看有问题的这个进程在干什么
pstack pid
#0 0x00007fbea3424d43 in epoll_wait () from /lib64/libc.so.6
通过pstack 可以看到,有大量的系统调用sys_epoll_wait占用了CPU
所以怀疑event_base_loop陷入了死循环,一直在反复调用epoll_wait。
也可以使用
-bash-4.2# perf top -e cpu-clock -p pid
-bash-4.2# perf report -i perf.data 查看系统调用占用率
为了确认是否存在反复调用epoll_wait的问题, 在设备上安装了systemtap工具, 通过工具每隔1秒打印1次epoll_wait的调用次数。结果如下:
=Timer(1) Begin=
=Timer(1) End=
=Timer(2) Begin=
pid( 1554) xxx1 --> called 200843 epoll_wait(epfd13)
pid( 651) xxx-daemon --> called 127 epoll_wait(epfd4)
pid( 480) xxx-journal --> called 9 epoll_wait(epfd7)
pid( 604) xxx --> called 18 epoll_wait(epfd9)
pid( 1744) xxx --> called 3 epoll_wait(epfd5)
pid( 1947)