以下是为****平台中****业务选择Java profile工具的结论:
微服务 SPARK_APP 备注
VisualVm jstatd Y Y 信息过少
VisualVm JMX Y Y ok
Jprofiler Y N 商用软件
Flight Recorder Y Y good
Yourkit Y Y 商用软件
一、VisualVm jstatd
Jstatd方法是利用后台的RMI守护进程来实现对远程JVM的监控
/pathto/jdk1.8.0_144/bin # cat jstatd.all.policy
grant codebase"file:/pathto /jdk1.8.0_144/lib/tools.jar"{ permission java.security.AllPermission; };
/pathto/jdk1.8.0_144/bin # ./jstatd -J-Djava.security.policy=jstatd.all.policy -J-Djava.rmi.server.hostname=<serverIp>
启动后会开启注册端口1099和一个随机的连接端口
注:
注册端口也可通过-p参数指定,如./jstatd -J-Djava.security.policy=all.policy -p 10003 &
如果需要RMI 日志功能的话,还可以在jstatd启动参数中加入 -J-Djava.rmi.server.logCalls=true
经过上诉步骤,即可在VisualVm-->Add Remote Host--><serverIp>即可看到信息
二、VisualVm JMX
修改进程启动参数,如在启动脚本中添加:
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8852 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=<serverIp>"
经过上诉步骤,即可在VisualVm-->Add Remote Host--><serverIp>-->Add JMX Connection 即可看到信息,包括概览
线程、MBeans、GC等信息
如何来调试Spark ON Yarn程序:
https://stackoverflow.com/questions/45435237/how-to-connect-with-jmx-remotely-to-spark-worker-on-dataproc
spark.driver.extraJavaOptions=-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=9178 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false
spark.executor.extraJavaOptions=-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=0 \ ----注意是0
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false
设置:-Dcom.sun.management.jmxremote.port=0产生一个随机端口。要找出最终使用的端口,请执行以下操作:netstat -alp | grep LISTEN.*<executor-pid>/java列出了该进程当前打开的端口。
其他:
添加VisualVm插件(监控项):
按https://blog.csdn.net/keketrtr/article/details/74448127 配置插件,由于代理原因,可通过本地安装的方式进行。Catalog URL: https://visualvm.github.io/uc/8u131/updates.xml.gz
也可以通过https://visualvm.github.io/下载最新版本visualvm,新版本可以直接使用系统代理。
三、JProfile
参考:
https://www.ej-technologies.com/products/jprofiler/overview.html
https://www.cnblogs.com/AmilyWilly/p/7272160.html?utm_source=itdadao&utm_medium=referral
四、Jcmd Flight Recorder
1、为服务器配置Java环境变量
export JAVA_HOME=/opt/huawei/Bigdata/common/runtime0/jdk1.8.0_144
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
2、重启集群
---上两步仅需操作一次---
3、开启进程的flight recorder配置
对于spark来说,spark-defaults.conf配置如下:
# Enable flight recording on the driver.
spark.driver.extraJavaOptions -XX:+UnlockCommercialFeatures -XX:+FlightRecorder
# Enable flight recording on the executors.
spark.executor.extraJavaOptions -XX:+UnlockCommercialFeatures -XX:+FlightRecorder
重启spark
/root/spark/sbin/stop-all.sh
/root/spark/sbin/start-all.sh
Spark on yarn需要重启yarn-----
4、找到要profile的进程 grep FlightRecorder
5、attach
# /pathto/jcmd <PID> JFR.start filename=spark.jfr settings=template.jfc duration=10s
注:attach不上可能需要切换下用户
settings=template.jfc 指定监控模板
6、生成火焰图
可以用5生成的spark.jfr文件生成火焰图https://github.com/chrishantha/jfr-flame-graph
五、Yourkit
略,商用工具,还没尝试过,据说功能不错