org.apache.spark
Class SparkConf

Object
  extended by org.apache.spark.SparkConf
All Implemented Interfaces:
Cloneable, Logging

public class SparkConf
extends Object
implements scala.Cloneable, Logging

Configuration for a Spark application. Used to set various Spark parameters as key-value pairs.

Most of the time, you would create a SparkConf object with new SparkConf(), which will load values from any spark.* Java system properties set in your application as well. In this case, parameters you set directly on the SparkConf object take priority over system properties.

For unit tests, you can also call new SparkConf(false) to skip loading external settings and get the same configuration no matter what the system properties are.

All setter methods in this class support chaining. For example, you can write new SparkConf().setMaster("local").setAppName("My app").

Note that once a SparkConf object is passed to Spark, it is cloned and can no longer be modified by the user. Spark does not support modifying the configuration at runtime.

param: loadDefaults whether to also load values from Java system properties


Constructor Summary
SparkConf()
          Create a SparkConf that loads defaults from system properties and the classpath
SparkConf(boolean loadDefaults)
           
 
Method Summary
 SparkConf clone()
          Copy this object
 boolean contains(String key)
          Does the configuration contain a given parameter?
 String get(String key)
          Get a parameter; throws a NoSuchElementException if it's not set
 String get(String key, String defaultValue)
          Get a parameter, falling back to a default if not set
 scala.collection.Seq<scala.Tuple2<String,String>> getAkkaConf()
          Get all akka conf variables set on this SparkConf
 scala.Tuple2<String,String>[] getAll()
          Get all parameters as a list of pairs
 String getAppId()
          Returns the Spark application id, valid in the Driver after TaskScheduler registration and from the start in the Executor.
 boolean getBoolean(String key, boolean defaultValue)
          Get a parameter as a boolean, falling back to a default if not set
static scala.Option<String> getDeprecatedConfig(String key, SparkConf conf)
          Looks for available deprecated keys for the given config option, and return the first value available.
 double getDouble(String key, double defaultValue)
          Get a parameter as a double, falling back to a default if not set
 scala.collection.Seq<scala.Tuple2<String,String>> getExecutorEnv()
          Get all executor environment variables set on this SparkConf
 int getInt(String key, int defaultValue)
          Get a parameter as an integer, falling back to a default if not set
 long getLong(String key, long defaultValue)
          Get a parameter as a long, falling back to a default if not set
 scala.Option<String> getOption(String key)
          Get a parameter as an Option
 long getSizeAsBytes(String key)
          Get a size parameter as bytes; throws a NoSuchElementException if it's not set.
 long getSizeAsBytes(String key, String defaultValue)
          Get a size parameter as bytes, falling back to a default if not set.
 long getSizeAsGb(String key)
          Get a size parameter as Gibibytes; throws a NoSuchElementException if it's not set.
 long getSizeAsGb(String key, String defaultValue)
          Get a size parameter as Gibibytes, falling back to a default if not set.
 long getSizeAsKb(String key)
          Get a size parameter as Kibibytes; throws a NoSuchElementException if it's not set.
 long getSizeAsKb(String key, String defaultValue)
          Get a size parameter as Kibibytes, falling back to a default if not set.
 long getSizeAsMb(String key)
          Get a size parameter as Mebibytes; throws a NoSuchElementException if it's not set.
 long getSizeAsMb(String key, String defaultValue)
          Get a size parameter as Mebibytes, falling back to a default if not set.
 long getTimeAsMs(String key)
          Get a time parameter as milliseconds; throws a NoSuchElementException if it's not set.
 long getTimeAsMs(String key, String defaultValue)
          Get a time parameter as milliseconds, falling back to a default if not set.
 long getTimeAsSeconds(String key)
          Get a time parameter as seconds; throws a NoSuchElementException if it's not set.
 long getTimeAsSeconds(String key, String defaultValue)
          Get a time parameter as seconds, falling back to a default if not set.
static boolean isAkkaConf(String name)
          Return whether the given config is an akka config (e.g.
static boolean isExecutorStartupConf(String name)
          Return whether the given config should be passed to an executor on start-up.
static boolean isSparkPortConf(String name)
          Return true if the given config matches either spark.*.port or spark.port.*.
static void logDeprecationWarning(String key)
          Logs a warning message if the given config key is deprecated.
 SparkConf registerKryoClasses(Class<?>[] classes)
          Use Kryo serialization and register the given set of classes with Kryo.
 SparkConf remove(String key)
          Remove a parameter from the configuration
 SparkConf set(String key, String value)
          Set a configuration variable.
 SparkConf setAll(scala.collection.Traversable<scala.Tuple2<String,String>> settings)
          Set multiple parameters together
 SparkConf setAppName(String name)
          Set a name for your application.
 SparkConf setExecutorEnv(scala.collection.Seq<scala.Tuple2<String,String>> variables)
          Set multiple environment variables to be used when launching executors.
 SparkConf setExecutorEnv(String variable, String value)
          Set an environment variable to be used when launching executors for this application.
 SparkConf setExecutorEnv(scala.Tuple2<String,String>[] variables)
          Set multiple environment variables to be used when launching executors.
 SparkConf setIfMissing(String key, String value)
          Set a parameter if it isn't already configured
 SparkConf setJars(scala.collection.Seq<String> jars)
          Set JAR files to distribute to the cluster.
 SparkConf setJars(String[] jars)
          Set JAR files to distribute to the cluster.
 SparkConf setMaster(String master)
          The master URL to connect to, such as "local" to run locally with one thread, "local[4]" to run locally with 4 cores, or "spark://master:7077" to run on a Spark standalone cluster.
 SparkConf setSparkHome(String home)
          Set the location where Spark is installed on worker nodes.
 String toDebugString()
          Return a string listing all keys and values, one per line.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.spark.Logging
initializeIfNecessary, initializeLogging, isTraceEnabled, log_, log, logDebug, logDebug, logError, logError, logInfo, logInfo, logName, logTrace, logTrace, logWarning, logWarning
 

Constructor Detail

SparkConf

public SparkConf(boolean loadDefaults)

SparkConf

public SparkConf()
Create a SparkConf that loads defaults from system properties and the classpath

Method Detail

isAkkaConf

public static boolean isAkkaConf(String name)
Return whether the given config is an akka config (e.g. akka.actor.provider). Note that this does not include spark-specific akka configs (e.g. spark.akka.timeout).

Parameters:
name - (undocumented)
Returns:
(undocumented)

isExecutorStartupConf

public static boolean isExecutorStartupConf(String name)
Return whether the given config should be passed to an executor on start-up.

Certain akka and authentication configs are required of the executor when it connects to the scheduler, while the rest of the spark configs can be inherited from the driver later.

Parameters:
name - (undocumented)
Returns:
(undocumented)

isSparkPortConf

public static boolean isSparkPortConf(String name)
Return true if the given config matches either spark.*.port or spark.port.*.

Parameters:
name - (undocumented)
Returns:
(undocumented)

getDeprecatedConfig

public static scala.Option<String> getDeprecatedConfig(String key,
                                                       SparkConf conf)
Looks for available deprecated keys for the given config option, and return the first value available.

Parameters:
key - (undocumented)
conf - (undocumented)
Returns:
(undocumented)

logDeprecationWarning

public static void logDeprecationWarning(String key)
Logs a warning message if the given config key is deprecated.

Parameters:
key - (undocumented)

set

public SparkConf set(String key,
                     String value)
Set a configuration variable.


setMaster

public SparkConf setMaster(String master)
The master URL to connect to, such as "local" to run locally with one thread, "local[4]" to run locally with 4 cores, or "spark://master:7077" to run on a Spark standalone cluster.

Parameters:
master - (undocumented)
Returns:
(undocumented)

setAppName

public SparkConf setAppName(String name)
Set a name for your application. Shown in the Spark web UI.


setJars

public SparkConf setJars(scala.collection.Seq<String> jars)
Set JAR files to distribute to the cluster.


setJars

public SparkConf setJars(String[] jars)
Set JAR files to distribute to the cluster. (Java-friendly version.)


setExecutorEnv

public SparkConf setExecutorEnv(String variable,
                                String value)
Set an environment variable to be used when launching executors for this application. These variables are stored as properties of the form spark.executorEnv.VAR_NAME (for example spark.executorEnv.PATH) but this method makes them easier to set.

Parameters:
variable - (undocumented)
value - (undocumented)
Returns:
(undocumented)

setExecutorEnv

public SparkConf setExecutorEnv(scala.collection.Seq<scala.Tuple2<String,String>> variables)
Set multiple environment variables to be used when launching executors. These variables are stored as properties of the form spark.executorEnv.VAR_NAME (for example spark.executorEnv.PATH) but this method makes them easier to set.

Parameters:
variables - (undocumented)
Returns:
(undocumented)

setExecutorEnv

public SparkConf setExecutorEnv(scala.Tuple2<String,String>[] variables)
Set multiple environment variables to be used when launching executors. (Java-friendly version.)

Parameters:
variables - (undocumented)
Returns:
(undocumented)

setSparkHome

public SparkConf setSparkHome(String home)
Set the location where Spark is installed on worker nodes.

Parameters:
home - (undocumented)
Returns:
(undocumented)

setAll

public SparkConf setAll(scala.collection.Traversable<scala.Tuple2<String,String>> settings)
Set multiple parameters together


setIfMissing

public SparkConf setIfMissing(String key,
                              String value)
Set a parameter if it isn't already configured


registerKryoClasses

public SparkConf registerKryoClasses(Class<?>[] classes)
Use Kryo serialization and register the given set of classes with Kryo. If called multiple times, this will append the classes from all calls together.

Parameters:
classes - (undocumented)
Returns:
(undocumented)

remove

public SparkConf remove(String key)
Remove a parameter from the configuration


get

public String get(String key)
Get a parameter; throws a NoSuchElementException if it's not set


get

public String get(String key,
                  String defaultValue)
Get a parameter, falling back to a default if not set


getTimeAsSeconds

public long getTimeAsSeconds(String key)
Get a time parameter as seconds; throws a NoSuchElementException if it's not set. If no suffix is provided then seconds are assumed.

Parameters:
key - (undocumented)
Returns:
(undocumented)
Throws:
NoSuchElementException

getTimeAsSeconds

public long getTimeAsSeconds(String key,
                             String defaultValue)
Get a time parameter as seconds, falling back to a default if not set. If no suffix is provided then seconds are assumed.

Parameters:
key - (undocumented)
defaultValue - (undocumented)
Returns:
(undocumented)

getTimeAsMs

public long getTimeAsMs(String key)
Get a time parameter as milliseconds; throws a NoSuchElementException if it's not set. If no suffix is provided then milliseconds are assumed.

Parameters:
key - (undocumented)
Returns:
(undocumented)
Throws:
NoSuchElementException

getTimeAsMs

public long getTimeAsMs(String key,
                        String defaultValue)
Get a time parameter as milliseconds, falling back to a default if not set. If no suffix is provided then milliseconds are assumed.

Parameters:
key - (undocumented)
defaultValue - (undocumented)
Returns:
(undocumented)

getSizeAsBytes

public long getSizeAsBytes(String key)
Get a size parameter as bytes; throws a NoSuchElementException if it's not set. If no suffix is provided then bytes are assumed.

Parameters:
key - (undocumented)
Returns:
(undocumented)
Throws:
NoSuchElementException

getSizeAsBytes

public long getSizeAsBytes(String key,
                           String defaultValue)
Get a size parameter as bytes, falling back to a default if not set. If no suffix is provided then bytes are assumed.

Parameters:
key - (undocumented)
defaultValue - (undocumented)
Returns:
(undocumented)

getSizeAsKb

public long getSizeAsKb(String key)
Get a size parameter as Kibibytes; throws a NoSuchElementException if it's not set. If no suffix is provided then Kibibytes are assumed.

Parameters:
key - (undocumented)
Returns:
(undocumented)
Throws:
NoSuchElementException

getSizeAsKb

public long getSizeAsKb(String key,
                        String defaultValue)
Get a size parameter as Kibibytes, falling back to a default if not set. If no suffix is provided then Kibibytes are assumed.

Parameters:
key - (undocumented)
defaultValue - (undocumented)
Returns:
(undocumented)

getSizeAsMb

public long getSizeAsMb(String key)
Get a size parameter as Mebibytes; throws a NoSuchElementException if it's not set. If no suffix is provided then Mebibytes are assumed.

Parameters:
key - (undocumented)
Returns:
(undocumented)
Throws:
NoSuchElementException

getSizeAsMb

public long getSizeAsMb(String key,
                        String defaultValue)
Get a size parameter as Mebibytes, falling back to a default if not set. If no suffix is provided then Mebibytes are assumed.

Parameters:
key - (undocumented)
defaultValue - (undocumented)
Returns:
(undocumented)

getSizeAsGb

public long getSizeAsGb(String key)
Get a size parameter as Gibibytes; throws a NoSuchElementException if it's not set. If no suffix is provided then Gibibytes are assumed.

Parameters:
key - (undocumented)
Returns:
(undocumented)
Throws:
NoSuchElementException

getSizeAsGb

public long getSizeAsGb(String key,
                        String defaultValue)
Get a size parameter as Gibibytes, falling back to a default if not set. If no suffix is provided then Gibibytes are assumed.

Parameters:
key - (undocumented)
defaultValue - (undocumented)
Returns:
(undocumented)

getOption

public scala.Option<String> getOption(String key)
Get a parameter as an Option


getAll

public scala.Tuple2<String,String>[] getAll()
Get all parameters as a list of pairs


getInt

public int getInt(String key,
                  int defaultValue)
Get a parameter as an integer, falling back to a default if not set


getLong

public long getLong(String key,
                    long defaultValue)
Get a parameter as a long, falling back to a default if not set


getDouble

public double getDouble(String key,
                        double defaultValue)
Get a parameter as a double, falling back to a default if not set


getBoolean

public boolean getBoolean(String key,
                          boolean defaultValue)
Get a parameter as a boolean, falling back to a default if not set


getExecutorEnv

public scala.collection.Seq<scala.Tuple2<String,String>> getExecutorEnv()
Get all executor environment variables set on this SparkConf


getAkkaConf

public scala.collection.Seq<scala.Tuple2<String,String>> getAkkaConf()
Get all akka conf variables set on this SparkConf


getAppId

public String getAppId()
Returns the Spark application id, valid in the Driver after TaskScheduler registration and from the start in the Executor.

Returns:
(undocumented)

contains

public boolean contains(String key)
Does the configuration contain a given parameter?


clone

public SparkConf clone()
Copy this object

Overrides:
clone in class Object

toDebugString

public String toDebugString()
Return a string listing all keys and values, one per line. This is useful to print the configuration out for debugging.

Returns:
(undocumented)