zoukankan      html  css  js  c++  java
  • 使用arthas 生成火焰图分析jvm

    arthas 是阿里巴巴开源的强大的jvm 应该分析工具,以下是使用arthas 生成jvm 火焰图的一个学习
    项目使用docker-compose 运行,对于生成的火焰图使用nginx 提供一个访问入口

    环境准备

    • docker-compose 文件
     
    version: "3"
    services: 
      web:
        image: openresty/openresty:alpine
        ports:
        - "8090:80"
        volumes: 
        - "./flamegraph:/opt/mywebs"
        - "./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf"
      app:
        build: ./
        cap_add: 
        - ALL
        ports:
        - "8080:8080"
        volumes: 
        - "./flamegraph:/usr/local/tomcat/arthas-output"
    • tomcat 集成arthas dockerfile
    FROM tomcat
    # copy arthas
    COPY --from=hengyunabc/arthas:latest /opt/arthas /opt/arthas
    • nginx config
    worker_processes 1;
    user root;  
    events {
        worker_connections 1024;
    }
    http {
        include mime.types;
        default_type application/octet-stream;
        sendfile on;
        lua_code_cache off;
        lua_need_request_body on;
        gzip on;
        resolver 127.0.0.11 ipv6=off;          
        real_ip_header X-Forwarded-For;
        real_ip_recursive on;
        gzip_min_length 2k;
        gzip_buffers 4 16k;
        log_format compression '$remote_addr - $remote_user [$time_local] '
                           '"$request" $status $bytes_sent '
                           '"$http_referer" "$http_user_agent" "$gzip_ratio"';
        gzip_comp_level 4;
        gzip_types text/plain text/css image/png application/javascript image/jpeg image/gif;
        server {
            listen 80;
            server_name _;
            charset utf-8;
            default_type text/html;
            root /opt/mywebs;
            location / {
               default_type text/plain;
               autoindex on;
            }
            location = /empty {
                empty_gif;
            }
            error_page 500 502 503 504 /50x.html;
            location = /50x.html {
                root html;
            }
        }
    }

    使用

    • 启动
    docker-compose up -d
    • 进入tomcat 启动arthas
    docker-compose exec app sh 
    java -jar /opt/arthas/arthas-boot.jar
    选择进程id 默认为1
    • 开启profiler
      生成火焰图
     
    profiler start
    • 一个简单的压力测试
    ab -n 20000 -c 200 http://localhost:8080/
    • 停止profiler
    profiler stop
    • 查看火焰图

    说明

    以上是一个简单的学习使用,开启容器的profiler 需要添加cap 为了简单,添加了all,arthas 功能很强大,是一把利器,同时集成到docker
    镜像中,可以方便的分析一些性能瓶颈

    参考资料

    https://alibaba.github.io/arthas/
    https://github.com/rongfengliang/arthas-docker-demo
    https://github.com/alibaba/arthas

  • 相关阅读:
    【HDU 6096】—String(扫描线+Trie)
    【BZOJ #4231】—回忆树(Kmp+Ac自动机)
    【BZOJ #4231】—回忆树(Kmp+Ac自动机)
    【BZOJ #3942】【Usaco2015 Feb】—Censoring(哈希)
    【BZOJ #3942】【Usaco2015 Feb】—Censoring(哈希)
    【洛谷P2444】【POI2000】—病毒(Ac自动机)
    【洛谷P2444】【POI2000】—病毒(Ac自动机)
    响应式实践
    2016-12-30
    响应式调研资料
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/12036957.html
Copyright © 2011-2022 走看看