Spark常见错误汇总
1. Spark Driver cannot bind on port0, SparkContext initialized failed
如果是通过spark-submit等命令行提交的任务,在spark的conf目录下,修改spark-env.sh(如果没有此文件,从spark-env-template.sh拷贝一份),添加 export SPARK_LOCAL_IP=127.0.0.1即可
如果是通过Idea等IDE来提交任务,调试,运行的时候,修改/etc/hosts, 添加或修改机器名对应的ip地址,比如 127.0.0.1 hostname
2. 连接mesos的时候出现 No credentials provided. Attempting to register without authentication 一直卡住不动
检查mesos的ip是否正确,检查本机的hostname对应的ip地址是否正确,不能是127.0.0.1,client与mesos需要能互相访问,如果有一方不能访问另一方,就会卡住
3. Java.lang.IllegalArgumentException: System memory 468189184 must be at least 4.718592E8. Please use a larger heap size.
通过查看spark源码,发现源码是这么写的:
- /**
- * Return the total amount of memory shared between execution and storage, in bytes.
- */
- private def getMaxMemory(conf: SparkConf): Long = {
- val systemMemory = conf.getLong("spark.testing.memory", Runtime.getRuntime.maxMemory)
- val reservedMemory = conf.getLong("spark.testing.reservedMemory",
- if (conf.contains("spark.testing")) 0 else RESERVED_SYSTEM_MEMORY_BYTES)
- val minSystemMemory = reservedMemory * 1.5
- if (systemMemory < minSystemMemory) {
- throw new IllegalArgumentException(s"System memory $systemMemory must " +
- s"be at least $minSystemMemory. Please use a larger heap size.")
- }
- val usableMemory = systemMemory - reservedMemory
- val memoryFraction = conf.getDouble("spark.memory.fraction", 0.75)
- (usableMemory * memoryFraction).toLong
- }
所以,这里主要是val systemMemory = conf.getLong("spark.testing.memory", Runtime.getRuntime.maxMemory)。
conf.getLong()的定义和解释是
- getLong(key: String, defaultValue: Long): Long
- Get a parameter as a long, falling back to a default if not set
所以,我们应该在conf里设置一下spark.testing.memory和spark.testing.reservedMemory
通过尝试,发现可以有2个地方可以设置
1. 自己的源代码处,可以在conf之后加上:
val conf = new SparkConf().setAppName("word count")
conf.set("spark.testing.memory", "2147480000")//后面的值大于512m即可
2. 可以在Eclipse的Run Configuration处,有一栏是Arguments,下面有VMarguments,在下面添加下面一行(值也是只要大于512m即可)
-Dspark.testing.memory=1073741824
其他的参数,也可以动态地在这里设置,比如-Dspark.master=spark://hostname:7077
再运行就不会报这个错误了。