使用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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· spring官宣接入deepseek,真的太香了~
2018-12-13 使用loki+ mtail + grafana + prometheus server分析应用问题
2018-12-13 mtail 提取应用日志数据到时序数据库的工具-支持prometheus
2018-12-13 使用 loki grafana 分析nginx 请求日志
2018-12-13 loki grafana 团队开源的,类似Prometheus 的log 系统
2017-12-13 gradle asciidoc 使用