Comment on page
Optimizing a Spark application
In this example study we’ll tune the parameters of SparkPi, one of the examples applications provided by most of the Apache Spark distributions, to minimize its execution time. Application monitoring is provided by the Spark History Server APIs.
The test environment includes the following instances:
- Akamas: instance running Akamas
- Spark cluster: composed of instances with 16 vCPUs and 64 GB of memory, where the Spark binaries are installed under
/usr/lib/spark. In particular, the roles are:
- 1x master instance: the Spark node running the resource manager and Spark History Server (host:
- 2x worker instances: the other instances in the cluster
To gather metrics about the application we will leverage the Spark History Server. If it is not already running, start it on the master instance with the following command:
To make sure the tested application is available on your cluster and runs correctly, execute the following commands:
--master yarn --deploy-mode client \
--class 'org.apache.spark.examples.SparkPi' \
In this section, we will guide you through the steps required to set up on Akamas the optimization of the Spark application execution.
Here’s the definition of the system we will use to group our components and telemetry instances for this example:
description: A system to tune the Spark Pi example application
To create the system run the following command:
akamas create system system.yaml
In the snippet shown below, we specify:
- the field properties required by Akamas to connect via SSH to the cluster master instance
- the parameters required by
spark-submitto execute the application
sparkApplicationflag required by the telemetry instance to associate the metrics from the History Server to this component
description: The Spark Application used to calculate KPIs for ContentWise Analytics
componentType: Spark Application 2.3.0
args: [ 1000 ]
To create the component in the system run the following command:
akamas create component sparkPi.yaml spark
The workflow used for this study contains only a single stage, where the operator submits the application along with the Spark parameters under test.
Here’s the definition of the workflow:
name: Run SparkPi
- name: run application
To create the workflow run the following command:
akamas create workflow workflow.yaml
Here’s the definition of the component, specifying the History Server endpoint:
To create the telemetry instance in the system run the following command:
akamas create telemetry-instance telemetry.yaml spark
This telemetry instance will be able to bind the fetched metrics to the related sparkPi component thanks to the
sparkApplicationattribute we previously added in its definition.
The goal of this study is to find a Spark configuration that minimizes the execution time for the example application.
To achieve this goal we’ll operate on the number of executor processes available to run the application job, and the memory and CPUs allocated for both driver and executors. The domains are configured so that the single driver/executor process does not exceed the size of the underlying instance, and the constraints make it so that the application overall does not require more resources than the ones available in the cluster, also taking into account that some resources must be reserved for other services such as the cluster manager.
Note that this study uses two constraints on the total number of resources to be used by the spark application. This example refers to a cluster of three nodes with 16 cores and 64 GB of memory each, and at least one core per instance should be reserved for the system.
Here’s the definition of the study:
name: Speedup SparkPi execution
workflow: Run SparkPi
- name: sparkPi.driverCores
domain: [1, 10]
- name: sparkPi.driverMemory
domain: [32, 2048]
- name: sparkPi.executorCores
domain: [1, 15]
- name: sparkPi.executorMemory
domain: [32, 2048]
- name: sparkPi.numExecutors
domain: [1, 45]
- name: cap_total_allocated_cpus
formula: (spark.driverCores + spark.executorCores*spark.numExecutors) <= 15*3
- name: cap_total_allocated_memory
formula: (spark.driverMemory + spark.executorMemory*spark.numExecutors) <= 60*3
- name: baseline
- name: tune
To create and run the study execute the following commands:
akamas create study study.yaml
akamas start study 'Speedup SparkPi execution'