# Spark 配置
* [Spark 屬性](#spark-屬性)
* [動態加載 Spark 屬性](#動態加載-spark-屬性)
* [查看 Spark 屬性](#查看-spark-屬性)
* [可用屬性](#可用屬性)
* [應用程序屬性](#應用程序屬性)
* [運行環境](#運行環境)
* [Shuffle Behavior(Shuffle 行為)](#shuffle-behavior-shuffle-行為)
* [Spark UI](#spark-ui)
* [Compression and Serialization(壓縮和序列化)](#compression-and-serialization-壓縮和序列化)
* [Memory Management(內存管理)](#memory-management-內存管理)
* [Execution Behavior(執行行為)](#execution-behavior-執行行為)
* [Networking(網絡)](#networking-網絡)
* [Scheduling(調度)](#scheduling-調度)
* [Dynamic Allocation(動態分配)](#dynamic-allocation-動態分配)
* [Security(安全)](#security-安全)
* [TLS / SSL](#tls--ssl)
* [Spark SQL](#spark-sql)
* [Spark Streaming](#spark-streaming)
* [SparkR](#sparkr)
* [GraphX](#graphx)
* [Deploy(部署)](#deploy-部署)
* [Cluster Managers(集群管理器)](#cluster-managers-集群管理器)
* [](#yarn)[YARN](running-on-yarn.html#configuration)
* [](#mesos)[Mesos](running-on-mesos.html#configuration)
* [](#standalone-mode)[Standalone Mode](spark-standalone.html#cluster-launch-scripts)
* [Environment Variables(環境變量)](#environment-variables-環境變量)
* [Configuring Logging(配置 Logging)](#configuring-logging-配置-logging)
* [Overriding configuration directory(覆蓋配置目錄)](#overriding-configuration-directory-覆蓋配置目錄)
* [Inheriting Hadoop Cluster Configuration(繼承 Hadoop 集群配置)](#inheriting-hadoop-cluster-configuration-繼承-hadoop-集群配置)
Spark 提供了三個位置來配置系統:
* [Spark 屬性](#spark-properties) 控制著大多數應用參數,并且可以通過使用一個 [SparkConf](api/scala/index.html#org.apache.spark.SparkConf) 對象來設置,或者通過 Java 系統屬性來設置.
* [環境變量](#environment-variables) 可用于在每個節點上通過 `conf/spark-env.sh` 腳本來設置每臺機器設置,例如 IP 地址.
* [Logging](#configuring-logging) 可以通過 `log4j.properties` 來設置.
# Spark 屬性
Spark 屬性控制大多數應用程序設置,并為每個應用程序單獨配置。這些屬性可以直接在 [SparkConf](api/scala/index.html#org.apache.spark.SparkConf) 上設置并傳遞給您的 `SparkContext`。`SparkConf` 可以讓你配置一些常見的屬性(例如 master URL 和應用程序名稱),以及通過 `set()` 方法來配置任意 key-value pairs(鍵值對)。例如,我們可以使用兩個線程初始化一個應用程序,如下所示:
請注意,我們運行 local[2],意思是兩個線程 - 代表 “最小” 并行性,這可以幫助檢測在只存在于分布式環境中運行時的錯誤.
```
val conf = new SparkConf()
.setMaster("local[2]")
.setAppName("CountingSheep")
val sc = new SparkContext(conf)
```
注意,本地模式下,我們可以使用多個線程,而且在像 Spark Streaming 這樣的場景下,我們可能需要多個線程來防止任一類型的類似 starvation issues(線程餓死)這樣的問題。配置時間段的屬性應該寫明時間單位,如下格式都是可接受的:
```
25ms (milliseconds)
5s (seconds)
10m or 10min (minutes)
3h (hours)
5d (days)
1y (years)
```
指定 byte size(字節大小)的屬性應該寫明單位。如下格式都是可接受的:
```
1b (bytes)
1k or 1kb (kibibytes = 1024 bytes)
1m or 1mb (mebibytes = 1024 kibibytes)
1g or 1gb (gibibytes = 1024 mebibytes)
1t or 1tb (tebibytes = 1024 gibibytes)
1p or 1pb (pebibytes = 1024 tebibytes)
```
## 動態加載 Spark 屬性
在某些場景下,你可能想避免將屬性值寫死在 SparkConf 中。例如,你可能希望在同一個應用上使用不同的 master 或不同的內存總量。Spark 允許你簡單地創建一個空的 conf :
```
val sc = new SparkContext(new SparkConf())
```
然后在運行時設置這些屬性 :
```
./bin/spark-submit --name "My app" --master local[4] --conf spark.eventLog.enabled=false
--conf "spark.executor.extraJavaOptions=-XX:+PrintGCDetails -XX:+PrintGCTimeStamps" myApp.jar
```
Spark shell 和 [`spark-submit`](submitting-applications.html) 工具支持兩種動態加載配置的方法。第一種,通過命令行選項,如:上面提到的 `--master`。`spark-submit` 可以使用 `--conf` flag 來接受任何 Spark 屬性標志,但對于啟動 Spark 應用程序的屬性使用 special flags(特殊標志)。運行 `./bin/spark-submit --help` 可以展示這些選項的完整列表.
`bin/spark-submit` 也支持從 `conf/spark-defaults.conf` 中讀取配置選項,其中每行由一個 key(鍵)和一個由 whitespace(空格)分隔的 value(值)組成,如下:
```
spark.master spark://5.6.7.8:7077
spark.executor.memory 4g
spark.eventLog.enabled true
spark.serializer org.apache.spark.serializer.KryoSerializer
```
指定為 flags(標志)或屬性文件中的任何值都將傳遞給應用程序并與通過 SparkConf 指定的那些值 merge(合并)。屬性直接在 SparkConf 上設置采取最高優先級,然后 flags(標志)傳遞給 `spark-submit` 或 `spark-shell`,然后選項在 `spark-defaults.conf` 文件中。自從 Spark 版本的早些時候,一些 configuration keys(配置鍵)已被重命名 ; 在這種情況下,舊的 key names(鍵名)仍然被接受,但要比較新的 key 優先級都要低一些.
## 查看 Spark 屬性
在應用程序的 web UI `http://<driver>:4040` 中,“Environment” tab(“環境”選項卡)中列出了 Spark 的屬性。這是一個檢查您是否正確設置了您的屬性的一個非常有用的地方。注意,只有顯示地通過 `spark-defaults.conf`,`SparkConf` 或者命令行設置的值將會出現。對于所有其他配置屬性,您可以認為使用的都是默認值.
## 可用屬性
大多數控制 internal settings(內部設置)的屬性具有合理的默認值。一些常見的選項是:
### 應用程序屬性
| Property Name(屬性名稱)| Default(默認值)| Meaning(含義)|
| --- | --- | --- |
| `spark.app.name` | (none) | Spark 應用的名字。會在 SparkUI 和日志中出現。 |
| `spark.driver.cores` | 1 | 在 cluster 模式下,用幾個 core 運行 driver 進程。 |
| `spark.driver.maxResultSize` | 1g | Spark action 算子返回的結果集的最大數量。至少要 1M,可以設為 0 表示無限制。如果結果超過這一大小,Spark job 會直接中斷退出。但是,設得過高有可能導致 driver 出現 out-of-memory 異常(取決于 spark.driver.memory 設置,以及驅動器 JVM 的內存限制)。設一個合理的值,以避免 driver 出現 out-of-memory 異常。 |
| `spark.driver.memory` | 1g | driver進程可以使用的內存總量(例如:`1g`,`2g`)。注意,在 client 模式下,這個配置不能在 SparkConf 中直接設置,應為在那個時候 driver 進程的 JVM 已經啟動了。因此需要在命令行里用 --driver-memory 選項 或者在默認屬性配置文件里設置。 |
| `spark.executor.memory` | 1g | 每個 executor 進程使用的內存總量(例如,`2g`,`8g`)。Amount of memory to use per executor process (例如,`2g`,`8g`). |
| `spark.extraListeners` | (none) | 逗號分隔的實現 `SparkListener` 接口的類名列表;初始化 SparkContext 時,這些類的實例會被創建出來,并且注冊到 Spark 的監聽器上。如果這些類有一個接受 SparkConf 作為唯一參數的構造函數,那么這個構造函數會被調用;否則,就調用無參構造函數。如果沒有合適的構造函數,SparkContext 創建的時候會拋異常。 |
| `spark.local.dir` | /tmp | Spark 的”草稿“目錄,包括 map 輸出的臨時文件以及 RDD 存在磁盤上的數據。這個目錄最好在本地文件系統中。這個配置可以接受一個以逗號分隔的多個掛載到不同磁盤上的目錄列表。注意:Spark-1.0 及以后版本中,這個屬性會被 cluster manager 設置的環境變量覆蓋:SPARK_LOCAL_DIRS(Standalone,Mesos)或者 LOCAL_DIRS(YARN)。 |
| `spark.logConf` | false | SparkContext 啟動時是否把生效的 SparkConf 屬性以 INFO 日志打印到日志里。 |
| `spark.master` | (none) | 要連接的 cluster manager。參考 [Cluster Manager](submitting-applications.html#master-urls) 類型。 |
| `spark.submit.deployMode` | (none) | Spark driver 程序的部署模式,可以是 "client" 或 "cluster",意味著部署 dirver 程序本地("client")或者遠程("cluster")在 Spark 集群的其中一個節點上。 |
| `spark.log.callerContext` | (none) | Application information that will be written into Yarn RM log/HDFS audit log when running on Yarn/HDFS. Its length depends on the Hadoop configuration `hadoop.caller.context.max.size`. It should be concise, and typically can have up to 50 characters. |
| `spark.driver.supervise` | false | If true, restarts the driver automatically if it fails with a non-zero exit status. Only has effect in Spark standalone mode or Mesos cluster deploy mode. |
Apart from these, the following properties are also available, and may be useful in some situations:
### 運行環境
| Property Name(屬性名稱)| Default(默認值)| Meaning(含義)|
| --- | --- | --- |
| `spark.driver.extraClassPath` | (none) | 額外的classpath條目需預先添加到驅動程序 classpath中。注意:在客戶端模式下,這一套配置不能通過 SparkConf 直接在應用在應用程序中,因為 JVM 驅動已經啟用了。相反,請在配置文件中通過設置 --driver-class-path 選項或者選擇默認屬性。 |
| `spark.driver.extraJavaOptions` | (none) | 一些額外的 JVM 屬性傳遞給驅動。例如,GC 設置或其他日志方面設置。注意,設置最大堆大小(-Xmx)是不合法的。最大堆大小設置可以通過在集群模式下設置 `spark.driver.memory` 選項,并且可以通過`--driver-memory` 在客戶端模式設置。<br>_注意:_ 在客戶端模式下,這一套配置不能通過 `SparkConf` 直接應用在應用程序中,因為 JVM 驅動已經啟用了。相反,請在配置文件中通過設置 `--driver-java-options` 選項或者選擇默認屬性。 |
| `spark.driver.extraLibraryPath` | (none) | 當啟動 JVM 驅動程序時設置一個額外的庫路徑。<br>_注意:_ 在客戶端模式下,這一套配置不能通過 `SparkConf` 直接在應用在應用程序中,因為 JVM 驅動已經啟用了。相反,請在配置文件中通過設置 `--driver-library-path` 選項或者選擇默認屬性。 |
| `spark.driver.userClassPathFirst` | false |(實驗)在驅動程序加載類庫時,用戶添加的 Jar 包是否優先于 Spark 自身的 Jar 包。這個特性可以用來緩解沖突引發的依賴性和用戶依賴。目前只是實驗功能。這是僅用于集群模式。 |
| `spark.executor.extraClassPath` | (none) | 額外的類路徑要預先考慮到 executor 的 classpath。這主要是為與舊版本的 Spark 向后兼容。用戶通常不應該需要設置這個選項。 |
| `spark.executor.extraJavaOptions` | (none) | 一些額外的 JVM 屬性傳遞給 executor。例如,GC 設置或其他日志方面設置。注意,設置最大堆大小(-Xmx)是不合法的。Spark 應該使用 SparkConf 對象或 Spark 腳本中使用的 spark-defaults.conf 文件中設置。最大堆大小設置可以在 spark.executor.memory 進行設置。 |
| `spark.executor.extraLibraryPath` | (none) | 當啟動 JVM 的可執行程序時設置額外的類庫路徑。 |
| `spark.executor.logs.rolling.maxRetainedFiles` | (none) | 最新回滾的日志文件將被系統保留。舊的日志文件將被刪除。默認情況下禁用。 |
| `spark.executor.logs.rolling.enableCompression` | false | Enable executor log compression. If it is enabled, the rolled executor logs will be compressed. Disabled by default. |
| `spark.executor.logs.rolling.maxSize` | (none) | 設置最大文件的大小,以字節為單位日志將被回滾。默認禁用。見 `spark.executor.logs.rolling.maxRetainedFiles` 舊日志的自動清洗。 |
| `spark.executor.logs.rolling.strategy` | (none) | 設置 executor 日志的回滾策略。它可以被設置為 “時間”(基于時間的回滾)或 “大小”(基于大小的回滾)。對于 “時間”,使用 `spark.executor.logs.rolling.time.interval` 設置回滾間隔。用 `spark.executor.logs.rolling.maxSize` 設置最大文件大小回滾。 |
| `spark.executor.logs.rolling.time.interval` | daily | 設定的時間間隔,executor 日志將回滾。默認情況下是禁用的。有效值是`每天`,`每小時`,`每分鐘`或任何時間間隔在幾秒鐘內。見 `spark.executor.logs.rolling.maxRetainedFiles` 舊日志的自動清洗。 |
| `spark.executor.userClassPathFirst` | false |(實驗)與 `spark.driver.userClassPathFirst` 相同的功能,但適用于執行程序的實例。 |
| `spark.executorEnv.[EnvironmentVariableName]` | (none) | 通過添加指定的環境變量 `EnvironmentVariableName` 給 executor 進程。用戶可以設置多個環境變量。 |
| `spark.redaction.regex` | (?i)secret|password | Regex to decide which Spark configuration properties and environment variables in driver and executor environments contain sensitive information. When this regex matches a property key or value, the value is redacted from the environment UI and various logs like YARN and event logs. |
| `spark.python.profile` | false | 啟用在 python 中的 profile。結果將由 `sc.show_profiles()` 顯示,或者它將會在驅動程序退出后顯示。它還可以通過 `sc.dump_profiles(path)` dump 到磁盤。如果一些 profile 文件的結果已經顯示,那么它們將不會再驅動程序退出后再次顯示。默認情況下,`pyspark.profiler.BasicProfiler` 將被使用,但這可以通過傳遞一個 profile 類作為一個參數到 `SparkContext` 中進行覆蓋。 |
| `spark.python.profile.dump` | (none) | 這個目錄是在驅動程序退出后,proflie 文件 dump 到磁盤中的文件目錄。結果將為每一個 RDD dump 為分片文件。它們可以通過 ptats.Stats() 加載。如果指定,profile 結果將不會自動顯示。 |
| `spark.python.worker.memory` | 512m | 在聚合期間,每個python工作進程使用的內存量,與JVM內存條(例如:`512m`,`2g`)格式相同。如果在聚合過程中使用的內存高于此數量,則會將數據溢出到磁盤中。 |
| `spark.python.worker.reuse` | true | 重用 python worker。如果為 true,它將使用固定數量的 worker 數量。不需要為每一個任務分配 python 進程。如果是大型的這將是非常有用。 |
| `spark.files` | | Comma-separated list of files to be placed in the working directory of each executor. |
| `spark.submit.pyFiles` | | Comma-separated list of .zip, .egg, or .py files to place on the PYTHONPATH for Python apps. |
| `spark.jars` | | Comma-separated list of local jars to include on the driver and executor classpaths. |
| `spark.jars.packages` | | Comma-separated list of Maven coordinates of jars to include on the driver and executor classpaths. The coordinates should be groupId:artifactId:version. If `spark.jars.ivySettings` is given artifacts will be resolved according to the configuration in the file, otherwise artifacts will be searched for in the local maven repo, then maven central and finally any additional remote repositories given by the command-line option `--repositories`. For more details, see [Advanced Dependency Management](submitting-applications.html#advanced-dependency-management). |
| `spark.jars.excludes` | | Comma-separated list of groupId:artifactId, to exclude while resolving the dependencies provided in `spark.jars.packages` to avoid dependency conflicts. |
| `spark.jars.ivy` | | Path to specify the Ivy user directory, used for the local Ivy cache and package files from `spark.jars.packages`. This will override the Ivy property `ivy.default.ivy.user.dir` which defaults to ~/.ivy2. |
| `spark.jars.ivySettings` | | Path to an Ivy settings file to customize resolution of jars specified using `spark.jars.packages` instead of the built-in defaults, such as maven central. Additional repositories given by the command-line option `--repositories` will also be included. Useful for allowing Spark to resolve artifacts from behind a firewall e.g. via an in-house artifact server like Artifactory. Details on the settings file format can be found at http://ant.apache.org/ivy/history/latest-milestone/settings.html |
| `spark.pyspark.driver.python` | | Python binary executable to use for PySpark in driver. (default is `spark.pyspark.python`) |
| `spark.pyspark.python` | | Python binary executable to use for PySpark in both driver and executors. |
### Shuffle Behavior(Shuffle 行為)
| Property Name(屬性名稱)| Default(默認值)| Meaning(含義)|
| --- | --- | --- |
| `spark.reducer.maxSizeInFlight` | 48m | 從每個 Reduce 任務中并行的 fetch 數據的最大大小。因為每個輸出都要求我們創建一個緩沖區,這代表要為每一個 Reduce 任務分配一個固定大小的內存。除非內存足夠大否則盡量設置小一點。 |
| `spark.reducer.maxReqsInFlight` | Int.MaxValue | 在集群節點上,這個配置限制了遠程 fetch 數據塊的連接數目。當集群中的主機數量的增加時候,這可能導致大量的到一個或多個節點的主動連接,導致負載過多而失敗。通過限制獲取請求的數量,可以緩解這種情況。 |
| `spark.shuffle.compress` | true | 是否要對 map 輸出的文件進行壓縮。默認為 true,使用 `spark.io.compression.codec`。 |
| `spark.shuffle.file.buffer` | 32k | 每個 shuffle 文件輸出流的內存大小。這些緩沖區的數量減少了磁盤尋道和系統調用創建的 shuffle 文件。 |
| `spark.shuffle.io.maxRetries` | 3 |(僅適用于 Netty)如果設置了非 0 值,與 IO 異常相關失敗的 fetch 將自動重試。在遇到長時間的 GC 問題或者瞬態網絡連接問題時候,這種重試有助于大量 shuffle 的穩定性。 |
| `spark.shuffle.io.numConnectionsPerPeer` | 1 |(僅Netty)重新使用主機之間的連接,以減少大型集群的連接建立。 對于具有許多硬盤和少量主機的群集,這可能導致并發性不足以使所有磁盤飽和,因此用戶可考慮增加此值。 |
| `spark.shuffle.io.preferDirectBufs` | true |(僅適用于 Netty)堆緩沖區用于減少在 shuffle 和緩存塊傳輸中的垃圾回收。對于嚴格限制的堆內存環境中,用戶可能希望把這個設置關閉,以強制Netty的所有分配都在堆上。 |
| `spark.shuffle.io.retryWait` | 5s |(僅適用于 Netty)fetch 重試的等待時長。默認 15s。計算公式是 `maxRetries * retryWait`。 |
| `spark.shuffle.service.enabled` | false | 啟用外部隨機播放服務。此服務保留由執行者編寫的隨機播放文件,以便可以安全地刪除執行程序。如果`spark.dynamicAllocation.enabled` 為 "true",則必須啟用此功能。必須設置外部隨機播放服務才能啟用它。有關詳細信息,請參閱 [動態分配配置和設置文檔](job-scheduling.html#configuration-and-setup)。 |
| `spark.shuffle.service.port` | 7337 | 外部 shuffle 的運行端口。 |
| `spark.shuffle.service.index.cache.entries` | 1024 | Max number of entries to keep in the index cache of the shuffle service. |
| `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. |
| `spark.shuffle.spill.compress` | true | Whether to compress data spilled during shuffles. Compression will use `spark.io.compression.codec`. |
| `spark.shuffle.accurateBlockThreshold` | 100 * 1024 * 1024 | When we compress the size of shuffle blocks in HighlyCompressedMapStatus, we will record the size accurately if it's above this config. This helps to prevent OOM by avoiding underestimating shuffle block size when fetch shuffle blocks. |
| `spark.io.encryption.enabled` | false | Enable IO encryption. Currently supported by all modes except Mesos. It's recommended that RPC encryption be enabled when using this feature. |
| `spark.io.encryption.keySizeBits` | 128 | IO encryption key size in bits. Supported values are 128, 192 and 256. |
| `spark.io.encryption.keygen.algorithm` | HmacSHA1 | The algorithm to use when generating the IO encryption key. The supported algorithms are described in the KeyGenerator section of the Java Cryptography Architecture Standard Algorithm Name Documentation. |
### Spark UI
| Property Name(屬性名稱)| Default(默認值)| Meaning(含義)|
| --- | --- | --- |
| `spark.eventLog.compress` | false | 是否壓縮記錄的事件,如果 `spark.eventLog.enabled` 為true。壓縮將使用`spark.io.compression.codec`。 |
| `spark.eventLog.dir` | file:///tmp/spark-events | Spark 事件日志的文件路徑。如果 `spark.eventLog.enabled` 為 true。在這個基本目錄下,Spark 為每個應用程序創建一個二級目錄,日志事件特定于應用程序的目錄。用戶可能希望設置一個統一的文件目錄像一個 HDFS 目錄那樣,所以歷史文件可以從歷史文件服務器中讀取。 |
| `spark.eventLog.enabled` | false | 是否對 Spark 事件記錄日志。在應用程序啟動后有助于重建 Web UI。 |
| `spark.ui.enabled` | true | Whether to run the web UI for the Spark application. |
| `spark.ui.killEnabled` | true | 允許從 Web UI 中結束相應的工作進程。 |
| `spark.ui.port` | 4040 | 應用 UI 的端口,用于顯示內存和工作負載數據。 |
| `spark.ui.retainedJobs` | 1000 | 在垃圾回收前,Spark UI 和 API 有多少 Job 可以留存。 |
| `spark.ui.retainedStages` | 1000 | 在垃圾回收前,Spark UI 和 API 有多少 Stage 可以留存。 |
| `spark.ui.retainedTasks` | 100000 | 在垃圾回收前,Spark UI 和 API 有多少 Task 可以留存。 |
| `spark.ui.reverseProxy` | false | Enable running Spark Master as reverse proxy for worker and application UIs. In this mode, Spark master will reverse proxy the worker and application UIs to enable access without requiring direct access to their hosts. Use it with caution, as worker and application UI will not be accessible directly, you will only be able to access them through spark master/proxy public URL. This setting affects all the workers and application UIs running in the cluster and must be set on all the workers, drivers and masters. |
| `spark.ui.reverseProxyUrl` | | This is the URL where your proxy is running. This URL is for proxy which is running in front of Spark Master. This is useful when running proxy for authentication e.g. OAuth proxy. Make sure this is a complete URL including scheme (http/https) and port to reach your proxy. |
| `spark.ui.showConsoleProgress` | true | Show the progress bar in the console. The progress bar shows the progress of stages that run for longer than 500ms. If multiple stages run at the same time, multiple progress bars will be displayed on the same line. |
| `spark.worker.ui.retainedExecutors` | 1000 | 在垃圾回收前,Spark UI 和 API 有多少 execution 已經完成。 |
| `spark.worker.ui.retainedDrivers` | 1000 | 在垃圾回收前,Spark UI 和 API 有多少 driver 已經完成。 |
| `spark.sql.ui.retainedExecutions` | 1000 | 在垃圾回收前,Spark UI 和 API 有多少 execution 已經完成。 |
| `spark.streaming.ui.retainedBatches` | 1000 | 在垃圾回收前,Spark UI 和 API 有多少 batch 已經完成。 |
| `spark.ui.retainedDeadExecutors` | 100 | 在垃圾回收前,Spark UI 和 API 有多少 dead executors。 |
### Compression and Serialization(壓縮和序列化)
| Property Name(屬性名稱)| Default(默認值)| Meaning(含義)|
| --- | --- | --- |
| `spark.broadcast.compress` | true | 是否在發送之前壓縮廣播變量。一般是個好主意壓縮將使用 `spark.io.compression.codec`。 |
| `spark.io.compression.codec` | lz4 | 內部數據使用的壓縮編解碼器,如 RDD 分區,廣播變量和混洗輸出。默認情況下,Spark 提供三種編解碼器:`lz4`,`lzf`,和 `snappy`。您還可以使用完全限定類名來指定編碼解碼器,例如:`org.apache.spark.io.LZ4CompressionCodec`,`org.apache.spark.io.LZFCompressionCodec`,和 `org.apache.spark.io.SnappyCompressionCodec`。 |
| `spark.io.compression.lz4.blockSize` | 32k | 在采用 LZ4 壓縮編解碼器的情況下,LZ4 壓縮使用的塊大小。減少塊大小還將降低采用 LZ4 時的混洗內存使用。 |
| `spark.io.compression.snappy.blockSize` | 32k | 在采用 Snappy 壓縮編解碼器的情況下,Snappy 壓縮使用的塊大小。減少塊大小還將降低采用 Snappy 時的混洗內存使用。 |
| `spark.kryo.classesToRegister` | (none) | 如果你采用 Kryo 序列化,給一個以逗號分隔的自定義類名列以注冊 Kryo。有關詳細信息,請參閱[調優指南](tuning.html#data-serialization)。 |
| `spark.kryo.referenceTracking` | true | 當使用 Kryo 序列化數據時,是否跟蹤對同一對象的引用,如果對象圖具有循環,并且如果它們包含同一對象的多個副本對效率有用,則這是必需的。如果您知道這不是這樣,可以禁用此功能來提高性能。 |
| `spark.kryo.registrationRequired` | false | 是否需要注冊 Kryo。如果設置為 'true',如果未注冊的類被序列化,Kryo 將拋出異常。如果設置為 false(默認值),Kryo 將與每個對象一起寫入未注冊的類名。編寫類名可能會導致顯著的性能開銷,因此啟用此選項可以嚴格強制用戶沒有從注冊中省略類。 |
| `spark.kryo.registrator` | (none) | 如果你采用 Kryo 序列化,則給一個逗號分隔的類列表,以使用 Kryo 注冊你的自定義類。如果你需要以自定義方式注冊你的類,則此屬性很有用,例如以指定自定義字段序列化程序。否則,使用 spark.kryo.classesToRegisteris 更簡單。它應該設置為 [`KryoRegistrator`](api/scala/index.html#org.apache.spark.serializer.KryoRegistrator) 的子類。詳見:[調整指南](tuning.html#data-serialization)。 |
| `spark.kryo.unsafe` | false | Whether to use unsafe based Kryo serializer. Can be substantially faster by using Unsafe Based IO. |
| `spark.kryoserializer.buffer.max` | 64m | Kryo 序列化緩沖區的最大允許大小。這必須大于你需要序列化的任何對象。如果你在 Kryo 中得到一個 “buffer limit exceeded” 異常,你就需要增加這個值。 |
| `spark.kryoserializer.buffer` | 64k | Kryo 序列化緩沖區的初始大小。注意,每個 worker上 _每個 core_ 會有一個緩沖區。如果需要,此緩沖區將增長到 `spark.kryoserializer.buffer.max`。 |
| `spark.rdd.compress` | false | 是否壓縮序列化RDD分區(例如,在 Java 和 Scala 中為 `StorageLevel.MEMORY_ONLY_SER` 或在 Python 中為 `StorageLevel.MEMORY_ONLY`)。可以節省大量空間,花費一些額外的CPU時間。壓縮將使用 `spark.io.compression.codec`。 |
| `spark.serializer` | org.apache.spark.serializer.
JavaSerializer | 用于序列化將通過網絡發送或需要以序列化形式緩存的對象的類。Java 序列化的默認值與任何Serializable Java對象一起使用,但速度相當慢,所以我們建議您在需要速度時使用 [使用 `org.apache.spark.serializer.KryoSerializer` 并配置 Kryo 序列化](tuning.html)。可以是 [`org.apache.spark.Serializer`](api/scala/index.html#org.apache.spark.serializer.Serializer) 的任何子類。 |
| `spark.serializer.objectStreamReset` | 100 | 當正使用 org.apache.spark.serializer.JavaSerializer 序列化時,序列化器緩存對象雖然可以防止寫入冗余數據,但是卻停止這些緩存對象的垃圾回收。通過調用 'reset' 你從序列化程序中清除該信息,并允許收集舊的對象。要禁用此周期性重置,請將其設置為 -1。默認情況下,序列化器會每過 100 個對象被重置一次。 |
### Memory Management(內存管理)
| Property Name(屬性名稱)| Default(默認值)| Meaning(含義)|
| --- | --- | --- |
| `spark.memory.fraction` | 0.6 | 用于執行和存儲的(堆空間 - 300MB)的分數。這個值越低,溢出和緩存數據逐出越頻繁。此配置的目的是在稀疏、異常大的記錄的情況下為內部元數據,用戶數據結構和不精確的大小估計預留內存。推薦使用默認值。有關更多詳細信息,包括關于在增加此值時正確調整 JVM 垃圾回收的重要信息,請參閱 [this description](tuning.html#memory-management-overview)。 |
| `spark.memory.storageFraction` | 0.5 | 不會被逐出內存的總量,表示為 `s?park.memory.fraction` 留出的區域大小的一小部分。這個越高,工作內存可能越少,執行和任務可能更頻繁地溢出到磁盤。推薦使用默認值。有關更多詳細信息,請參閱 [this description](tuning.html#memory-management-overview)。 |
| `spark.memory.offHeap.enabled` | false | 如果為 true,Spark 會嘗試對某些操作使用堆外內存。如果啟用了堆外內存使用,則 `spark.memory.offHeap.size` 必須為正值。 |
| `spark.memory.offHeap.size` | 0 | 可用于堆外分配的絕對內存量(以字節為單位)。此設置對堆內存使用沒有影響,因此如果您的執行器的總內存消耗必須滿足一些硬限制,那么請確保相應地縮減JVM堆大小。當 `spark.memory.offHeap.enabled=true` 時,必須將此值設置為正值。 |
| `spark.memory.useLegacyMode` | false | 是否啟用 Spark 1.5 及以前版本中使用的傳統內存管理模式。傳統模式將堆空間嚴格劃分為固定大小的區域,如果未調整應用程序,可能導致過多溢出。必須啟用本參數,以下選項才可用:`spark.shuffle.memoryFraction`
`spark.storage.memoryFraction`
`spark.storage.unrollFraction` |
| `spark.shuffle.memoryFraction` | 0.2 |(過時)只有在啟用 `spark.memory.useLegacyMode` 時,此屬性才是可用的。混洗期間用于聚合和 cogroups 的 Java 堆的分數。在任何給定時間,用于混洗的所有內存映射的集合大小不會超過這個上限,超過該限制的內容將開始溢出到磁盤。如果溢出頻繁,請考慮增加此值,但這以 `spark.storage.memoryFraction` 為代價。 |
| `spark.storage.memoryFraction` | 0.6 |(過時)只有在啟用 `spark.memory.useLegacyMode` 時,此屬性才是可用的。Java 堆的分數,用于 Spark 的內存緩存。這個值不應該大于 JVM 中老生代(old generation) 對象所占用的內存,默認情況下,它提供 0.6 的堆,但是如果配置你所用的老生代對象大小,你可以增加它。 |
| `spark.storage.unrollFraction` | 0.2 |(過時)只有在啟用 `spark.memory.useLegacyMode` 時,此屬性才是可用的。`spark.storage.memoryFraction` 用于在內存中展開塊的分數。當沒有足夠的空閑存儲空間來完全展開新塊時,通過刪除現有塊來動態分配。 |
| `spark.storage.replication.proactive` | false | Enables proactive block replication for RDD blocks. Cached RDD block replicas lost due to executor failures are replenished if there are any existing available replicas. This tries to get the replication level of the block to the initial number. |
### Execution Behavior(執行行為)
| Property Name(屬性名稱)| Default(默認行為)| Meaning(含義)|
| --- | --- | --- |
| `spark.broadcast.blockSize` | 4m | `TorrentBroadcastFactory` 的一個塊的每個分片大小。過大的值會降低廣播期間的并行性(更慢了); 但是,如果它過小,`BlockManager` 可能會受到性能影響。 |
| `spark.executor.cores` | 在 YARN 模式下默認為 1,standlone 和 Mesos 粗粒度模型中的 worker 節點的所有可用的 core。 | 在每個 executor(執行器)上使用的 core 數。在 standlone 和 Mesos 的粗粒度模式下,設置此參數允許應用在相同的 worker 上運行多個 executor(執行器),只要該 worker 上有足夠的 core。否則,每個 application(應用)在單個 worker 上只會啟動一個 executor(執行器)。 |
| `spark.default.parallelism` | 對于分布式混洗(shuffle)操作,如 `reduceByKey` 和 `join`,父 RDD 中分區的最大數量。對于沒有父 RDD 的 `parallelize` 操作,它取決于集群管理器:<br><li>本地模式:本地機器上的 core 數<br><li>Mesos 細粒度模式:8<br><li>其他:所有執行器節點上的 core 總數或者 2,以較大者為準 | 如果用戶沒有指定參數值,則這個屬性是 `join`,`reduceByKey`,和 `parallelize` 等轉換返回的 RDD 中的默認分區數。 |
| `spark.executor.heartbeatInterval` | 10s | 每個執行器的心跳與驅動程序之間的間隔。心跳讓驅動程序知道執行器仍然存活,并用正在進行的任務的指標更新它 |
| `spark.files.fetchTimeout` | 60s | 獲取文件的通訊超時,所獲取的文件是從驅動程序通過 SparkContext.addFile() 添加的。 |
| `spark.files.useFetchCache` | true | 如果設置為 true(默認),文件提取將使用由屬于同一應用程序的執行器共享的本地緩存,這可以提高在同一主機上運行許多執行器時的任務啟動性能。如果設置為 false,這些緩存優化將被禁用,所有執行器將獲取它們自己的文件副本。如果使用駐留在 NFS 文件系統上的 Spark 本地目錄,可以禁用此優化(有關詳細信息,請參閱 [SPARK-6313](https://issues.apache.org/jira/browse/SPARK-6313))。 |
| `spark.files.overwrite` | false | 當目標文件存在且其內容與源不匹配的情況下,是否覆蓋通過 SparkContext.addFile() 添加的文件。 |
| `spark.files.maxPartitionBytes` | 134217728 (128 MB) | The maximum number of bytes to pack into a single partition when reading files. |
| `spark.files.openCostInBytes` | 4194304 (4 MB) | The estimated cost to open a file, measured by the number of bytes could be scanned in the same time. This is used when putting multiple files into a partition. It is better to over estimate, then the partitions with small files will be faster than partitions with bigger files. |
| `spark.hadoop.cloneConf` | false | 如果設置為true,則為每個任務克隆一個新的Hadoop `Configuration` 對象。應該啟用此選項以解決 `Configuration` 線程安全問題(有關詳細信息,請參閱 [SPARK-2546](https://issues.apache.org/jira/browse/SPARK-2546))。默認情況下,這是禁用的,以避免不受這些問題影響的作業的意外性能回歸。 |
| `spark.hadoop.validateOutputSpecs` | true | 如果設置為 true,則驗證 saveAsHadoopFile 和其他變體中使用的輸出規范(例如,檢查輸出目錄是否已存在)。可以禁用此選項以靜默由于預先存在的輸出目錄而導致的異常。我們建議用戶不要禁用此功能,除非需要實現與以前版本的 Spark 的兼容性。可以簡單地使用 Hadoop 的 FileSystem API 手動刪除輸出目錄。對于通過 Spark Streaming 的StreamingContext 生成的作業會忽略此設置,因為在檢查點恢復期間可能需要將數據重寫到預先存在的輸出目錄。 |
| `spark.storage.memoryMapThreshold` | 2m | 當從磁盤讀取塊時,Spark 內存映射的塊大小。這會阻止 Spark 從內存映射過小的塊。通常,存儲器映射對于接近或小于操作系統的頁大小的塊具有高開銷。 |
| `spark.hadoop.mapreduce.fileoutputcommitter.algorithm.version` | 1 | The file output committer algorithm version, valid algorithm version number: 1 or 2. Version 2 may have better performance, but version 1 may handle failures better in certain situations, as per [MAPREDUCE-4815](https://issues.apache.org/jira/browse/MAPREDUCE-4815). |
### Networking(網絡)
| Property Name(屬性名稱)| Default(默認值)| Meaning(含義)|
| --- | --- | --- |
| `spark.rpc.message.maxSize` | 128 | 在 “control plane” 通信中允許的最大消息大小(以 MB 為單位); 一般只適用于在 executors 和 driver 之間發送的映射輸出大小信息。如果您正在運行帶有數千個 map 和 reduce 任務的作業,并查看有關 RPC 消息大小的消息,請增加此值。 |
| `spark.blockManager.port` | (random) | 所有塊管理器監聽的端口。這些都存在于 driver 和 executors 上。 |
| `spark.driver.blockManager.port` | (value of spark.blockManager.port) | Driver-specific port for the block manager to listen on, for cases where it cannot use the same configuration as executors. |
| `spark.driver.bindAddress` | (value of spark.driver.host) | Hostname or IP address where to bind listening sockets. This config overrides the SPARK_LOCAL_IP environment variable (see below).
It also allows a different address from the local one to be advertised to executors or external systems. This is useful, for example, when running containers with bridged networking. For this to properly work, the different ports used by the driver (RPC, block manager and UI) need to be forwarded from the container's host. |
| `spark.driver.host` | (local hostname) | 要監聽的 driver 的主機名或 IP 地址。這用于與 executors 和 standalone Master 進行通信。 |
| `spark.driver.port` | (random) | 要監聽的 driver 的端口。這用于與 executors 和 standalone Master 進行通信。 |
| `spark.network.timeout` | 120s | 所有網絡交互的默認超時。如果未配置此項,將使用此配置替換 `spark.core.connection.ack.wait.timeout`,`spark.storage.blockManagerSlaveTimeoutMs`,`spark.shuffle.io.connectionTimeout`,`spark.rpc.askTimeout` or `spark.rpc.lookupTimeout`。 |
| `spark.port.maxRetries` | 16 | 在綁定端口放棄之前的最大重試次數。當端口被賦予特定值(非 0)時,每次后續重試將在重試之前將先前嘗試中使用的端口增加 1。這本質上允許它嘗試從指定的開始端口到端口 + maxRetries 的一系列端口。 |
| `spark.rpc.numRetries` | 3 | 在 RPC 任務放棄之前重試的次數。RPC 任務將在此數字的大多數時間運行。 |
| `spark.rpc.retry.wait` | 3s | RPC 請求操作在重試之前等待的持續時間。 |
| `spark.rpc.askTimeout` | `spark.network.timeout` | RPC 請求操作在超時前等待的持續時間。 |
| `spark.rpc.lookupTimeout` | 120s | RPC 遠程端點查找操作在超時之前等待的持續時間。 |
### Scheduling(調度)
| Property Name(屬性名稱)| Default(默認值)| Meaning(含義)|
| --- | --- | --- |
| `spark.cores.max` | (not set) | 當以 “coarse-grained(粗粒度)” 共享模式在 [standalone deploy cluster](spark-standalone.html) 或 [Mesos cluster in "coarse-grained" sharing mode](running-on-mesos.html#mesos-run-modes) 上運行時,從集群(而不是每臺計算機)請求應用程序的最大 CPU 內核數量。如果未設置,默認值將是 Spar k的 standalone deploy 管理器上的 `spark.deploy.defaultCores`,或者 Mesos上的無限(所有可用核心)。 |
| `spark.locality.wait` | 3s | 等待啟動本地數據任務多長時間,然后在較少本地節點上放棄并啟動它。相同的等待將用于跨越多個地點級別(process-local,node-local,rack-local 等所有)。也可以通過設置 `spark.locality.wait.node` 等來自定義每個級別的等待時間。如果任務很長并且局部性較差,則應該增加此設置,但是默認值通常很好。 |
| `spark.locality.wait.node` | spark.locality.wait | 自定義 node locality 等待時間。例如,您可以將其設置為 0 以跳過 node locality,并立即搜索機架位置(如果群集具有機架信息)。 |
| `spark.locality.wait.process` | spark.locality.wait | 自定義 process locality 等待時間。這會影響嘗試訪問特定執行程序進程中的緩存數據的任務。 |
| `spark.locality.wait.rack` | spark.locality.wait | 自定義 rack locality 等待時間。 |
| `spark.scheduler.maxRegisteredResourcesWaitingTime` | 30s | 在調度開始之前等待資源注冊的最大時間量。 |
| `spark.scheduler.minRegisteredResourcesRatio` | 0.8 for YARN mode; 0.0 for standalone mode and Mesos coarse-grained mode | 注冊資源(注冊資源/總預期資源)的最小比率(資源是 yarn 模式下的執行程序,standalone 模式下的 CPU 核心和 Mesos coarsed-grained 模式 'spark.cores.max' 值是 Mesos coarse-grained 模式下的總體預期資源])在調度開始之前等待。指定為 0.0 和 1.0 之間的雙精度。無論是否已達到資源的最小比率,在調度開始之前將等待的最大時間量由配置`spark.scheduler.maxRegisteredResourcesWaitingTime` 控制。 |
| `spark.scheduler.mode` | FIFO | 作業之間的 [scheduling mode(調度模式)](job-scheduling.html#scheduling-within-an-application) 提交到同一個 SparkContext。可以設置為 `FAIR` 使用公平共享,而不是一個接一個排隊作業。對多用戶服務有用。 |
| `spark.scheduler.revive.interval` | 1s | 調度程序復活工作資源去運行任務的間隔長度。 |
| `spark.blacklist.enabled` | false | If set to "true", prevent Spark from scheduling tasks on executors that have been blacklisted due to too many task failures. The blacklisting algorithm can be further controlled by the other "spark.blacklist" configuration options. |
| `spark.blacklist.timeout` | 1h | (Experimental) How long a node or executor is blacklisted for the entire application, before it is unconditionally removed from the blacklist to attempt running new tasks. |
| `spark.blacklist.task.maxTaskAttemptsPerExecutor` | 1 | (Experimental) For a given task, how many times it can be retried on one executor before the executor is blacklisted for that task. |
| `spark.blacklist.task.maxTaskAttemptsPerNode` | 2 | (Experimental) For a given task, how many times it can be retried on one node, before the entire node is blacklisted for that task. |
| `spark.blacklist.stage.maxFailedTasksPerExecutor` | 2 | (Experimental) How many different tasks must fail on one executor, within one stage, before the executor is blacklisted for that stage. |
| `spark.blacklist.stage.maxFailedExecutorsPerNode` | 2 | (Experimental) How many different executors are marked as blacklisted for a given stage, before the entire node is marked as failed for the stage. |
| `spark.blacklist.application.maxFailedTasksPerExecutor` | 2 | (Experimental) How many different tasks must fail on one executor, in successful task sets, before the executor is blacklisted for the entire application. Blacklisted executors will be automatically added back to the pool of available resources after the timeout specified by `spark.blacklist.timeout`. Note that with dynamic allocation, though, the executors may get marked as idle and be reclaimed by the cluster manager. |
| `spark.blacklist.application.maxFailedExecutorsPerNode` | 2 | (Experimental) How many different executors must be blacklisted for the entire application, before the node is blacklisted for the entire application. Blacklisted nodes will be automatically added back to the pool of available resources after the timeout specified by `spark.blacklist.timeout`. Note that with dynamic allocation, though, the executors on the node may get marked as idle and be reclaimed by the cluster manager. |
| `spark.blacklist.killBlacklistedExecutors` | false | (Experimental) If set to "true", allow Spark to automatically kill, and attempt to re-create, executors when they are blacklisted. Note that, when an entire node is added to the blacklist, all of the executors on that node will be killed. |
| `spark.speculation` | false | 如果設置為 "true",則執行任務的推測執行。這意味著如果一個或多個任務在一個階段中運行緩慢,則將重新啟動它們。 |
| `spark.speculation.interval` | 100ms | Spark 檢查要推測的任務的時間間隔。 |
| `spark.speculation.multiplier` | 1.5 | 一個任務的速度可以比推測的平均值慢多少倍。 |
| `spark.speculation.quantile` | 0.75 | 對特定階段啟用推測之前必須完成的任務的分數。 |
| `spark.task.cpus` | 1 | 要為每個任務分配的核心數。 |
| `spark.task.maxFailures` | 4 | 放棄作業之前任何特定任務的失敗次數。分散在不同任務中的故障總數不會導致作業失敗; 一個特定的任務允許失敗這個次數。應大于或等于 1\. 允許重試次數=此值 - 1\. |
| `spark.task.reaper.enabled` | false | Enables monitoring of killed / interrupted tasks. When set to true, any task which is killed will be monitored by the executor until that task actually finishes executing. See the other `spark.task.reaper.*` configurations for details on how to control the exact behavior of this monitoring. When set to false (the default), task killing will use an older code path which lacks such monitoring. |
| `spark.task.reaper.pollingInterval` | 10s | When `spark.task.reaper.enabled = true`, this setting controls the frequency at which executors will poll the status of killed tasks. If a killed task is still running when polled then a warning will be logged and, by default, a thread-dump of the task will be logged (this thread dump can be disabled via the `spark.task.reaper.threadDump` setting, which is documented below). |
| `spark.task.reaper.threadDump` | true | When `spark.task.reaper.enabled = true`, this setting controls whether task thread dumps are logged during periodic polling of killed tasks. Set this to false to disable collection of thread dumps. |
| `spark.task.reaper.killTimeout` | -1 | When `spark.task.reaper.enabled = true`, this setting specifies a timeout after which the executor JVM will kill itself if a killed task has not stopped running. The default value, -1, disables this mechanism and prevents the executor from self-destructing. The purpose of this setting is to act as a safety-net to prevent runaway uncancellable tasks from rendering an executor unusable. |
| `spark.stage.maxConsecutiveAttempts` | 4 | Number of consecutive stage attempts allowed before a stage is aborted. |
### Dynamic Allocation(動態分配)
| Property Name(屬性名稱)| Default(默認值)| Meaning(含義)|
| --- | --- | --- |
| `spark.dynamicAllocation.enabled` | false | 是否使用動態資源分配,它根據工作負載調整為此應用程序注冊的執行程序數量。有關更多詳細信息,請參閱 [here](job-scheduling.html#dynamic-resource-allocation) 的說明。這需要設置 `spark.shuffle.service.enabled`。以下配置也相關:`spark.dynamicAllocation.minExecutors`,`spark.dynamicAllocation.maxExecutors` 和`spark.dynamicAllocation.initialExecutors`。 |
| `spark.dynamicAllocation.executorIdleTimeout` | 60s | 如果啟用動態分配,并且執行程序已空閑超過此持續時間,則將刪除執行程序。有關更多詳細信息,請參閱此[description](job-scheduling.html#resource-allocation-policy)。 |
| `spark.dynamicAllocation.cachedExecutorIdleTimeout` | infinity | 如果啟用動態分配,并且已緩存數據塊的執行程序已空閑超過此持續時間,則將刪除執行程序。有關詳細信息,請參閱此 [description](job-scheduling.html#resource-allocation-policy)。 |
| `spark.dynamicAllocation.initialExecutors` | `spark.dynamicAllocation.minExecutors` | 啟用動態分配時要運行的執行程序的初始數。如果 `--num-executors`(或 `spark.executor.instances`)被設置并大于此值,它將被用作初始執行器數。 |
| `spark.dynamicAllocation.maxExecutors` | infinity | 啟用動態分配的執行程序數量的上限。 |
| `spark.dynamicAllocation.minExecutors` | 0 | 啟用動態分配的執行程序數量的下限。 |
| `spark.dynamicAllocation.schedulerBacklogTimeout` | 1s | 如果啟用動態分配,并且有超過此持續時間的掛起任務積壓,則將請求新的執行者。有關更多詳細信息,請參閱此 [description](job-scheduling.html#resource-allocation-policy)。 |
| `spark.dynamicAllocation.sustainedSchedulerBacklogTimeout` | `schedulerBacklogTimeout` | 與 `spark.dynamicAllocation.schedulerBacklogTimeout` 相同,但僅用于后續執行者請求。有關更多詳細信息,請參閱此 [description](job-scheduling.html#resource-allocation-policy)。 |
### Security(安全)
| Property Name(屬性名稱)| Default(默認值)| Meaning(含義)|
| --- | --- | --- |
| `spark.acls.enable` | false | 是否開啟 Spark acls。如果開啟了,它檢查用戶是否有權限去查看或修改 job。Note this requires the user to be known, so if the user comes across as null no checks are done. UI 利用使用過濾器驗證和設置用戶。 |
| `spark.admin.acls` | Empty | 逗號分隔的用戶或者管理員列表,列表中的用戶或管理員有查看和修改所有 Spark job 的權限。如果你運行在一個共享集群,有一組管理員或開發者幫助 debug,這個選項有用。 |
| `spark.admin.acls.groups` | Empty | 具有查看和修改對所有Spark作業的訪問權限的組的逗號分隔列表。如果您有一組幫助維護和調試的 administrators 或 developers 可以使用此功能基礎設施。在列表中輸入 "*" 表示任何組中的任何用戶都可以使用 admin 的特權。用戶組是從 groups mapping provider 的實例獲得的。由 `spark.user.groups.mapping` 指定。檢查 entry `spark.user.groups.mapping` 了解更多詳細信息。 |
| `spark.user.groups.mapping` | `org.apache.spark.security.ShellBasedGroupsMappingProvider` | 用戶的組列表由特征定義的 group mapping service 決定可以通過此屬性配置的org.apache.spark.security.GroupMappingServiceProvider. 提供了基于 unix shell 的默認實現 `org.apache.spark.security.ShellBasedGroupsMappingProvider` 可以指定它來解析用戶的組列表。_注意:_ 此實現僅支持基于 Unix/Linux 的環境。Windows 環境目前是 **不** 支持。但是,通過實現可以支持新的 platform/protocol(平臺/協議)trait `org.apache.spark.security.GroupMappingServiceProvider`。 |
| `spark.authenticate` | false | 是否 Spark 驗證其內部連接。如果不是運行在 YARN 上,請看 `spark.authenticate.secret`。 |
| `spark.authenticate.secret` | None | 設置密鑰用于 spark 組件之間進行身份驗證。這需要設置 不啟用運行在 yarn 和身份驗證。 |
| `spark.network.crypto.enabled` | false | Enable encryption using the commons-crypto library for RPC and block transfer service. Requires `spark.authenticate` to be enabled. |
| `spark.network.crypto.keyLength` | 128 | The length in bits of the encryption key to generate. Valid values are 128, 192 and 256. |
| `spark.network.crypto.keyFactoryAlgorithm` | PBKDF2WithHmacSHA1 | The key factory algorithm to use when generating encryption keys. Should be one of the algorithms supported by the javax.crypto.SecretKeyFactory class in the JRE being used. |
| `spark.network.crypto.saslFallback` | true | Whether to fall back to SASL authentication if authentication fails using Spark's internal mechanism. This is useful when the application is connecting to old shuffle services that do not support the internal Spark authentication protocol. On the server side, this can be used to block older clients from authenticating against a new shuffle service. |
| `spark.network.crypto.config.*` | None | Configuration values for the commons-crypto library, such as which cipher implementations to use. The config name should be the name of commons-crypto configuration without the "commons.crypto" prefix. |
| `spark.authenticate.enableSaslEncryption` | false | 身份驗證時啟用加密通信。這是 block transfer service(塊傳輸服務)和支持 RPC 的端點。 |
| `spark.network.sasl.serverAlwaysEncrypt` | false | 禁用未加密的連接服務,支持 SASL 驗證。這是目前支持的外部轉移服務。 |
| `spark.core.connection.ack.wait.timeout` | `spark.network.timeout` | 連接在 timing out(超時)和 giving up(放棄)之前等待 ack occur 的時間。為了避免長時間 pause(暫停),如 GC,導致的不希望的超時,你可以設置較大的值。 |
| `spark.modify.acls` | Empty | 逗號分隔的用戶列表,列表中的用戶有查看 Spark web UI 的權限。默認情況下,只有啟動 Spark job 的用戶有修改(比如殺死它)權限。在列表中加入 "*" 意味著任何用戶可以訪問以修改它。 |
| `spark.modify.acls.groups` | Empty | 具有對 Spark job 的修改訪問權限的組的逗號分隔列表。如果你可以使用這個有一組來自同一個 team 的 administrators 或 developers 可以訪問控制工作。在列表中放置 "*" 表示任何組中的任何用戶都有權修改 Spark job。用戶組是從 `spark.user.groups.mapping` 指定的 groups mapping 提供者的實例獲得的。查看 entry `spark.user.groups.mapping` 來了解更多細節。 |
| `spark.ui.filters` | None | 應用到 Spark web UI 的用于 filter class(過濾類)名的逗號分隔的列表。過濾器必須是標準的 [javax servlet Filter](http://docs.oracle.com/javaee/6/api/javax/servlet/Filter.html)。每個過濾器的參數也可以通過設置一個 java 系統屬性來指定 spark。java 系統屬性:
`spark.<class name of filter>.params='param1=value1,param2=value2'`
例如:
`-Dspark.ui.filters=com.test.filter1`
`-Dspark.com.test.filter1.params='param1=foo,param2=testing'` |
| `spark.ui.view.acls` | Empty | 逗號分隔的可以訪問 Spark web ui 的用戶列表。默認情況下只有啟動 Spark job 的用戶具有 view 訪問權限。在列表中放入 "*" 表示任何用戶都可以具有訪問此 Spark job 的 view。
| `spark.ui.view.acls.groups` | Empty | 逗號分隔的列表,可以查看訪問 Spark web ui 的組,以查看 Spark Job 細節。如果您有一組 administrators 或 developers 或可以使用的用戶,則可以使用此功能 monitor(監控)提交的 Spark job。在列表中添加 "*" 表示任何組中的任何用戶都可以查看 Spark web ui 上的 Spark 工作詳細信息。用戶組是從 由 `spark.user.groups.mapping` 指定的 groups mapping provider(組映射提供程序)實例獲得的。查看 entry `spark.user.groups.mapping` 來了解更多細節。 |
### TLS / SSL
| Property Name | Default | Meaning |
| --- | --- | --- |
| `spark.ssl.enabled` | false | Whether to enable SSL connections on all supported protocols.
When `spark.ssl.enabled` is configured, `spark.ssl.protocol` is required.
All the SSL settings like `spark.ssl.xxx` where `xxx` is a particular configuration property, denote the global configuration for all the supported protocols. In order to override the global configuration for the particular protocol, the properties must be overwritten in the protocol-specific namespace.
Use `spark.ssl.YYY.XXX` settings to overwrite the global configuration for particular protocol denoted by `YYY`. Example values for `YYY` include `fs`, `ui`, `standalone`, and `historyServer`. See [SSL Configuration](security.html#ssl-configuration) for details on hierarchical SSL configuration for services. |
| `spark.ssl.[namespace].port` | None | The port where the SSL service will listen on.
The port must be defined within a namespace configuration; see [SSL Configuration](security.html#ssl-configuration) for the available namespaces.
When not set, the SSL port will be derived from the non-SSL port for the same service. A value of "0" will make the service bind to an ephemeral port. |
| `spark.ssl.enabledAlgorithms` | Empty | A comma separated list of ciphers. The specified ciphers must be supported by JVM. The reference list of protocols one can find on [this](https://blogs.oracle.com/java-platform-group/entry/diagnosing_tls_ssl_and_https) page. Note: If not set, it will use the default cipher suites of JVM. |
| `spark.ssl.keyPassword` | None | A password to the private key in key-store. |
| `spark.ssl.keyStore` | None | A path to a key-store file. The path can be absolute or relative to the directory where the component is started in. |
| `spark.ssl.keyStorePassword` | None | A password to the key-store. |
| `spark.ssl.keyStoreType` | JKS | The type of 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](https://blogs.oracle.com/java-platform-group/entry/diagnosing_tls_ssl_and_https) page. |
| `spark.ssl.needClientAuth` | false | Set true if SSL needs client authentication. |
| `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. |
| `spark.ssl.trustStoreType` | JKS | The type of the trust-store. |
### Spark SQL
運行 `SET -v` 命令將顯示 SQL 配置的整個列表.
```
// spark is an existing SparkSession
spark.sql("SET -v").show(numRows = 200, truncate = false)
```
```
// spark is an existing SparkSession
spark.sql("SET -v").show(200, false);
```
```
# spark is an existing SparkSession
spark.sql("SET -v").show(n=200, truncate=False)
```
```
sparkR.session()
properties <- sql("SET -v")
showDF(properties, numRows = 200, truncate = FALSE)
```
### Spark Streaming
| Property Name(屬性名稱)| Default(默認值)| Meaning(含義)|
| --- | --- | --- |
| `spark.streaming.backpressure.enabled` | false | 開啟或關閉 Spark Streaming 內部的 backpressure mecheanism(自 1.5 開始)。基于當前批次調度延遲和處理時間,這使得 Spark Streaming 能夠控制數據的接收率,因此,系統接收數據的速度會和系統處理的速度一樣快。從內部來說,這動態地設置了 receivers 的最大接收率。這個速率上限通過 `spark.streaming.receiver.maxRate` 和 `spark.streaming.kafka.maxRatePerPartition` 兩個參數設定(如下)。 |
| `spark.streaming.backpressure.initialRate` | not set | 當 backpressure mecheanism 開啟時,每個 receiver 接受數據的初始最大值。 |
| `spark.streaming.blockInterval` | 200ms | 在這個時間間隔(ms)內,通過 Spark Streaming receivers 接收的數據在保存到 Spark 之前,chunk 為數據塊。推薦的最小值為 50ms。具體細節見 Spark Streaming 指南的 [performance tuning](streaming-programming-guide.html#level-of-parallelism-in-data-receiving) 一節。 |
| `spark.streaming.receiver.maxRate` | not set | 每秒鐘每個 receiver 將接收的數據的最大速率(每秒鐘的記錄數目)。有效的情況下,每個流每秒將最多消耗這個數目的記錄。設置這個配置為 0 或者 -1 將會不作限制。細節參見 Spark Streaming 編程指南的 [deployment guide](streaming-programming-guide.html#deploying-applications) 一節。 |
| `spark.streaming.receiver.writeAheadLog.enable` | false | 為 receiver 啟用 write ahead logs。所有通過接收器接收輸入的數據將被保存到 write ahead logs,以便它在驅動程序故障后進行恢復。見星火流編程指南部署指南了解更多詳情。細節參見 Spark Streaming 編程指南的 [deployment guide](streaming-programming-guide.html#deploying-applications) 一節。 |
| `spark.streaming.unpersist` | true | 強制通過 Spark Streaming 生成并持久化的 RDD 自動從 Spark 內存中非持久化。通過 Spark Streaming 接收的原始輸入數據也將清除。設置這個屬性為 false 允許流應用程序訪問原始數據和持久化 RDD,因為它們沒有被自動清除。但是它會造成更高的內存花費。 |
| `spark.streaming.stopGracefullyOnShutdown` | false | 如果為 `true`,Spark 將 gracefully(緩慢地)關閉在 JVM 運行的 StreamingContext,而非立即執行。 |
| `spark.streaming.kafka.maxRatePerPartition` | not set | 在使用新的 Kafka direct stream API 時,從每個 kafka 分區讀到的最大速率(每秒的記錄數目)。詳見 [Kafka Integration guide](streaming-kafka-integration.html)。 |
| `spark.streaming.kafka.maxRetries` | 1 | driver 連續重試的最大次數,以此找到每個分區 leader 的最近的(latest)的偏移量(默認為 1 意味著 driver 將嘗試最多兩次)。僅應用于新的 kafka direct stream API。 |
| `spark.streaming.ui.retainedBatches` | 1000 | 在垃圾回收之前,Spark Streaming UI 和狀態API 所能記得的 批處理(batches)數量。 |
| `spark.streaming.driver.writeAheadLog.closeFileAfterWrite` | false | 在寫入一條 driver 中的 write ahead log 記錄 之后,是否關閉文件。如果你想為 driver 中的元數據 WAL 使用 S3(或者任何文件系統而不支持 flushing),設定為 true。
| `spark.streaming.receiver.writeAheadLog.closeFileAfterWrite` | false | 在寫入一條 reveivers 中的 write ahead log 記錄 之后,是否關閉文件。如果你想為 reveivers 中的元數據 WAL 使用 S3(或者任何文件系統而不支持 flushing),設定為 true。 |
### SparkR
| Property Name(屬性名稱)| Default(默認值)| Meaning(含義)|
| --- | --- | --- |
| `spark.r.numRBackendThreads` | 2 | 使用 RBackend 處理來自 SparkR 包中的 RPC 調用的線程數。 |
| `spark.r.command` | Rscript | 在 driver 和 worker 兩種集群模式下可執行的 R 腳本。 |
| `spark.r.driver.command` | spark.r.command | 在 driver 的 client 模式下可執行的 R 腳本。在集群模式下被忽略。 |
| `spark.r.shell.command` | R | Executable for executing sparkR shell in client modes for driver. Ignored in cluster modes. It is the same as environment variable `SPARKR_DRIVER_R`, but take precedence over it. `spark.r.shell.command` is used for sparkR shell while `spark.r.driver.command` is used for running R script. |
| `spark.r.backendConnectionTimeout` | 6000 | Connection timeout set by R process on its connection to RBackend in seconds. |
| `spark.r.heartBeatInterval` | 100 | Interval for heartbeats sent from SparkR backend to R process to prevent connection timeout. |
### GraphX
| Property Name | Default | Meaning |
| --- | --- | --- |
| `spark.graphx.pregel.checkpointInterval` | -1 | Checkpoint interval for graph and message in Pregel. It used to avoid stackOverflowError due to long lineage chains after lots of iterations. The checkpoint is disabled by default. |
### Deploy(部署)
| Property Name(屬性名稱)| Default(默認值)| Meaning(含義)|
| --- | --- | --- |
| `spark.deploy.recoveryMode` | NONE | 集群模式下,Spark jobs 執行失敗或者重啟時,恢復提交 Spark jobs 的恢復模式設定。 |
| `spark.deploy.zookeeper.url` | None | 當 `spark.deploy.recoveryMode` 被設定為 ZOOKEEPER,這一配置被用來連接 zookeeper URL。 |
| `spark.deploy.zookeeper.dir` | None | 當 `spark.deploy.recoveryMode` 被設定為 ZOOKEEPER,這一配置被用來設定 zookeeper 目錄為 store recovery state。 |
### Cluster Managers(集群管理器)
Spark 中的每個集群管理器都有額外的配置選項,這些配置可以在每個模式的頁面中找到:
#### [YARN](running-on-yarn.html#configuration)
#### [Mesos](running-on-mesos.html#configuration)
#### [Standalone Mode](spark-standalone.html#cluster-launch-scripts)
# Environment Variables(環境變量)
通過環境變量配置特定的 Spark 設置。環境變量從 Spark 安裝目錄下的 `conf/spark-env.sh` 腳本讀取(或者是 window 環境下的 `conf/spark-env.cmd`)。在 Standalone 和 Mesos 模式下,這個文件可以指定機器的特定信息,比如 hostnames。它也可以為正在運行的 Spark Application 或者提交腳本提供 sourced(來源).
注意,當 Spark 被安裝,默認情況下 `conf/spark-env.sh` 是不存在的。但是,你可以通過拷貝 `conf/spark-env.sh.template` 來創建它。確保你的拷貝文件時可執行的。`spark-env.sh`:中有有以下變量可以被設置 :
| Environment Variable(環境變量)| Meaning(含義)|
| --- | --- |
| `JAVA_HOME` | Java 的安裝路徑(如果不在你的默認 `PATH` 下)。 |
| `PYSPARK_PYTHON` | 在 driver 和 worker 中 PySpark 用到的 Python 二進制可執行文件(如何有默認為 `python2.7`,否則為 `python`)。如果設置了屬性 `spark.pyspark.python`,則會優先考慮。 |
| `PYSPARK_DRIVER_PYTHON` | 只在 driver 中 PySpark 用到的 Python 二進制可執行文件(默認為 `PYSPARK_PYTHON`)。如果設置了屬性 `spark.pyspark.driver.python` ,則優先考慮。 |
| `SPARKR_DRIVER_R` | SparkR shell 用到的 R 二進制可執行文件(默認為 `R`)。如果設置了屬性 `spark.r.shell.command` 則會優先考慮。 |
| `SPARK_LOCAL_IP` | 機器綁定的 IP 地址。 |
| `SPARK_PUBLIC_DNS` | 你的 Spark 程序通知其他機器的 Hostname。 |
除了以上參數,[standalone cluster scripts](spark-standalone.html#cluster-launch-scripts) 也可以設置其他選項,比如每個機器使用的 CPU 核數和最大內存.
因為 `spark-env.sh` 是 shell 腳本,一些可以通過程序的方式來設置,比如你可以通過特定的網絡接口來計算 `SPARK_LOCAL_IP`。
注意:當以 `cluster` mode(集群模式)運行 Spark on YARN 時,環境變量需要通過在您的 `conf/spark-defaults.conf` 文件中 `spark.yarn.appMasterEnv.[EnvironmentVariableName]` 來設定。`cluster` mode(集群模式)下,`spark-env.sh` 中設定的環境變量將不會在 YARN Application Master 過程中反應出來。詳見 [YARN-related Spark Properties](running-on-yarn.html#spark-properties).
# Configuring Logging(配置 Logging)
Spark 用 [log4j](http://logging.apache.org/log4j/) 生成日志,你可以通過在 `conf` 目錄下添加 `log4j.properties` 文件來配置.一種方法是拷貝 `log4j.properties.template` 文件.
# Overriding configuration directory(覆蓋配置目錄)
如果你想指定不同的配置目錄,而不是默認的 “SPARK_HOME/conf”,你可以設置 SPARK_CONF_DIR。Spark 將從這一目錄下讀取文件(spark-defaults.conf,spark-env.sh,log4j.properties 等)
# Inheriting Hadoop Cluster Configuration(繼承 Hadoop 集群配置)
如果你想用 Spark 來讀寫 HDFS,在 Spark 的 classpath 就需要包括兩個 Hadoop 配置文件:
* `hdfs-site.xml`,為 HDFS client 提供 default behaviors(默認的行為).
* `core-site.xml`,設定默認的文件系統名稱.
這些配置文件的位置因 Hadoop 版本而異,但是一個常見的位置在 `/etc/hadoop/conf` 內。一些工具創建配置 on-the-fly,但提供了一種機制來下載它們的副本.
為了使這些文件對 Spark 可見,需要設定 `$SPARK_HOME/spark-env.sh` 中的 `HADOOP_CONF_DIR` 到一個包含配置文件的位置.
- Spark 概述
- 編程指南
- 快速入門
- Spark 編程指南
- 構建在 Spark 之上的模塊
- Spark Streaming 編程指南
- Spark SQL, DataFrames and Datasets Guide
- MLlib
- GraphX Programming Guide
- API 文檔
- 部署指南
- 集群模式概述
- Submitting Applications
- 部署模式
- Spark Standalone Mode
- 在 Mesos 上運行 Spark
- Running Spark on YARN
- 其它
- 更多
- Spark 配置
- Monitoring and Instrumentation
- Tuning Spark
- 作業調度
- Spark 安全
- 硬件配置
- Accessing OpenStack Swift from Spark
- 構建 Spark
- 其它
- 外部資源
- Spark RDD(Resilient Distributed Datasets)論文
- 翻譯進度