SPARK Configuration 参数配置表,有能力的请直接看原文
spark.apache.org/docs/2.3.2/…
Spark Streaming
| 名称 | 默认 | 含义 |
|---|
spark.streaming.backpressure.enabled | false | 启用或禁用Spark Streaming的内部背压机制(自1.5起)。这使Spark Streaming能够根据当前的批处理调度延迟和处理时间来控制接收速率,以便系统只接收系统可以处理的速度。在内部,这动态地设置接收器的最大接收速率。这个速率的上限取决于值spark.streaming.receiver.maxRate,spark.streaming.kafka.maxRatePerPartition如果设置了它们(见下文)。 |
spark.streaming.backpressure.initialRate | false | 这是在启用背压机制时每个接收器将接收第一批数据的初始最大接收速率。 |
spark.streaming.blockInterval | 200毫秒 | Spark Streaming接收器接收的数据在存储到Spark之前被分块为数据块的时间间隔。建议最低 - 50毫秒。有关更多详细信息,请参阅Spark Streaming编程指南中的 性能调整部分。 |
spark.streaming.receiver.maxRate | false | 每个接收器将接收数据的最大速率(每秒记录数)。实际上,每个流每秒最多将消耗此数量的记录。将此配置设置为0或负数将对速率没有限制。有关 模式详细信息,请参阅Spark Streaming编程指南中的部署指南 |
spark.streaming.receiver.writeAheadLog.enable | false | 启用接收器的预写日志。通过接收器接收的所有输入数据将被保存到提前写入日志,以便在驱动程序失败后恢复。有关 更多详细信息,请参阅Spark Streaming编程指南中的部署指南 |
spark.streaming.unpersist | true | Spark Streaming生成并持久化的强制RDD将自动从Spark的内存中取消。Spark Streaming接收的原始输入数据也会自动清除。将此设置为false将允许原始数据和持久RDD在流应用程序外部可访问,因为它们不会自动清除。但它的代价是Spark中更高的内存使用量。 |
spark.streaming.stopGracefullyOnShutdown | false | 如果true,Spark StreamingContext在JVM关闭时优先关闭而不是立即关闭。 |
spark.streaming.kafka.maxRatePerPartition | false | 使用新Kafka直接流API时从每个Kafka分区读取数据的最大速率(每秒记录数)。有关详细信息,请参阅 Kafka集成指南 |
spark.streaming.kafka.maxRetries | 1 | 驱动程序为了在每个分区的leader上找到最新偏移量而进行的最大连续重试次数(默认值为1表示驱动程序最多会尝试2次)。仅适用于新的Kafka直接流API。 |
spark.streaming.ui.retainedBatches | 1000 | 在垃圾收集之前,Spark Streaming UI和状态API记住了多少批次。 |
spark.streaming.driver.writeAheadLog.closeFileAfterWrite | false | 是否在驱动程序上写入先写日志记录后关闭文件。如果要将S3(或任何不支持刷新的文件系统)用于驱动程序上的元数据WAL,请将此项设置为“true”。 |
spark.streaming.receiver.writeAheadLog.closeFileAfterWrite | false | 是否在接收器上写入写入日志记录后关闭文件。如果要将S3(或任何不支持刷新的文件系统)用于接收器上的数据WAL,请将此项设置为“true”。 |
Application Properties
| 属性 | 默认值 | 描述 |
|---|
| spark.app.name | (none) | 应用程序的名称,会在日志和webUI显示 |
| spark.driver.cores | 1 | driver程序占用的CPU核数,只在cluster模式下有小。 |
| spark.driver.maxResultSize | 1g | 对Spark每个action结果集大小的限制,最少是1M,若设为0则不限制大小。若Job结果超过限制则会异常退出,若结果集限制过大也可能造成OOM问题。 |
| spark.driver.memory | 1g | driver进程可用的内存。注意:不能在代码中配置,因为此时driver已经启动,可以通过–driver-memory命令行参数或者配置文件进行配置。 |
| spark.executor.memory | 1g | 每个executor可用的内存数量 (e.g. 2g, 8g). |
| spark.extraListeners | (none) | 一系列实现SparkListener的类,spark监听总线会创建这些类的实例。 |
| spark.local.dir | /tmp | 用于存储mpp输出文件和RDD缓存文件,常配置在SSD等存储设备上,可以通过逗号分隔指定多个目录。 注意: 在Spark 1.0 后续版本,会被SPARK_LOCAL_DIRS (Standalone, Mesos) or LOCAL_DIRS (YARN) 环境变量覆盖. |
| spark.logConf | false | 将SparkConf 的有效配置作为INFO进行记录 |
| spark.master | (none) | 集群master节点 |
运行时环境
| 属性 | 默认值 | 描述 |
|---|
| spark.driver.userClassPathFirst | false | 用户指定的jars优先于Spark的库。用于解决用户与环境的版本冲突 |
| spark.executor.logs.rolling.maxRetainedFiles | (none) | 系统保留日志的最大数量,当超限时,旧的日志被删除,默认不启动 |
| spark.executor.logs.rolling.time.interval | daily | 设置日志rolling时间间隔,默认rolling不启动 |
| spark.executor.userClassPathFirst | false | executor执行时,用户指定的jars优先于Spark的库。用于解决用户与环境的版本冲突 |
| spark.python.worker.memory | 512m | 每个worker进程在聚集时的内存上限,若超限则输出到硬盘 |
Shuffle 行为
| 属性 | 默认值 | 描述 |
|---|
| spark.reducer.maxSizeInFlight | 48m | 多个reduce任务从map输出获取结果的最大尺寸。由于每个reducer需要创建缓存保留数据,除非内存很大,一般不要修改此参数 |
| spark.shuffle.compress | true | 是否对map的输出结果进行压缩,压缩器为spark.io.compression.codec |
| spark.shuffle.file.buffer | 32k | 每个shuffle文件输出流的内存缓存区大小。这些缓冲区减少了系统IO的调用次数 |
| spark.shuffle.manager | sort | shuffle数据的实现方法,包括sort和hash两种。sort内存利用率更改,从1.2版本后sort作为默认实现方法 |
| spark.shuffle.service.enabled | false | 激活外部shuffle服务。服务维护executor写的文件,因而executor可以被安全移除。需要设置spark.dynamicAllocation.enabled 为true,同事指定外部shuffle服务。 |
| spark.shuffle.service.port | 7337 | 默认的外部shuffle服务端口 |
| spark.shuffle.sort.bypassMergeThreshold | 200 | 用于设置在Reducer的partition数目少于多少的时候,Sort Based Shuffle内部不使用Merge Sort的方式处理数据,而是直接将每个partition写入单独的文件。这个方式和Hash Based的方式是类似的,区别就是在最后这些文件还是会合并成一个单独的文件,并通过一个index索引文件来标记不同partition的位置信息。从Reducer看来,数据文件和索引文件的格式和内部是否做过Merge Sort是完全相同的。这个可以看做SortBased Shuffle在Shuffle量比较小的时候对于Hash Based Shuffle的一种折衷。当然了它和Hash Based Shuffle一样,也存在同时打开文件过多导致内存占用增加的问题。因此如果GC比较严重或者内存比较紧张,可以适当的降低这个值。 |
| spark.shuffle.spill.compress | true | 若为true,代表处理的中间结果在spill到本地硬盘时都会进行压缩,在将中间结果取回进行merge的时候,要进行解压。在Disk IO成为瓶颈的场景下,这个被设置为true可能比较合适;如果本地硬盘是SSD,那么这个设置为false可能比较合适。 |
Spark UI
| 属性 | 默认值 | 描述 |
|---|
| spark.eventLog.compress | false | 是否压缩事务日志,当spark.eventLog.enabled为true时有效 |
| spark.eventLog.dir | file:///tmp/spark-events | 记录event日志的目录,也可以是hdfs目录 |
| spark.eventLog.enabled | false | 是否记录Spark events,用于在应用执行完后重建Web UI |
| spark.eventLog.enabled | true | 是否允许通过web UI kill掉stages和相关的job |
| spark.ui.port | 4040 | 应用统计信息的端口 |
| spark.ui.retainedJobs | 1000 | spark UI和status APIs在垃圾回收之前记录的任务数 |
| spark.ui.retainedStages | 1000 | spark UI和status APIs在垃圾回收之前记录的Stage数 |
| spark.worker.ui.retainedExecutors | 1000 | spark UI和status APIs在垃圾回收之前记录的executor数目 |
| spark.worker.ui.retainedDrivers | 1000 | 同上 |
| spark.worker.ui.retainedExecutions | 1000 | 同上 |
| spark.worker.ui.retainedBatches | 1000 | 同上 |
压缩和序列化
| 属性 | 默认值 | 描述 |
|---|
| spark.broadcast.compress | true | 广播变量是否被压缩 |
| spark.closure.serializer | org.apache.spark.serializer.JavaSerializer | 闭包的序列化类,目前只支持java序列化 |
| spark.io.compression.codec | snappy | 内部数据RDD的压缩编码器,用于RDD、广播变量和shuffle数据压缩。支持三种编码器:lz4、lzf和snappy。 |
| spark.io.compression.lz4.blockSize | 32k | 压缩块大小 |
| spark.io.compression.snappy.blockSize | 32k | 压缩块大小 |
| spark.kryo.classesToRegister | (none) | 若使用kryo序列化,本参数指定需要注册的自定义类 |
| spark.kryo.referenceTracking | true(false when using Spark SQL Thrift Server) | 序列化时是否使用相同的对象,若对象图谱中包含同一对象的多个副本,会提高性能。若不存在该情况,关闭可以提高性能 |
| spark.kryo.registrationRequired | false | 是否需要kry注册,若为true,在序列化未注册的类时kryo会抛出异常;若为false,对于未注册的类,kryo会在每个对象写入类名,降低了性能。 |
| spark.kryo.registrator | (none) | 指定自定义的kryo注册类 |
| spark.kryoserializer.buffer.max | 64m | kryo序列化的缓冲区大小,需要比所有序列化对象大 |
| spark.kryoserializer.buffer | 64k | 初始化的序列化缓冲区,可以根据需要增长到spark.kryoserializer.buffer.max |
| spark.rdd.compress | false | 是否序列化RDD分区,能通过耗费大量CPU降低存储空间 |
| spark.serializer | org.apache.spark.serializer.JavaSerializer | 序列化对象的类,建议使用org.apache.spark.serializer.KryoSerializer |
| spark.serializer.objectStreamReset | 100 | 当序列化对象时,为了减少IO会缓存大量数据,然而这会阻止垃圾回收,可以通过reset将刷新缓冲区。 |
内存管理
| 属性 | 默认值 | 描述 |
|---|
| spark.memory.fraction | 0.75 | 用于执行和存储的内存比例。值越小,计算内存越小,缓冲区数据被排除的可能越大。这个比例剩余的部分用于存储spark元数据、用户数据结构,最好使用默认值。 |
| spark.memory.storageFraction | 0.5 | 在存储和计算内存中,缓存所占的内存比例,值越大,计算可用内存越少。 |
| spark.memory.offHeap.enabled | false | 若为true,则spark会尝试使用堆外内存,同时要求spark.memory.offHeap.size必须是正数 |
| spark.memory.offHeap.size | 0 | 堆外内存可用的字节数 |
| spark.memory.useLegacyMode | false | 是否可以使用传统内存管理。本参数为true时,以下参数(已废弃)才有效:spark.shuffle.memoryFraction spark.storage.memoryFraction spark.storage.unrollFraction |
执行操作
| 属性 | 默认值 | 描述 |
|---|
| spark.broadcast.blockSize | 4m | TorrentBroadcastFactory中每个block的大小。若值太大会降低广播的并行度,若值太小则可能出现BlockManager瓶颈 |
| spark.broadcast.factory | org.apache.spark.broadcast.TorrentBroadcastFactory | 广播的实现 |
| spark.cleaner.ttl | (infinite) | spark记忆元数据的时间。若超时则清理,用于长时间运行例如spark stream应用,需要注意被缓存的RDD超时也会被清理。 |
| spark.executor.cores | 在Yarn是1;standalone中是所有可用的core | 每个executor可用的CPU核心数目,standalone模式下,每个worker会每个executor使用一个CPU核心 |
| spark.default.parallelism | 对于reduceByKey和join操作,是RDD中最大分区数;对于parallelize操作,分区数与集群管理相关:本地模式(CPU核心数作为分区数)、Mesos(8)、其他(所有执行器的核心数与2求最大值) | 默认的并行数 |
| spark.executor.heartbeatInterval | 10s | executor与driver的心跳间隔 |
| spark.files.fetchTimeout | 60s | SparkContext.addFile的超时值 |
| spark.files.useFetchCache | true | 若为true,同一应用的执行器间通过局部缓存优化;若为false则各个executor获取各自文件 |
| spark.files.overwrite | false | 当目标文件存在时是否重写 |
| spark.hadoop.cloneConf | false | 若为true,则为每个task拷贝hadoop的配置对象; |
| spark.hadoop.validateOutputSpecs | true | 若设置为true,saveAsHadoopFile会验证输出目录是否存在。虽然设为false可以忽略文件存在的异常,但建议使用Hadoop文件系统的API手动删除输出目录。当通过Spark Streaming的StreamingContext时本参数会被忽略,因为当进行checkpoint恢复时会重写已经存在的文件。 |
| spark.storage.memoryMapThreshold | 2m | 读取文件块时Spark内存map最小的大小。当map所占内存接近或小于操作系统page大小时,内存映射负载很大 |
| spark.externalBlockStore.blockManager | org.apache.spark.storage.TachyonBlockManager | 存储RDDs的外部文件块管理器。文件系统的URL被设置为spark.externalBlockStore.url |
| spark.externalBlockStore.baseDir | System.getProperty(“java.io.tmpdir”) | 外部块存储RDD的目录。文件系统URL被设置为spark.externalBlockStore.url |
| spark.externalBlockStore.url | tachyon://localhost:19998 for Tachyon | 代表外部块文件系统的URL |
网络
| 属性 | 默认值 | 描述 |
|---|
| spark.akka.frameSize | 128 | 最大消息大小(MB)。一般用于限制executor与driver之间的信息大小,若运行几千个map和reduce任务,可以适当调大参数 |
| spark.akka.heartbeat.interval | 1000s | 可以调成很大,用于禁止Akka内部的传输失败检测。越大的时间间隔减少网络负载,越小的间隔容易进行Akka错误检测。 |
| spark.akka.heartbeat.pauses | 6000s | 与spark.akka.heartbeat.interval类似 |
| spark.akka.threads | 4 | actor用于传输的线程个数。当driver有较多CPU是可以调大该值 |
| spark.akka.timeout | 100s | spark节点间沟通的超时时间 |
| spark.blockManager.port | random | block 管理器的监听端口 |
| spark.broadcast.port | random | driver的http广播监听端口 |
| spark.driver.host | (local hostname) | driver监听的主机名或者IP地址。用于master和executor的信息传输 |
| spark.driver.port | random | driver监听的接口 |
| spark.executor.port | random | executor监听的端口 |
| spark.fileserver.port | random | driver 文件服务监听的接口 |
| spark.network.timeout | 120s | 默认所有网络交互的超时时间 |
| spark.port.maxRetries | 16 | 端口重试连接最大次数 |
| spark.replClassServer.port | random | driver类服务监听的接口 |
| spark.rpc.numRetries | 3 | RPC任务重试的次数 |
| spark.rpc.retry.wait | 3s | RPC任务ask操作的延时 |
| spark.rpc.askTimeout | 120s | RPC任务等待超时 |
| spark.rpc.lookupTimeout | 120s | RPC远程lookup操作超时时间 |
作业调度Scheduling
| 属性 | 默认值 | 描述 |
|---|
| spark.cores.max | (not set) | spark应用可用最大CPU内核数,若未设置,stanalone集群使用 spark.deploy.defaultCores作为参数,Mesos可以使用所有CPU。 |
| spark.locality.wait | 3s | data-local或less-local任务启动任务超时时间。若任务时间长且数据不再本地,则最后调大 |
| spark.locality.wait.node | spark.locality.wait | Customize the locality wait for node locality. For example, you can set this to 0 to skip node locality and search immediately for rack locality (if your cluster has rack information). |
| spark.locality.wait.process | spark.locality.wait | Customize the locality wait for process locality. This affects tasks that attempt to access cached data in a particular executor process. |
| spark.locality.wait.rack | spark.locality.wait | Customize the locality wait for rack locality. |
| spark.scheduler.maxRegisteredResourcesWaitingTime | 30s | Maximum amount of time to wait for resources to register before scheduling begins. |
| spark.scheduler.mode | FIFO | 作业调度模式。可以设置为FAIR公平调度或者FIFO先进先出 |
| spark.scheduler.revive.interval | 1s | The interval length for the scheduler to revive the worker resource offers to run tasks. |
| spark.speculation | false | 若设置为true,则会根据执行慢的stage多次启动,以最先完成为准。 |
| spark.speculation.interval | 100ms | speculate 的频率 |
| spark.speculation.multiplier | 1.5 | 当task比所有任务执行时间的中值长多少倍时启动speculate |
| spark.speculation.quantile | 0.75 | 启动speculate前任务完成数据量所占比例值 |
| spark.task.cpus | 1 | 每个task分配的cpu数量 |
| spark.task.maxFailures | 4 | task失败的最多次数,比重试次数多1 |
动态分配内存
| 属性 | 默认值 | 描述 |
|---|
| spark.dynamicAllocation.enabled | false | 是否启动动态资源分配 |
| spark.dynamicAllocation.executorIdleTimeout | 60s | 若动态分配设为true且executor处于idle状态的时间已超时,则移除executor |
| spark.dynamicAllocation.cachedExecutorIdleTimeout | infinity | 若executor缓存数据超时,且动态内存分配为true,则移除缓存 |
| spark.dynamicAllocation.initialExecutors | spark.dynamicAllocation.minExecutors | 若动态分配为true,执行器的初始数量 |
| spark.dynamicAllocation.maxExecutor | infinity | 执行器最大数量 |
| spark.dynamicAllocation.minExecutor | 0 | 执行器最少数量 |
| spark.dynamicAllocation.schedulerBacklogTimeout | 1s | If dynamic allocation is enabled and there have been pending tasks backlogged for more than this duration, new executors will be requested. |
| spark.dynamicAllocation.sustainedSchedulerBacklogTimeout | schedulerBacklogTimeout | Same as spark.dynamicAllocation.schedulerBacklogTimeout, but used only for subsequent executor requests. |
安全
| 属性 | 默认值 | 描述 |
|---|
| spark.acls.enable | false | Whether Spark acls should are enabled. If enabled, this checks to see if the user has access permissions to view or modify the job. Note this requires the user to be known, so if the user comes across as null no checks are done. Filters can be used with the UI to authenticate and set the user. |
| spark.admin.acls | Empty | Comma separated list of users/administrators that have view and modify access to all Spark jobs. This can be used if you run on a shared cluster and have a set of administrators or devs who help debug when things work. Putting a “*” in the list means any user can have the priviledge of admin. |
| spark.authenticate | false | Whether Spark authenticates its internal connections. See spark.authenticate.secret if not running on YARN. |
| spark.authenticate.secret | None | Set the secret key used for Spark to authenticate between components. This needs to be set if not running on YARN and authentication is enabled. |
| spark.authenticate.enableSaslEncryption | false | Enable encrypted communication when authentication is enabled. This option is currently only supported by the block transfer service. |
| spark.network.sasl.serverAlwaysEncrypt | false | Disable unencrypted connections for services that support SASL authentication. This is currently supported by the external shuffle service. |
| spark.core.connection.ack.wait.timeout | 60s | How long for the connection to wait for ack to occur before timing out and giving up. To avoid unwilling timeout caused by long pause like GC, you can set larger value. |
| spark.core.connection.auth.wait.timeout | 30s | How long for the connection to wait for authentication to occur before timing out and giving up. |
| spark.modify.acls | Empty | Comma separated list of users that have modify access to the Spark job. By default only the user that started the Spark job has access to modify it (kill it for example). Putting a “*” in the list means any user can have access to modify it. |
| spark.ui.filters | None | Comma separated list of filter class names to apply to the Spark web UI. The filter should be a standard javax servlet Filter. Parameters to each filter can also be specified by setting a java system property of:spark..params=’param1=value1,param2=value2’For example:-Dspark.ui.filters=com.test.filter1 -Dspark.com.test.filter1.params=’param1=foo,param2=testing’ |
| spark.ui.view.acls | Empty | Comma separated list of users that have view access to the Spark web ui. By default only the user that started the Spark job has view access. Putting a “*” in the list means any user can have view access to this Spark job. |
加密Encryption
| 属性 | 默认值 | 描述 |
|---|
| spark.ssl.enabled | false | 是否在所有协议中支持SSL连接 |
| spark.ssl.enabledAlgorithms | Empty | 一些列的密码运算,指定的cipher需要被JVM支持 |
| spark.ssl.keyPassword | None | 私钥密码 |
| spark.ssl.keyStore | None | key存储文件,可以是组件启动的相对路径也可以是绝对路径 |
| spark.ssl.keyStorePassword | None | A password to the key-store |
| spark.ssl.protocol | None | A protocol name. The protocol must be supported by JVM. The reference list of protocols one can find on this page. |
| spark.ssl.trustStore | None | A path to a trust-store file. The path can be absolute or relative to the directory where the component is started in. |
| spark.ssl.trustStorePassword | None | A password to the trust-store. |
Deploy
| Property Name | Default | Meaning |
|---|
spark.deploy.recoveryMode | NONE | 恢复模式设置,用于在失败并重新启动时使用群集模式恢复提交的Spark作业。这仅适用于使用Standalone或Mesos运行时的群集模式。 |
spark.deploy.zookeeper.url | None | 当spark.deploy.recoveryMode设置为ZOOKEEPER时,此配置用于设置要连接的zookeeper URL。 |
spark.deploy.zookeeper.dir | None | 当spark.deploy.recoveryMode设置为ZOOKEEPER时,此配置用于将zookeeper目录设置为存储恢复状态。 |