spark-submit提交方式测试Demo
写一个小小的Demo测试一下Spark提交程序的流程
Maven的pom文件
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<encoding>UTF-8</encoding>
<spark.version>1.6.1</spark.version>
</properties> <dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>${spark.version}</version>
</dependency> <dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.1</version>
</dependency> </dependencies> <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
编写一个蒙特卡罗求PI的代码
import java.util.ArrayList;
import java.util.List; import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;
import org.apache.spark.api.java.function.Function2; import redis.clients.jedis.Jedis; /**
* Computes an approximation to pi
* Usage: JavaSparkPi [slices]
*/
public final class JavaSparkPi { public static void main(String[] args) throws Exception {
SparkConf sparkConf = new SparkConf().setAppName("JavaSparkPi")/*.setMaster("local[2]")*/;
JavaSparkContext jsc = new JavaSparkContext(sparkConf); Jedis jedis = new Jedis("192.168.49.151",19000);
int slices = (args.length == 1) ? Integer.parseInt(args[0]) : 2;
int n = 100000 * slices;
List<Integer> l = new ArrayList<Integer>(n);
for (int i = 0; i < n; i++) {
l.add(i);
} JavaRDD<Integer> dataSet = jsc.parallelize(l, slices); int count = dataSet.map(new Function<Integer, Integer>() {
@Override
public Integer call(Integer integer) {
double x = Math.random() * 2 - 1;
double y = Math.random() * 2 - 1;
return (x * x + y * y < 1) ? 1 : 0;
}
}).reduce(new Function2<Integer, Integer, Integer>() {
@Override
public Integer call(Integer integer, Integer integer2) {
return integer + integer2;
}
}); jedis.set("Pi", String.valueOf(4.0 * count / n));
System.out.println("Pi is roughly " + 4.0 * count / n); jsc.stop();
}
}
前提条件的setMaster("local[2]") 没有在代码中hard code
本地模式测试情况:# Run application locally on 8 cores
spark-submit \
--master local[8] \
--class com.spark.test.JavaSparkPi \
--executor-memory 4g \
--executor-cores 4 \
/home/dinpay/test/Spark-SubmitTest.jar 100
运行结果在本地:运行在本地一起提交8个Task,不会在WebUI的8080端口上看见提交的任务

-------------------------------------
spark-submit \
--master local[8] \
--class com.spark.test.JavaSparkPi \
--executor-memory 8G \
--total-executor-cores 8 \
hdfs://192.168.46.163:9000/home/test/Spark-SubmitTest.jar 100
运行报错:java.lang.ClassNotFoundException: com.spark.test.JavaSparkPi
------------------------------------
spark-submit \
--master local[8] \
--deploy-mode cluster \
--supervise \
--class com.spark.test.JavaSparkPi \
--executor-memory 8G \
--total-executor-cores 8 \
/home/dinpay/test/Spark-SubmitTest.jar 100
运行报错:Error: Cluster deploy mode is not compatible with master "local"
====================================================================
Standalone模式client模式 # Run on a Spark standalone cluster in client deploy mode
spark-submit \
--master spark://hadoop-namenode-02:7077 \
--class com.spark.test.JavaSparkPi \
--executor-memory 8g \
--tital-executor-cores 8 \
/home/dinpay/test/Spark-SubmitTest.jar 100
运行结果如下:



-------------------------------------------
spark-submit \
--master spark://hadoop-namenode-02:7077 \
--class com.spark.test.JavaSparkPi \
--executor-memory 4g \
--executor-cores 4g \
hdfs://192.168.46.163:9000/home/test/Spark-SubmitTest.jar 100
运行报错:java.lang.ClassNotFoundException: com.spark.test.JavaSparkPi
=======================================================================
standalone模式下的cluster模式 # Run on a Spark standalone cluster in cluster deploy mode with supervise
spark-submit \
--master spark://hadoop-namenode-02:7077 \
--class com.spark.test.JavaSparkPi \
--deploy-mode cluster \
--supervise \
--executor-memory 4g \
--executor-cores 4 \
/home/dinpay/test/Spark-SubmitTest.jar 100
运行报错:java.io.FileNotFoundException: /home/dinpay/test/Spark-SubmitTest.jar (No such file or directory)
-------------------------------------------
spark-submit \
--master spark://hadoop-namenode-02:7077 \
--class com.spark.test.JavaSparkPi \
--deploy-mode cluster \
--supervise \
--driver-memory 4g \
--driver-cores 4 \
--executor-memory 2g \
--total-executor-cores 4 \
hdfs://192.168.46.163:9000/home/test/Spark-SubmitTest.jar 100
运行结果如下:



=============================================
如果代码中写定了.setMaster("local[2]");
则提交的集群模式也会运行driver,但是不会有对应的application并行运行
spark-submit --deploy-mode cluster \
--master spark://hadoop-namenode-02:6066 \
--class com.dinpay.bdp.rcp.service.Window12HzStat \
--driver-memory 2g \
--driver-cores 2 \
--executor-memory 1g \
--total-executor-cores 2 \
hdfs://192.168.46.163:9000/home/dinpay/RCP-HZ-TASK-0.0.1-SNAPSHOT.jar
如果代码中限定了.setMaster("local[2]");
则提交方式还是本地模式,会找一台worker进行本地化运行任务
spark-submit提交方式测试Demo的更多相关文章
- Spark(五)Spark任务提交方式和执行流程
一.Spark中的基本概念 (1)Application:表示你的应用程序 (2)Driver:表示main()函数,创建SparkContext.由SparkContext负责与ClusterMan ...
- <input type = "submit"> 提交方式和用js的form.submit()有什么区别?
假设: A表单内有<input type="submit">,通过点击这个input来提交表单 B表单内没有<input type="submit&qu ...
- spark下使用submit提交任务后报jar包已存在错误
使用spark submit进行任务提交,离线跑数据,提交后的一段时间内可以application可以正常运行.过了一段时间后,就抛出以下错误: org.apache.spark.SparkExcep ...
- 【原创】大数据基础之Spark(1)Spark Submit即Spark任务提交过程
Spark2.1.1 一 Spark Submit本地解析 1.1 现象 提交命令: spark-submit --master local[10] --driver-memory 30g --cla ...
- Spark Standalone与Spark on YARN的几种提交方式
不多说,直接上干货! Spark Standalone的几种提交方式 别忘了先启动spark集群!!! spark-shell用于调试,spark-submit用于生产. 1.spark-shell ...
- 请写出一段表单提交的HTML代码,表单名称为form1,提交方式为post,提交地址为submit.asp
请写出一段表单提交的HTML代码,表单名称为form1,提交方式为post,提交地址为submit.asp 解答: <form name=”form1” method=”post” action ...
- form表单提交三种方式,demo实例详解
第一种:使用type=submit 可以直接提交 <html> <head> <title>submit直接提交</title> </head& ...
- form表单的两种提交方式,submit和button的用法
1.当输入用户名和密码为空的时候,需要判断.这时候就用到了校验用户名和密码,这个需要在jsp的前端页面写:有两种方法,一种是用submit提交.一种是用button提交.方法一: 在jsp的前端页面的 ...
- 触发form表单的两种提交方式,submit和button的用法
1.当输入用户名和密码为空的时候,需要判断.这时候就用到了校验用户名和密码,这个需要在jsp的前端页面写:有两种方法,一种是用submit提交.一种是用button提交. 方法一: 在jsp的前端页面 ...
随机推荐
- PostgreSQL 如何优化索引效率
使用 gin() 创建全文索引后,虽然有走索引,但是当结果集很大时,查询效率还是很底下, SELECT keyword,avg_mon_search,competition,impressions,c ...
- Selenium - WebDriver Advanced Usage
Explicit Waits # Python from selenium import webdriver from selenium.webdriver.common.by import By f ...
- ls 的顺序与倒序排列
linux 中文件夹的文件按照时间倒序或者升序排列 1,按照时间升序 ls -lrt -l use a long listing format 以长列表方式显示(详细信息方式) -t sort by ...
- nodejs、yarn编译安装
yarn和npm一样,是nodejs的一个依赖管理工具 1.安装nodejs 如果缺少c++ compiler 会报错 yum install -y gcc gcc-c++ 安装nodejs V8 ...
- 【bzoj2529】[Poi2011]Sticks 贪心
题目描述 给出若干木棍,每根木棍有特定的颜色和长度.问能否找到三条颜色不同的木棍构成一个三角形.(注意这里所说的三角形面积要严格大于0) 输入 第一行给出一个整数k(3<=k<=50),表 ...
- pat 团体天梯赛 L2-001. 紧急救援
L2-001. 紧急救援 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 作为一个城市的应急救援队伍的负责人,你有一张特殊的全国 ...
- 【linux命令】lscpu,/etc/cpuinfo详解
lscpu 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 i2000:~ # lscpu Architecture: ...
- eclipse去除所有调试断点 (转)
今天调试的时候发现之前加了太多断点,想去除所有断点,才想起来一直都没有使用过这个功能,放狗搜了一下,很快找到,记录一下. 方法一: 在工作界面,点window菜单栏,选中Preperences,在Ge ...
- i2c 协议解析【转】
转自:http://blog.csdn.net/g_salamander/article/details/8016698 版权声明:本文为博主原创文章,未经博主允许不得转载. 1.基本概念 主机 ...
- Ubuntu 14.04 x64配置Android 4.4 kitkat编译环境的方法
Ubuntu 14.04 x64配置Android 4.4 kitkat编译环境的方法跟Ubuntu 12.04 - 13.10 以及jellybean编译环境配置没多大区别, 顺便记录下而已: Ub ...