Optimizing a Spark application
In this example study we’ll tune the parameters of SparkPi, one of the example applications provided by most of the Apache Spark distributions, to minimize its execution time. Application monitoring is provided by the Spark History Server APIs.
Environment setup
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:
sparkmaster.akamas.io
)2x worker instances: the other instances in the cluster
Telemetry Infrastructure setup
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:
Application and Test tools
To make sure the tested application is available on your cluster and runs correctly, execute the following commands:
Optimization setup
In this section, we will guide you through the steps required to set up on Akamas the optimization of the Spark application execution.
System
System spark
Here’s the definition of the system we will use to group our components and telemetry instances for this example:
To create the system run the following command:
Component sparkPi
We’ll use a component of type Spark Application 2.3.0 to represent the application running on the Apache Spark framework 2.3.
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-submit
to execute the applicationthe
sparkApplication
flag required by the telemetry instance to associate the metrics from the History Server to this component
To create the component in the system run the following command:
Workflow
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:
To create the workflow run the following command:
Telemetry
If you have not installed the Spark History Server telemetry provider yet, take a look at the telemetry provider page Spark History Server Provider to proceed with the installation.
Here’s the definition of the component, specifying the History Server endpoint:
To create the telemetry instance in the system run the following command:
This telemetry instance will be able to bind the fetched metrics to the related sparkPi component thanks to the sparkApplication
attribute we previously added in its definition.
Study
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:
To create and run the study execute the following commands:
Last updated