nginx 火焰图分析

主要是简单的学习,基于了openresty 开启了debug,同时保留构建的符号表信息

构建命令

只包含核心部分,其他的具体参考gihtub

    --with-debug \
    --with-cc-opt='-O0 -g' \

容器集成使用

  • nginx 配置使用了单进程模式
worker_processes  1;
user root;  
master_process off;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    root html;
    keepalive_timeout  65;
    gzip  on;
    upstream cluster1 {
        # simple round-robin
        server app2:80;
        server app3:80;
        check interval=1000 rise=2 fall=5 timeout=1000 type=http;
        check_http_send "HEAD / HTTP/1.0\r\n\r\n";
        check_http_expect_alive http_2xx http_3xx;
    }  
     upstream cluster2 {
        # simple round-robin
        server app2:80;
        server app3:80;
        check interval=1000 rise=2 fall=5 timeout=1000 type=http;
        check_http_send "HEAD / HTTP/1.0\r\n\r\n";
        check_http_expect_alive http_2xx http_3xx;
    } 
    server {
        listen       81;
        server_name  localhost;
        charset utf-8;
        default_type text/html;
        location / {
            index index.html;
        }
        location /status {
            healthcheck_status;
        }
        location /app.html {
            root html;
        }
        location /css/ {
            trim on;
            trim_js on;
            trim_css on;
            concat on;
            concat_max_files 20;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }    
    }
    server {
        listen       80;
        server_name  localhost;
        charset utf-8;
        default_type text/html;
        location / {
            proxy_set_header Host $http_host;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for; 
            client_body_buffer_size 10M;
            client_max_body_size 10G;
            proxy_buffers 1024 4k;
            proxy_read_timeout 300;
            proxy_connect_timeout 80;
            proxy_pass http://cluster1;
            footer "<!-- dalong demo-->";  
        }
        location /status {
            healthcheck_status;
        }
        location /app.html {
            root html;
        }
        location /css/ {
            trim on;
            trim_js on;
            trim_css on;
            concat on;
            concat_max_files 20;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }    
    }    
}
  • 集成perf 的镜像
FROM dalongrong/openresty-tengine:debug
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
  • docker-compose 集成
version: '3'
services:
  app:
    build: ./
    volumes:
      - "./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf"
      - "./css/:/usr/local/openresty/nginx/html/"
    privileged: true
    cap_add:
       - ALL
    ports:
      - "80:80"
      - "81:81"
  app2:
    image: dalongrong/openresty-tengine:latest
  app3:
    image: dalongrong/openresty-tengine:latest

perf 集成

  • 预备
    进入容器
 
sh -c " echo 0 > /proc/sys/kernel/kptr_restrict"
perf record -ag -F 99 1
  • 执行压测
ab -n 20000 -c 100 http://localhost/
ab -n 20000 -c 100 http://localhost/status
  • 生成perf 内容
perf script --header > nginx.perf
  • 使用flamescope 查看火焰图

 

 

  • 参考效果

 

 

说明

相关测试perf 我已经push 到github 了,可以参考学习

参考资料

https://github.com/rongfengliang/openresty-tengine-docker/blob/master/alpine/Dockerfile-debug
https://docs.nginx.com/nginx/admin-guide/monitoring/debugging/
https://www.cnblogs.com/rongfengliang/p/11350847.html
https://github.com/Netflix/flamescope
https://github.com/rongfengliang/openresty-perf

posted on   荣锋亮  阅读(332)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2021-04-04 dremio 自定义arp 开发的几个细节
2021-04-04 protostuff java 序列化&&proto 编译&&生成器
2021-04-04 dremio 15一些新特性简单说明
2021-04-04 dremio 15 发布
2020-04-04 baretest小巧但是强大的jest可选测试框架
2020-04-04 fetchq-cron 基于webhook 的任务调度工具
2020-04-04 uwsgi+nginx+flask+docker+supervisord oracle中文乱码问题

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示