spark提交任务端口占用异常

当在同一台机器上提交多个spark任务时 并且是以client的方式提交,会报端口占用错误

17/05/05 15:51:07 WARN AbstractLifeCycle: FAILED org.spark-project.jetty.server.Server@3c8bdd5b: java.net.BindException: Address already in use
java.net.BindException: Address already in use
	at sun.nio.ch.Net.bind0(Native Method)
	at sun.nio.ch.Net.bind(Net.java:433)
	at sun.nio.ch.Net.bind(Net.java:425)
	at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
	at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
	at org.spark-project.jetty.server.nio.SelectChannelConnector.open(SelectChannelConnector.java:187)
	at org.spark-project.jetty.server.AbstractConnector.doStart(AbstractConnector.java:316)
	at org.spark-project.jetty.server.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:265)
	at org.spark-project.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
	at org.spark-project.jetty.server.Server.doStart(Server.java:293)
	at org.spark-project.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
	at org.apache.spark.ui.JettyUtils$.org$apache$spark$ui$JettyUtils$$connect$1(JettyUtils.scala:237)
	at org.apache.spark.ui.JettyUtils$$anonfun$3.apply(JettyUtils.scala:247)
	at org.apache.spark.ui.JettyUtils$$anonfun$3.apply(JettyUtils.scala:247)
	at org.apache.spark.util.Utils$$anonfun$startServiceOnPort$1.apply$mcVI$sp(Utils.scala:1920)
	at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:141)
	at org.apache.spark.util.Utils$.startServiceOnPort(Utils.scala:1911)
	at org.apache.spark.ui.JettyUtils$.startJettyServer(JettyUtils.scala:247)
	at org.apache.spark.ui.WebUI.bind(WebUI.scala:136)
	at org.apache.spark.SparkContext$$anonfun$13.apply(SparkContext.scala:474)
	at org.apache.spark.SparkContext$$anonfun$13.apply(SparkContext.scala:474)
	at scala.Option.foreach(Option.scala:236)
	at org.apache.spark.SparkContext.(SparkContext.scala:474)
	at com.fangdd.data.recommender.utils.SparkUtil$.getSparkContext(SparkUtil.scala:25)
	at com.fangdd.data.recommender.strategy.contentbase.ContentBasedI2URecommenderLoupan$.main(ContentBasedI2URecommenderLoupan.scala:63)
	at com.fangdd.data.recommender.strategy.contentbase.ContentBasedI2URecommenderLoupan.main(ContentBasedI2URecommenderLoupan.scala)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:685)
	at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:180)
	at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:205)
	at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:120)
	at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

Spark任务都会绑定一个端口来显示WebUI,默认端口为4040,如果被占用则依次递增+1端口重试,重试次数由参数spark.port.maxRetries=16控制,默认重试16次后就放弃执行

spark.port.maxRetries 16 Maximum number of retries when binding to a port before giving up. When a port is given a specific value (non 0), each subsequent retry will increment the port used in the previous attempt by 1 before retrying. This essentially allows it to try a range of ports from the start port specified to port + maxRetries.
初始化参数方式
1. 程序代码中初始化SparkConf时,设置conf.set(“spark.port.maxRetries”,“128”)
2. 使用spark-submit提交任务时,--conf spark.port.maxRetries=128
3. 在全局的spark-defaults.conf中添加spark.port.maxRetries 128 , 对所有的application起作用

参考配置文档:https://spark.apache.org/docs/1.6.3/configuration.html

你可能感兴趣的:(spark)