summaryrefslogblamecommitdiff
path: root/site/docs/0.6.1/configuration.html
blob: 7846b62e44aaf6aa2a527d5c2628228206592c09 (plain) (tree)


























                                                                              
                                                      






























































































































































































































































































































































                                                                                                                                                                                                                                                                                                       
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title>Spark Configuration - Spark 0.6.1 Documentation</title>
        <meta name="description" content="">

        <link rel="stylesheet" href="css/bootstrap.min.css">
        <style>
            body {
                padding-top: 60px;
                padding-bottom: 40px;
            }
        </style>
        <meta name="viewport" content="width=device-width">
        <link rel="stylesheet" href="css/bootstrap-responsive.min.css">
        <link rel="stylesheet" href="css/main.css">

        <script src="js/vendor/modernizr-2.6.1-respond-1.1.0.min.js"></script>
        
        <link rel="stylesheet" href="css/pygments-default.css">
        <script type="text/javascript">
          var _gaq = _gaq || [];
          _gaq.push(['_setAccount', 'UA-32518208-2']);
          _gaq.push(['_trackPageview']);

          (function() {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
          })();
        </script>
    </head>
    <body>
        <!--[if lt IE 7]>
            <p class="chromeframe">You are using an outdated browser. <a href="http://browsehappy.com/">Upgrade your browser today</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to better experience this site.</p>
        <![endif]-->

        <!-- This code is taken from http://twitter.github.com/bootstrap/examples/hero.html -->

        <div class="navbar navbar-fixed-top" id="topbar">
            <div class="navbar-inner">
                <div class="container">
                    <div class="brand"><a href="index.html">
                      <img src="img/spark-logo-77x50px-hd.png" /></a><span class="version">0.6.1</span>
                    </div>
                    <ul class="nav">
                        <!--TODO(andyk): Add class="active" attribute to li some how.-->
                        <li><a href="index.html">Overview</a></li>

                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Programming Guides<b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                <li><a href="quick-start.html">Quick Start</a></li>
                                <li><a href="scala-programming-guide.html">Scala</a></li>
                                <li><a href="java-programming-guide.html">Java</a></li>
                            </ul>
                        </li>
                        
                        <li><a href="api/core/index.html">API (Scaladoc)</a></li>

                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Deploying<b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                <li><a href="ec2-scripts.html">Amazon EC2</a></li>
                                <li><a href="spark-standalone.html">Standalone Mode</a></li>
                                <li><a href="running-on-mesos.html">Mesos</a></li>
                                <li><a href="running-on-yarn.html">YARN</a></li>
                            </ul>
                        </li>

                        <li class="dropdown">
                            <a href="api.html" class="dropdown-toggle" data-toggle="dropdown">More<b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                <li><a href="configuration.html">Configuration</a></li>
                                <li><a href="tuning.html">Tuning Guide</a></li>
                                <li><a href="bagel-programming-guide.html">Bagel (Pregel on Spark)</a></li>
                                <li><a href="contributing-to-spark.html">Contributing to Spark</a></li>
                            </ul>
                        </li>
                    </ul>
                    <!--<p class="navbar-text pull-right"><span class="version-text">v0.6.1</span></p>-->
                </div>
            </div>
        </div>

        <div class="container" id="content">
          <h1 class="title">Spark Configuration</h1>

          <p>Spark provides three main locations to configure the system:</p>

<ul>
  <li><a href="#environment-variables">Environment variables</a> for launching Spark workers, which can
be set either in your driver program or in the <code>conf/spark-env.sh</code> script.</li>
  <li><a href="#system-properties">Java system properties</a>, which control internal configuration parameters and can be set either
programmatically (by calling <code>System.setProperty</code> <em>before</em> creating a <code>SparkContext</code>) or through the
<code>SPARK_JAVA_OPTS</code> environment variable in <code>spark-env.sh</code>.</li>
  <li><a href="#configuring-logging">Logging configuration</a>, which is done through <code>log4j.properties</code>.</li>
</ul>

<h1 id="environment-variables">Environment Variables</h1>

<p>Spark determines how to initialize the JVM on worker nodes, or even on the local node when you run <code>spark-shell</code>,
by running the <code>conf/spark-env.sh</code> script in the directory where it is installed. This script does not exist by default
in the Git repository, but but you can create it by copying <code>conf/spark-env.sh.template</code>. Make sure that you make
the copy executable.</p>

<p>Inside <code>spark-env.sh</code>, you <em>must</em> set at least the following two variables:</p>

<ul>
  <li><code>SCALA_HOME</code>, to point to your Scala installation.</li>
  <li><code>MESOS_NATIVE_LIBRARY</code>, if you are <a href="running-on-mesos.html">running on a Mesos cluster</a>.</li>
</ul>

<p>In addition, there are four other variables that control execution. These can be set <em>either in <code>spark-env.sh</code>
or in each job&rsquo;s driver program</em>, because they will automatically be propagated to workers from the driver.
For a multi-user environment, we recommend setting the in the driver program instead of <code>spark-env.sh</code>, so
that different user jobs can use different amounts of memory, JVM options, etc.</p>

<ul>
  <li><code>SPARK_MEM</code>, to set the amount of memory used per node (this should be in the same format as the 
 JVM&rsquo;s -Xmx option, e.g. <code>300m</code> or <code>1g</code>)</li>
  <li><code>SPARK_JAVA_OPTS</code>, to add JVM options. This includes any system properties that you&rsquo;d like to pass with <code>-D</code>.</li>
  <li><code>SPARK_CLASSPATH</code>, to add elements to Spark&rsquo;s classpath.</li>
  <li><code>SPARK_LIBRARY_PATH</code>, to add search directories for native libraries.</li>
</ul>

<p>Note that if you do set these in <code>spark-env.sh</code>, they will override the values set by user programs, which
is undesirable; you can choose to have <code>spark-env.sh</code> set them only if the user program hasn&rsquo;t, as follows:</p>

<div class="highlight"><pre><code class="bash"><span class="k">if</span> <span class="o">[</span> -z <span class="s2">&quot;$SPARK_MEM&quot;</span> <span class="o">]</span> ; <span class="k">then</span>
<span class="k">  </span><span class="nv">SPARK_MEM</span><span class="o">=</span><span class="s2">&quot;1g&quot;</span>
<span class="k">fi</span>
</code></pre>
</div>

<h1 id="system-properties">System Properties</h1>

<p>To set a system property for configuring Spark, you need to either pass it with a -D flag to the JVM (for example <code>java -Dspark.cores.max=5 MyProgram</code>) or call <code>System.setProperty</code> in your code <em>before</em> creating your Spark context, as follows:</p>

<div class="highlight"><pre><code class="scala"><span class="nc">System</span><span class="o">.</span><span class="n">setProperty</span><span class="o">(</span><span class="s">&quot;spark.cores.max&quot;</span><span class="o">,</span> <span class="s">&quot;5&quot;</span><span class="o">)</span>
<span class="k">val</span> <span class="n">sc</span> <span class="k">=</span> <span class="k">new</span> <span class="nc">SparkContext</span><span class="o">(...)</span>
</code></pre>
</div>

<p>Most of the configurable system properties control internal settings that have reasonable default values. However,
there are at least four properties that you will commonly want to control:</p>

<table class="table">
<tr><th>Property Name</th><th>Default</th><th>Meaning</th></tr>
<tr>
  <td>spark.serializer</td>
  <td>spark.JavaSerializer</td>
  <td>
    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 recommend <a href="tuning.html">using <code>spark.KryoSerializer</code>
    and configuring Kryo serialization</a> when speed is necessary. Can be any subclass of 
    <a href="api/core/index.html#spark.Serializer"><code>spark.Serializer</code></a>).
  </td>
</tr>
<tr>
  <td>spark.kryo.registrator</td>
  <td>(none)</td>
  <td>
    If you use Kryo serialization, set this class to register your custom classes with Kryo.
    You need to set it to a class that extends 
    <a href="api/core/index.html#spark.KryoRegistrator"><code>spark.KryoRegistrator</code></a>).
    See the <a href="tuning.html#data-serialization">tuning guide</a> for more details.
  </td>
</tr>
<tr>
  <td>spark.local.dir</td>
  <td>/tmp</td>
  <td>
    Directory 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.
  </td>
</tr>
<tr>
  <td>spark.cores.max</td>
  <td>(infinite)</td>
  <td>
    When running on a <a href="spark-standalone.html">standalone deploy cluster</a> or a
    <a href="running-on-mesos.html#mesos-run-modes">Mesos cluster in "coarse-grained"
    sharing mode</a>, how many CPU cores to request at most. The default will use all available cores.
  </td>
</tr>
</table>

<p>Apart from these, the following properties are also available, and may be useful in some situations:</p>

<table class="table">
<tr><th>Property Name</th><th>Default</th><th>Meaning</th></tr>
<tr>
  <td>spark.mesos.coarse</td>
  <td>false</td>
  <td>
    If set to "true", runs over Mesos clusters in
    <a href="running-on-mesos.html#mesos-run-modes">"coarse-grained" sharing mode</a>,
    where Spark acquires one long-lived Mesos task on each machine instead of one Mesos task per Spark task.
    This gives lower-latency scheduling for short queries, but leaves resources in use for the whole
    duration of the Spark job.
  </td>
</tr>
<tr>
  <td>spark.default.parallelism</td>
  <td>8</td>
  <td>
    Default number of tasks to use for distributed shuffle operations (<code>groupByKey</code>,
    <code>reduceByKey</code>, etc) when not set by user.
  </td>
</tr>
<tr>
  <td>spark.storage.memoryFraction</td>
  <td>0.66</td>
  <td>
    Fraction of Java heap to use for Spark's memory cache. This should not be larger than the "old"
    generation of objects in the JVM, which by default is given 2/3 of the heap, but you can increase
    it if you configure your own old generation size.
  </td>
</tr>
<tr>
  <td>spark.shuffle.compress</td>
  <td>true</td>
  <td>
    Whether to compress map output files. Generally a good idea.
  </td>
</tr>
<tr>
  <td>spark.broadcast.compress</td>
  <td>true</td>
  <td>
    Whether to compress broadcast variables before sending them. Generally a good idea.
  </td>
</tr>
<tr>
  <td>spark.rdd.compress</td>
  <td>false</td>
  <td>
    Whether to compress serialized RDD partitions (e.g. for <code>StorageLevel.MEMORY_ONLY_SER</code>).
    Can save substantial space at the cost of some extra CPU time.
  </td>
</tr>
<tr>
  <td>spark.reducer.maxMbInFlight</td>
  <td>48</td>
  <td>
    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.
  </td>
</tr>
<tr>
  <td>spark.closure.serializer</td>
  <td>spark.JavaSerializer</td>
  <td>
    Serializer class to use for closures. Generally Java is fine unless your distributed functions
    (e.g. map functions) reference large objects in the driver program.
  </td>
</tr>
<tr>
  <td>spark.kryoserializer.buffer.mb</td>
  <td>32</td>
  <td>
    Maximum object size to allow within Kryo (the library needs to create a buffer at least as
    large as the largest single object you'll serialize). Increase this if you get a "buffer limit
    exceeded" exception inside Kryo. Note that there will be one buffer <i>per core</i> on each worker.
  </td>
</tr>
<tr>
  <td>spark.broadcast.factory</td>
  <td>spark.broadcast. HttpBroadcastFactory</td>
  <td>
    Which broadcast implementation to use.
  </td>
</tr>
<tr>
  <td>spark.locality.wait</td>
  <td>3000</td>
  <td>
    Number of milliseconds to wait to launch a data-local task before giving up and launching it
    in a non-data-local location. You should increase this if your tasks are long and you are seeing
    poor data locality, but the default generally works well.
  </td>
</tr>
<tr>
  <td>spark.akka.threads</td>
  <td>4</td>
  <td>
    Number of actor threads to use for communication. Can be useful to increase on large clusters
    when the master has a lot of CPU cores.
  </td>
</tr>
<tr>
  <td>spark.master.host</td>
  <td>(local hostname)</td>
  <td>
    Hostname or IP address for the master to listen on.
  </td>
</tr>
<tr>
  <td>spark.master.port</td>
  <td>(random)</td>
  <td>
    Port for the master to listen on.
  </td>
</tr>
</table>

<h1 id="configuring-logging">Configuring Logging</h1>

<p>Spark uses <a href="http://logging.apache.org/log4j/">log4j</a> for logging. You can configure it by adding a <code>log4j.properties</code>
file in the <code>conf</code> directory. One way to start is to copy the existing <code>log4j.properties.template</code> located there.</p>

            <!-- Main hero unit for a primary marketing message or call to action -->
            <!--<div class="hero-unit">
                <h1>Hello, world!</h1>
                <p>This is a template for a simple marketing or informational website. It includes a large callout called the hero unit and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
                <p><a class="btn btn-primary btn-large">Learn more &raquo;</a></p>
            </div>-->

            <!-- Example row of columns -->
            <!--<div class="row">
                <div class="span4">
                    <h2>Heading</h2>
                    <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
                    <p><a class="btn" href="#">View details &raquo;</a></p>
                </div>
                <div class="span4">
                    <h2>Heading</h2>
                    <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
                    <p><a class="btn" href="#">View details &raquo;</a></p>
               </div>
                <div class="span4">
                    <h2>Heading</h2>
                    <p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
                    <p><a class="btn" href="#">View details &raquo;</a></p>
                </div>
            </div>

            <hr>-->

            <!--<footer>
                <p></p>
            </footer>-->

        </div> <!-- /container -->

        <script src="js/vendor/jquery-1.8.0.min.js"></script>
        <script src="js/vendor/bootstrap.min.js"></script>
        <script src="js/main.js"></script>
        
        <!-- A script to fix internal hash links because we have an overlapping top bar.
             Based on https://github.com/twitter/bootstrap/issues/193#issuecomment-2281510 -->
        <script>
          $(function() {
            function maybeScrollToHash() {
              if (window.location.hash && $(window.location.hash).length) {
                var newTop = $(window.location.hash).offset().top - $('#topbar').height() - 5;
                $(window).scrollTop(newTop);
              }
            }
            $(window).bind('hashchange', function() {
              maybeScrollToHash();
            });
            // Scroll now too in case we had opened the page on a hash, but wait 1 ms because some browsers
            // will try to do *their* initial scroll after running the onReady handler.
            setTimeout(function() { maybeScrollToHash(); }, 1)
          })
        </script>

    </body>
</html>