nchan 火焰图学习

主要是想学习下nchan nginx 模块的生命周期阶段函数,为了方便直接基于openresty+perf 搞了一个docker 镜像
方便了解nchan 的阶段处理

docker 镜像构建

具体参考github 文档, https://github.com/rongfengliang/openresty-tengine-docker/blob/master/alpine/Dockerfile-debug-njs

perf 集成

 
FROM dalongrong/openresty-tengine:debug-njs
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk update && apk upgrade
RUN apk add --no-cache perf

已经构建好的镜像dalongrong/openresty-tengine:debug-njs-perf

参考使用

具体可以参考gihtub rongfengliang/openresty-nchan,对于容器运行核心是cap 能力的添加,比如如下,我为了方便直接添加的ALL
运行命令

 
sh -c " echo 0 > /proc/sys/kernel/kptr_restrict"
perf record -ag -F 99 1

docker-compose 部分配置

   app:
     image: dalongrong/openresty-tengine:debug-njs-perf
     privileged: true
     cap_add:
       - ALL
     ports:
     - "80:80"
     volumes:
     - "./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf"

效果

对于生成的perf 文件,我是基于flamescope 工具分析的,很方便火焰图生成分析工具

  • redis event 处理

从下图可以看出,实际上作者的演讲中有提到

 

 


 

 

  • pubsub 指令的处理

 

 

说明

我已经共享了一个到github 可以参考 https://github.com/rongfengliang/openresty-perf/blob/main/nchan.perf ,结合火焰图可以更好的了解nchan 的机制

参考资料

https://github.com/rongfengliang/openresty-perf
https://github.com/rongfengliang/openresty-nchan
https://www.cnblogs.com/rongfengliang/p/11350847.html
https://github.com/rongfengliang/openresty-perf/blob/main/nchan.perf

posted on 2022-06-05 23:10  荣锋亮  阅读(81)  评论(0编辑  收藏  举报

导航