Performance Tuning in Apache Spark for Data Engineers

Contents

While working on Spark app tuning issue, I spent a considerable amount of time trying to make sense of the Spark web UI visualizations. Spark Web UI is a very useful tool for this task. For beginners, it becomes very difficult to get insights into a problem just from these visualizations. Although there are very good resources on Spark performance, the information was scattered. Therefore, I felt the need to document and share my learnings.

Target audience and conclusions

This post assumes that readers have a basic understanding of Spark concepts.. This post will help beginners identify potential performance issues in their applications running from a Spark web UI.. The focus is only on the information that is not obvious from the user interface and the inferences that can be drawn from this non-obvious information. Note that it does not contain an exhaustive list of information to interpret from Spark Web UI, but only those that I found relevant to my project and, but nevertheless, general enough for the audience to know.

Spark web user interface

Spark's web UI is only available when the application is running. To analyze past executions, the history server must be enabled to store event logs which can then be used to populate the web UI.

Spark Web UI displays useful information about your application in tabs, namely

  • Executors
  • Environment
  • Works
  • Etapas
  • Storage

The remaining post describes the intuitions of each of the tabs, in the order mentioned.

Executors tab

Gives information about the tasks executed by each executor.

Fig 1: Executor tab summary

42021picture201-1198431

A partir de la figure 1, it can be understood that there is a controller and 5 executors, each of which runs with 2 cores and 3 GB of memory.

The box marked in Red muestra la distribución desigual de las tareas en las que un node of the cluster está exagerando las tareas, while others are relatively inactive.

The box marked in blue shows that the size of the input data was 487,3 MB. Now, this application ran on a dataset size of 83 MB. The size of the input data comprises the reading of the original data set and the random data transfers between the nodes. This shows that a lot of data has been shuffled (about 400+ MB) in the app.

Environment tab

There are many spark properties to control and adjust the application. These properties can be set when submitting the job or when creating the context object. Unless the property is explicitly added, does not apply. We are wrong to assume that the properties are applied with their default values, when not explicitly stated. All applied properties can be seen in the Environment tab. If the property is not seen there, means that the property has not been applied at all.

Jobs tab

Un trabajo está asociado con una cadena de dependencias Resilient Distributed means fault tolerance so they can recalculate missing or damaged partitions due to node failures organizadas en un direct acyclic chart (DAY) which looks like Fig. 2. From the DAG visualizations, you can find the executed stages and the number of skipped stages. By default, spark does not reuse its calculated steps in stages, unless persisted or explicitly cached. Skipped stages are cached stages marked in gray, donde los valores de cálculo se almacenan en la memoria y no se vuelven a calcular después de acceder a HDFS. A glance at the DAG display is enough to know if RDD calculations are performed repeatedly or if cached stages are used.

Fig 2: DAG display of a job

54628picture202-8604941

Stages tab

Provides a deeper insight into the application running at the task level. A stage represents a segment of work performed in parallel by individual tasks. There is a mapping 1-1 between tasks and data partitions, namely, 1 task per data partition. One can delve into a job, in specific stages and up to each task in a stage from the Spark web UI.

The stage provides a good overview of the executions: DAG displays, event timelines, summary metrics / aggregation of your tasks.

I prefer to look at the timelines of the events to analyze the tasks. They give a pictorial representation of the details of the time invested in the execution of the stage. With a single glance, we could make quick inferences about how well the stage performed and how we could further improve the execution time.

Fig 3 – Event timeline sample

90162picture203-7870562

For instance, the inferences drawn from the figure 3 they could be:

  1. The data is divided into 15 partitions. Therefore, They are running 15 homework (represented with 15 green lines).
  2. Tasks run in 3 nodes, each one with 2 executors
  3. The stage completes only when the longest running task ends. Other executors remain inactive until the longest task is finished.
  4. Few long-running tasks, while few tasks run for a very short time, indicating that the data is not well partitioned.
  5. Not much time has been spent on delaying the scheduler or serialization at this stage, which is good.

Fig. 4 – One-stage event timeline with many data partitions.

56490picture204-6220746

Observing the figure 4, we can infer that the data is not well distributed and unnecessarily partitioned. From the evaluation metric, it can be confirmed that the task scheduling took longer than the actual execution time. The higher the percentage of green in the timeline, the more efficient will be the calculation of the stage.

It is desirable to have fewer stages in the work. Whenever data is mixed, a new stage is created. Shuffling is expensive and, Thus, try to reduce the number of stages your program needs.

Input data size

Another important information is to observe the input size of the data that has been shuffled. One of the goals is also to reduce the size of this random data.

Fig. 5 – Stages tab overview.

40949picture205-6387210

The figure 5 above shows the stages in which the data moves in MB. This suggests that the code can be improved to reduce the size of the data that has been exchanged between the stages. For instance, Let's say if a filter was applied on some data for an 'x event’ dice, then in the resulting RDD, the column "event" becomes redundant since technically all the rows are from the event 'x'. This column could be removed from future RDDs created from this filtered data to save additional information transferred during shuffle operations.

Token de almacenamiento

Shows only RDDs that have been preserved, namely, who use persist () o hide (). To make it more readable, you can name the RDD while storing it using setName (). Only the RDDs you want to keep should be displayed on the Storage tab and could be easily recognizable with the custom names provided.

Summary

This article helps provide information to identify Spark web UI issues, as the size of the data that has been shuffled, the execution time of the stages, RDD recalculation due to lack of caching. If one understands its data and its application, then the ideal data distribution and the desired number of partitions could be measured by inferring from the running UI. The overhead of one node versus others in the cluster is another area for improvement that could be seen in this user interface. The resolution de algunos de estos problemas se discute más en el Apache Spark Performance Tuning Article.

The media shown in this article is not the property of DataPeaker and is used at the author's discretion.

Subscribe to our Newsletter

We will not send you SPAM mail. We hate it as much as you.

Datapeaker