通过jmc监控spark应用的内存使用情况

1、概述

使用jmc工具

(1)连接本机java测试程序

(2)连接远程主机java测试程序

(3)连接spark集群中提交的App中的driver,executor,监控这两个进程的jvm使用情况

2、操作过程

(1)连接本机

测试代码

public class HelloWorld {
    public static void main(String[] args){
        while (true){
            System.out.println("hello world!");
        }
    }
}

在cmd下执行

java -Dcom.sun.management.jmxremote.port=7091 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar

参数解读:

-Dcom.sun.management.jmxremote.port=7091   :开启远程连接的端口

-Dcom.sun.management.jmxremote.authenticate=false     :是否开启验证,改为false

-Dcom.sun.management.jmxremote.ssl=false         :是否使用ssl加密协议,我是用false,不知道true是否可以远程连接

到java bin目录下启动jmc

 

点击:文件===》连接====》创建新的连接

点击连接即可

(2)连接远程主机java测试程序

同windows环境下的连接方式相同。

(3)连接spark集群中提交的App中的driver,executor,监控这两个进程的jvm使用情况

大致过程与前边相同,但是关于配置jvm启动参数时需要注意:

配置方式有三种:

1)在spark-defaults.conf中配置那三个参数

2)在spark-env.sh中配置:配置master,worker的JavaOptions

3)在spark-submit提交时配置

spark-submit \
--class myTest.KafkaWordCount --master spark://*.*.*.*:7077 \
--conf "spark.driver.extraJavaOptions=-Dcom.sun.management.jmxremote.port=7091 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false" \
--conf "spark.executor.extraJavaOptions=-Dcom.sun.management.jmxremote.port=7092 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false" \
--deploy-mode cluster \
--supervise \
--executor-memory 1G \
--total-executor-cores 6 \
/hadoop/spark/app/spark/20151223/testSpark.jar *.*.*.*:* test3 wordcount 4 kafkawordcount3 checkpoint4

注意:

deriver的JavaOptions参数只能在spark-submit脚本或者default配置文件中配,具体看如下的官方文档介绍

A string of extra JVM options to pass to the driver. For instance, GC settings or other logging. 
Note: In client mode, this config must not be set through the SparkConf directly in your application, because the driver JVM has already started at that point. Instead, please set this through the --driver-java-options command line option or in your default properties file.

executor可以在程序中通过conf.set("","")方式来配,通过spark-submit脚本中配,通过default配置文件配。但是,需要注意配置文件加载顺序的影响。只需要一个地方配就好了,否则最后加载的配置参数会将其他位置的配置参数给覆盖掉。

你可能感兴趣的:(Spark相关)