使用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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM