uber_jvm-profiler 初探

uber的porfiler,
地址如下
https://github.com/uber-common/jvm-profiler

它可以针对spark项目上传到hdfs,针对集群进行性能分析。这儿先做一点小的笔记

首先需要系统有maven,
git clone
在下载当前目录:
mvn clean package
即可使用

run sprak项目示例:

1
2
3
–conf spark.jars=hdfs://hdfs_url/lib/jvm-profiler-1.0.0.jar

–conf spark.executor.extraJavaOptions=-javaagent:jvm-profiler-1.0.0.jar

run jar包示例

1
java -javaagent:/opt/jvm-profiler/target/jvm-profiler-1.0.0.jar=reporter=com.uber.profiling.reporters.ConsoleOutputReporter,metricInterval=5000,durationProfiling=foo.bar.FooAppication.barMethod,sampleInterval=5000 -jar foo-application.jar

注意,上文中的durationProfiling是classpath,我个人使用groupid+a..id+mainclass定位的,不知道有没有错。
有的时候会显示jar包没有主类,解决方法是在pom中添加maven插件,在spark初探一文中我有备注。

它的功能包括以下内容:

1
2
3
4
5
6
Debug memory usage for all your spark application executors, including java heap memory, non-heap memory, native memory (VmRSS, VmHWM), memory pool, and buffer pool (directed/mapped buffer).
Debug CPU usage, Garbage Collection time for all spark executors.
Debug arbitrary java class methods (how many times they run, how much duration they spend). We call it Duration Profiling.
Debug arbitrary java class method call and trace it argument value. We call it Argument Profiling.
Do Stacktrack Profiling and generate flamegraph to visualize CPU time spent for the spark application.
Debug IO metrics (disk read/write bytes for the application, CPU iowait for the machine)

分析还是用火焰图比较好看,这时候就需要改一些参数,比如reporter类型,outputDir等
GitHub中有参数具体解释,这里不过多赘述
以下命令可以生成相关的数据json

1
java -javaagent:/home/ycr/uber_profile/jvm-profiler/target/jvm-profiler-1.0.0.jar=reporter=com.uber.profiling.reporters.FileOutputReporter,sampleInterval=5000,outputDir=/home/ycr/test/target,metricInterval=5000,durationProfiling=com.cn.SimpleApp,sampleInterval=5000 -jar test-1.0-SNAPSHOT.jar

注意修改两个jar包的位置即可。
生成3个json,json格式可以在github上看到,不多说。
在当前目录下的py脚本可以按步骤生成.svg的火焰图

python stackcollapse.py -i Stacktrace.json > Stacktrace.folded
flamegraph.pl Stacktrace.folded > Stacktrace.svg
注意,flamegraph.pl不是该项目的文件,是另一个火焰图项目的内容,见github
https://github.com/brendangregg/FlameGraph
需要clone后使用