New Spark configuration suggestions

I know that a fair amount of people still look at the configuration suggestions I made way back when here. Since then, we’ve made a number of changes to improve performance and reliability. We’ve moved a lot of the memory and core configurations out of the spark-env.sh script into the spark-defaults.conf, which allows them to be overridden by advanced users and is generally a better place to put those things. We’re also working on limiting the number of cores used by spark and the amount of memory in order to leave some space for OS and background processes, (hopefully preventing runaway load problems we’ve been fighting for a long time).

Upcoming changes will, I believe, provide even better performance and stability. We will be moving the spark.local.dirs from a single, slow HDD to 3x SSDs (consumer grade, but generally good performance/$). This should prevent the memory filling up from the reduce phase outrunning the disk. I strongly recommend making this change in your environment, if at all possible.

The new spark-defaults.conf:

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Default system properties included when running spark-submit.
# This is useful for setting default environmental settings.

# Example:
# spark.master                     spark://master:7077
# spark.eventLog.enabled           true
# spark.eventLog.dir               hdfs://namenode:8021/directory
# spark.serializer                 org.apache.spark.serializer.KryoSerializer
# spark.driver.memory              5g
# spark.executor.extraJavaOptions  -XX:+PrintGCDetails -Dkey=value -Dnumbers="one two three"
#########################################################################
spark.akka.timeout=300s 
spark.rpc.askTimeout=300s 
spark.storage.blockManagerHeartBeatMs=30000
spark.rpc.retry.wait=30s 
spark.kryoserializer.buffer.max=1024m
spark.core.connection.ack.wait.timeout=600s
spark.driver.maxResultSize=0
spark.python.worker.memory=1536m
spark.driver.memory=70g
spark.executor.memory=25g
spark.executor.cores=5
spark.akka.frameSize=2047

The identical two timeouts are because under Spark 1.6 and newer, akka is deprecated (removed entirely in 2.0.0, I believe), and without it, our workers would repeatedly drop out of the cluster.

The spark.python.worker.memory is crucial to set to a relatively small value, because pyspark operates outside the jvm(s) that is/are configured with the spark.executor.memory value. So in our environment, with 128GB nodes, we need to keep the total memory usage below 120GB. The 1536MB isn’t a hard limit, but it is the point where the python processes are instructed to start dumping their memory to disk. Depending on the application, it might be more advantageous to use less executor.memory and more python.worker.memory.

spark.executor.cores determines the amount of cores allocated to that jvm and, thus, how many spark executors will be running on the worker node. In this case, it will be 3 executors with one core left free for system processes.

The spark-env.sh file is now very trimmed down from the original (created back in the 0.7 days…):


#!/usr/bin/env bash

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This file is sourced when running various Spark programs.
# Copy it as spark-env.sh and edit that to configure Spark for your site.

ulimit -n 65535
export SCALA_HOME=/usr/local/scala-2.10.3

export SPARK_WORKER_DIR=/scratch/spark/work
export JAVA_HOME=/usr/local/jdk1.8.0_45
export SPARK_LOG_DIR=~/.spark/logs/$(date +%H-%F)/
export SPARK_WORKER_OPTS=-Dspark.worker.cleanup.enabled=true

###################################
#set disk for shuffle and spilling
#Local hdd 
export SPARK_LOCAL_DIRS=/scratch/spark/tmp

#3 local ssds
#export SPARK_LOCAL_DIRS=/scratch-ssd1/sparklocaldir,/scratch-ssd2/sparklocaldir,/scratch-ssd3/sparklocaldir

#################################

export PYSPARK_PYTHON=/usr/local/python-2.7.6/bin/python
export SPARK_SLAVES=/scratch/spark/tmp/slaves
export SPARK_SSH_OPTS="-o StrictHostKeyChecking=no -o ConnectTimeout=30"
export SPARK_PUBLIC_DNS=$HOSTNAME

## pull in users environment variables on the workers to that PYTHONPATH will transfer
source $HOME/.bash_profile

Basically all that we’re doing is selecting the versions of java, scala, and python to be used by default, allocating the location for the list of slaves (may not even be necessary with sparkflex), and setting the various local directories. Note the two options between local HDD and the 3 SSDs. These paths will of course be different in your environment. You’ll also need to make sure that the spark log directory already exists.

Advertisements

About kcarlile
Twitter: @overclockdlemon

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: