Spark 配置指南

来源:互联网 发布:python update mysql 编辑:程序博客网 时间:2024/05/21 12:47

目录

  • 目录
  • 应用属性
  • 运行时环境Runtime Environment
  • Shuffle Behavior
  • Spark UI
  • Compression and Serialization
  • Execution Behavior
  • Networking
  • Scheduling
  • Security
  • Spark Streaming
  • 集群管理器Cluster Managers

1 应用属性

Spark属性控制应用的大部分设置, 可以为不同的应用分别设置. 这些属性在SparkConf对象上设置, SparkConf被传给SparkContext. SparkConf允许你配置一些通用的属性(比如master URL 和应用名), 也可以通过set() 方法设置键值对. 例如,我们可以这样初始化一个应用:

val conf = new SparkConf()             .setMaster("local")             .setAppName("CountingSheep")             .set("spark.executor.memory", "1g")val sc = new SparkContext(conf)
  • 动态加载Spark属性
    在一些情况下你可能想避免在SparkConf上硬编码. 举例来说, 如果你想在不同的master上或者不同的内存上运行同样的应用, Spark允许你简单创建一个空的conf:
val sc = new SparkContext(new SparkConf())

你可以在运行时提供这些配置值:

./bin/spark-submit --name "My app" --master local[4] --conf spark.shuffle.spill=false  --conf "spark.executor.extraJavaOptions=-XX:+PrintGCDetails -XX:+PrintGCTimeStamps" myApp.jar

Spark shell 和 spark-submit脚本支持两个动态加载配置的方法. 第一种是命令行参数, 如上面用到的 —master. spark-submit通过—conf可以接收任意的spark属性, 但会使用一些其它参数来启动Spark应用. 运行./bin/spark-submit —hp 会显示完整的参数列表.

bin/spark-submit会从conf/spark-defaults.conf读取缺省的配置参数, 每一行包括一个键和一个值, 由空格分隔. 比如下面的例子

spark.master            spark://5.6.7.8:7077spark.executor.memory   512mspark.eventLog.enabled  truespark.serializer        org.apache.spark.serializer.KryoSerialize

命令行参数和文件中配置的属性都会传给应用,由SparkConf合并这些配置. SparkConf上设置的属性有最高优先级,然后是命令行传入给spark-submit或spark-shell的参数, 最后才是缺省文件中配置的属性.

  • 查看Spark属性
    应用的web UI (http://:4040)在”Environment”标签页列出了所有的Spark属性. 这是一个很有用的页面,可以帮助你检查你的属性是否设置正确。 注意只有显式在spark-defaults.conf 或 SparkConf 设置的属性才显示。 其它的配置属性将使用缺省值。
  • 可用的属性
    大部分控制内部设置的属性都有合适的缺省值。一些常用的属性分门别类的列在这里:
属性名 缺省值 意义 spark.app.name (none) The name of your application. This will appear in the UI and in log data. spark.master (none) The cluster manager to connect to. See the list of allowed master URL’s. spark.executor.memory 512m Amount of memory to use per executor process, in the same format as JVM memory strings (e.g.512m,2g). spark.serializer org.apache.spark.serializer.JavaSerializer Class to use for serializing objects that will be sent over the network or need to be cached in serialized form. The default of Java serialization works with any Serializable Java object but is quite slow, so we recommendusingorg.apache.spark.serializer.KryoSerializer and configuring Kryo serialization when speed is necessary. Can be any subclass oforg.apache.spark.Serializer. spark.kryo.registrator (none) If you use Kryo serialization, set this class to register your custom classes with Kryo. It should be set to a class that extendsKryoRegistrator. spark.local.dir /tmp See thetuning guide for more dDirectory to use for “scratch” space in Spark, including map output files and RDDs that get stored on disk. This should be on a fast, local disk in your system. It can also be a comma-separated list of multiple directories on different disks. NOTE: In Spark 1.0 and later this will be overriden by SPARK_LOCAL_DIRS (Standalone, Mesos) or LOCAL_DIRS (YARN) environment variables set by the cluster manager. spark.logConf false Logs the effective SparkConf as INFO when a SparkContex

除了这些,下面的属性也可用,在某些情况下需要设置:

2 运行时环境Runtime Environment

属性名 缺省值 意义 spark.executor.extraJavaOptions (none) A string of extra JVM options to pass to executors. For instance, GC settings or other logging. Note that it is illegal to set Spark properties or heap size settings with this option. Spark properties should be set using a SparkConf object or the spark-defaults.conf file used with the spark-submit script. Heap size settings can be set with spark.executor.memory. spark.executor.extraClassPath (none) Extra classpath entries to append to the classpath of executors. This exists primarily for backwards-compatibility with older versions of Spark. Users typically should not need to set this option. spark.executor.extraLibraryPath (none) Set a special library path to use when launching executor JVM’s. spark.files.userClassPathFirst false user-added jars precedence over Spark’s own jars when loading classes in Executors. This feature can be used to mitigate conflicts between Spark’s dependencies and user dependencies. It is currently an experimental feature. spark.python.worker.memory 512m Amount of memory to use per python worker process during aggregation, in the same format as JVM memory strings (e.g.512m,2g). If the memory used during aggregation goes above this amount, it will spill the data into disks. spark.executorEnv.[EnvironmentVariableName] (none) Add the environment variable specified byEnvironmentVariableName to the Executor process. The user can specify multiple of these and to set multiple environment variables. spark.mesos.executor.home driver sideSPARK_HOME Set the directory in which Spark is installed on the executors in Mesos. By default, the executors will simply use the driver’s Spark home directory, which may not be visible to them. Note that this is only relevant if a Spark binary package is not specified throughspark.executor.uri spark.mesos.executor.memoryOverhead executor memory * 0.07, with minimum of 384 This value is an additive forspark.executor.memory, specified in MiB, which is used to calculate the total Mesos task memory. A value of384 implies a 384MiB overhead. Additionally, there is a hard-coded 7% minimum overhead. The final overhead will be the larger of either spark.mesos.executor.memoryOverhead or 7% of spark.executor.memory.

3 Shuffle Behavior

属性名 缺省值 意义 spark.shuffle.consolidateFiles false If set to “true”, consolidates intermediate files created during a shuffle. Creating fewer files can improve filesystem performance for shuffles with large numbers of reduce tasks. It is recommended to set this to “true” when using ext4 or xfs filesystems. On ext3, this option might degrade performance on machines with many (>8) cores due to filesystem limitations. spark.shuffle.spill true If set to “true”, limits the amount of memory used during reduces by spilling data out to disk. This spilling threshold is specified byspark.shuffle.memoryFraction. spark.shuffle.spill.compress true Whether to compress data spilled during shuffles. Compression will usespark.io.compression.codec. spark.shuffle.memoryFraction 0.2 Fraction of Java heap to use for aggregation and cogroups during shuffles, ifspark.shuffle.spill is true. At any given time, the collective size of all in-memory maps used for shuffles is bounded by this limit, beyond which the contents will begin to spill to disk. If spills are often, consider increasing this value at the expense ofspark.storage.memoryFraction. spark.shuffle.compress true Whether to compress map output files. Generally a good idea. Compression will usespark.io.compression.codec. spark.shuffle.file.buffer.kb 32 Size of the in-memory buffer for each shuffle file output stream, in kilobytes. These buffers reduce the number of disk seeks and system calls made in creating intermediate shuffle files. spark.reducer.maxMbInFlight 48 Maximum size (in megabytes) of map outputs to fetch simultaneously from each reduce task. Since each output requires us to create a buffer to receive it, this represents a fixed memory overhead per reduce task, so keep it small unless you have a large amount of memory. spark.shuffle.manager HASH Implementation to use for shuffling data. A hash-based shuffle manager is the default, but starting in Spark 1.1 there is an experimental sort-based shuffle manager that is more memory-efficient in environments with small executors, such as YARN. To use that, change this value toSORT. spark.shuffle.sort.bypassMergeThreshold 200 (Advanced) In the sort-based shuffle manager, avoid merge-sorting data if there is no map-side aggregation and there are at most this many reduce partitions.

4 Spark UI

属性名 缺省值 意义 spark.ui.port 4040 Port for your application’s dashboard, which shows memory and workload data. spark.ui.retainedStages 1000 How many stages the Spark UI remembers before garbage collecting. spark.ui.killEnabled true Allows stages and corresponding jobs to be killed from the web ui. spark.eventLog.enabled false Whether to log Spark events, useful for reconstructing the Web UI after the application has finished. spark.eventLog.compress false Whether to compress logged events, ifspark.eventLog.enabled is true. spark.eventLog.dir file:///tmp/spark-events Base directory in which Spark events are logged, ifspark.eventLog.enabled is true. Within this base directory, Spark creates a sub-directory for each application, and logs the events specific to the application in this directory. Users may want to set this to a unified location like an HDFS directory so history files can be read by the history server.

5 Compression and Serialization

属性名 缺省值 意义 spark.broadcast.compress true Whether to compress broadcast variabl spark.rdd.compress false Whether to compress serialized RDD partitions (e.g. forStorageLevel.MEMORY_ONLY_SER). Can save substantial space at the cost of some extra spark.io.compression.codec snappy The codec used to compress internal data such as RDD partitions and shuffle outputs. By default, Spark provides three codecs:lz4,lzf, andsnappy. You can also use fully qualified class names to specify the codec, e.g.org.apache.spark.io.LZ4CompressionCodec,org.apache.spark.io.LZFCompressionCodec, andorg.apache.spark.io.SnappyCompression spark.io.compression.snappy.block.size 32768 Block size (in bytes) used in Snappy compression, in the case when Snappy compression codec is used. Lowering this block size will also lower sh spark.io.compression.lz4.block.size 32768 Block size (in bytes) used in LZ4 compression, in the case when LZ4 compression codec is used. Lowering this block size will also lower shuf spark.closure.serializer org.apache.spark.serializer.

JavaSerializer|Serializer class to use for closures. Currently only |
|spark.serializer.objectStreamReset|100|When serializing using org.apache.spark.serializer.JavaSerializer, the serializer caches objects to prevent writing redundant data, however that stops garbage collection of those objects. By calling ‘reset’ you flush that info from the serializer, and allow old objects to be collected. To turn off this periodic reset set it to -1. By default it will re|
|spark.kryo.referenceTracking|true|Whether to track references to the same object when serializing data with Kryo, which is necessary if your object graphs have loops and useful for efficiency if they contain multiple copies of the same object. Can be disabled to improve performance if |
|spark.kryo.registrationRequired|false| Whether to require registration with Kryo. If set to ‘true’, Kryo will throw an exception if an unregistered class is serialized. If set to false (the default), Kryo will write unregistered class names along with each object. Writing class names can cause significant performance overhead, so enabling this option can enforce strictly that a user has not omi|
|spark.kryoserializer.buffer.mb|0.064| Initial size of Kryo’s serialization buffer, in megabytes. Note that there will be one bufferper core on each worker. This buffer will grow up tospark.k|
|spark.kryoserializer.buffer.max.mb|64|Maximum allowable size of Kryo serialization buffer, in megabytes. This must be larger than any object you attempt to serialize. Increase this if you get a “buffer limit exceeded” exception inside Kryo.|

6 Execution Behavior

属性名 缺省值 意义

7 Networking

8 Scheduling

9 Security

10 Spark Streaming

11 集群管理器Cluster Managers

0 0
原创粉丝点击