1.shell 脚本
exec $SPARK_HOME/bin/spark-submit \
--class com.bigeyedata.mort.Main \$MORT_HOME/mort.jar > $MORT_HOME/mort.log 2>&1
2.命令:
~/opt/spark-2.2.0-bin-hadoop2.7/bin/spark-submit \
--class com.sznongfu.cn.center.StartCenter \
--master spark://$(hostname):7077 \
--executor-memory 1G \
--total-executor-cores 30 \
--driver-class-path /home/sznongfu/opt/spark-2.2.0-bin-hadoop2.7/jars/ \
../libs/LogProcess-1.0-SNAPSHOT-all.jar ../conf/la.benchmark.properties com.sznongfu.cn.offline.statistic.UserTrajectoryStatistic >> ../logs/offline.log 2>&1 &
3.spark on yarn
yarn-client: 无法关闭启动任务所在机器,便于进行错误日志收集,进行问题定位(相比yarn-cluster日志不确定:需要用yarn logs -applicationId)
spark-shell
spark-submit
--master yarn-client/yarn-cluster \
--driver-memory 10g \ --驱动器节点分配内存
--num-executors 3 \ --执行器节点个数
--executor-memory 3g \ --每个executor 分配的内存
--executor-cores 2 \ -- 每个executor分配的cpu core数量 :3 (为提高并发量,提高吞吐,可以超过物理cpu cores(超线程技术))
-- conf spark.yarn.executor.memoryOverhead=1024m --设置executor的堆外内存(不受GC管理)
driver 分配的总内存为: 10g
executor分配的总内存为 num-executor * executor-memory == 集群all executor分配集群可用内存总量
--driver-memory : driver节点分配的内存大小
--num-executor: 启动executor 数量,即执行spark 计算任务启动的jvm数量
--executor-memory: executor 内存大小,默认1g
--executor-cores: 每个executor 使用内核数量(因超线程技术等,为提高并发量,吞吐,可以设置超过物理cpu cores,但要综合考虑(是否影响其他应用)
--jars: driver 节点依赖的第三方jar(如mysql依赖)
--class : 主类名称,全路径,是spark apllication的main ,应用入口
--queue: 提交应用程序给那个队列,默认:default --防止spark资源争用
--conf spark.properites=value :任意spark属性
spark executor container 内存: 堆内内存,executor内存
executor.memory : 进行业务处理,广播变量,accumualtor
spark.memory.fraction:
用于设置execution,storage内存在节点内存的总占比
storage: (JVMn对内存-300M,300是预留内存,防止OOM)默认是整个内存的60%,用于存储spark运算中序列化对象,为了防止OOM,只分配了60%的90%,另外60%90%中又有20%分配的内存进行序列化和反序列化运算
execution:默认整个内存的20%,用于处理spark shuffle,join,aggregate计算等,为了防止OOM,之分配了20%的80%
spark.memory.storageFraction:设置storage占 storage和execution的占比,可避免cache和persit的缓存数据被清理
yarn 的 apllication master 容器创建后,接受spark提交的taskset进行启动设置数量的executor容器,apllication master也会占用一个core,对应内存