With the growing amount of data being generated by businesses, the speed at which this data can be processed is critical for analytics, reporting, machine learning, and other daily business functions. If data pipelines slow down or analytical queries are taking too long to run, many times organizations will add additional computing resources to improve the performance. Organizations may choose to add more CPU capacity, increase the size of their clusters, or upgrade their cloud infrastructure in hopes of improving the performance.
However, adding more compute does not always solve the underlying problem.
A data processing job may run slowly due to bad query execution, poor distribution of the data, too much network communication, limited storage space, or a pipeline architecture that does not allow for parallel task execution. In all such cases, using more computer power will only create a higher cost of operation for the system and not produce any appreciable performance improvement.
The same thing can happen when a company has millions of sales transactions to process, and they decide to expand their Spark cluster from four to twelve workers. However, if one worker finishes all of the work while the other eleven workers are idle, then the total processing time will probably not change much.
This illustrates a critical concept in data engineering — the amount of computational capacity provided does not determine its effectiveness; rather, the efficiency with which the workload utilizes that capacity determines its success.
This article will address why adding additional computing power is not always an effective solution for solving data processing bottlenecks, how to determine the underlying reasons for poor performance on workloads, and how to implement various optimization strategies to enhance performance with minimal expense in terms of increasing infrastructure.
What Are Data Processing Bottlenecks?
A data processing bottleneck is a single element or step in a larger process, such as a data pipeline, that constrains the overall performance (speed) of the process.
A data processing system usually has many parts, such as computing power, memory, data storage, network communication, data input, and query execution. When one part of the data processing system is not able to handle the load being put on it, then the whole process will be slowed down.
As an example, if you were to run a pipeline that had the processing power to handle millions of records per second, the limiting factor for how many records it processed would likely be getting the records out of storage. Likewise, if you were to run a distributed processing job with many workers, most of the total processing time will probably be spent on moving the data around among the workers.
Common data processing bottlenecks include:
- Compute bottlenecks: Either you have an inadequate amount of computer hardware (such as CPUs) to handle your workload, or you are not effectively utilizing the existing hardware that you do have.
- Bottlenecks related to memory: Large sets of data and/or temporary (intermediate) results that are too large for the amount of memory that is currently available.
- Storage bottlenecks: Slow data reads, writes, or inefficient file layouts.
- Network bottlenecks: Excessive data movement between workers or systems.
- Data skew: In a distributed environment, data skew is when there is an unequal amount of data across all of your tasks. This results in some of your tasks having significantly more work than others.
- Query bottlenecks: Bottlenecks can occur during a query when there is an inefficient join, unnecessary transformation of data, or a poorly designed SQL operation.
- Pipeline Bottlenecks: A sequential dependency or a slow upstream process that prevents other downstream tasks from being completed.
The initial phase of optimizing performance involves identifying which component is causing limitations.
Why Adding More Compute Doesn’t Always Work
1. The Real Bottleneck May Be Storage
Slow storage cannot be sped up by adding more CPU cores.
The performance of data processing jobs that read large amounts of data from cloud object storage, databases, or other external sources is dependent upon several factors, including: throughput of the storage system, latency of requests made to the storage system, how the data is organized in the storage system, and how the data is being accessed.
An example of this is a Data Engineering Team that increases the size of their Spark Cluster to speed up a daily reporting process. If, however, the majority of the time the workload waits for the thousands of small files to be found and read, the extra workers will most likely produce little benefit.
The problem isn’t that we don’t have enough computing power; it’s that we aren’t accessing the data as quickly as we could.
How to resolve this issue: Analyze storage read times, file counts, scan metrics, and data access patterns. Minimize the number of unnecessary data reads, enhance file organization, and apply appropriate data formats and table optimization strategies. If there are recurring analysis workloads, partitioning or clustering can also assist in minimizing the amount of data scanned.
2. Data Skew Creates Uneven Workloads
Distributed processing systems divide work among many different tasks in order to allow for simultaneous operation of numerous processes. The best results occur when the distribution of work is relatively even.
In addition to being unevenly distributed, some data sets will also have very uneven distributions of the data within the partitions themselves. Some of the keys in a data set can account for a large percentage of all records, so those partitions containing those keys will be much bigger than any other partition.
A retail organization analyzing millions of transactions based on customer IDs can find itself with a much larger amount of processing time required for a particular task if a single customer ID is found to occur many times more frequently than other customer IDs.
Even if more employees can be added to your work force, this does not mean that every job will automatically be divided into several small, equal-sized jobs.
Most employees can complete their tasks early because of this, and the whole assignment is delayed by one very large task.
To determine how to resolve this issue, analyze the time each task took to complete, the size of each partition created by the tasks, and the amount of data transferred during the shuffle process. These three elements will assist you in identifying skew. Solutions to fix the problem depend upon the type of operation being performed and can range from modifying the partitioning of data, utilizing an adaptive query optimizer, selecting a different method for joining data, or implementing a technique known as key salting.
The goal is to provide an equitable distribution of work, not just add more employees.
3. Excessive Data Shuffling Consumes Resources
Data shuffling is the process of redistributing data records among different data partitions in a distributed data processing system. Shuffling usually takes place during data processing tasks such as joining data from multiple sources, aggregating data, sorting data, and some types of data repartitioning.
To shuffle the data, there will be significant amounts of network communication, serialization, and disk activity. These expenses can potentially be a significant source of latency during the process of large-scale data processing.
As an example, if you have a Spark query that is going to join two large datasets together, there is likely going to be a lot of data that will have to go from executor to executor so that those two datasets can be combined into one with matching records.
More computer power will not eliminate the overhead associated with the communications required for distributing work among multiple computers. In addition, when there are many computers being used to perform a task, the process of exchanging data can become much more complex.
How to address this: Use execution plans and performance metrics to determine which shuffle operations are particularly expensive. Before joining, reduce the number of records, select only those columns needed for the analysis, avoid excessive re-partitioning, and look into broadcast joins if you have a very small data set that can be distributed without any issues.
Moving less data across workers is often a better option than making your cluster larger.
4. Inefficient Queries Waste Available Compute
Poorly written queries will utilize large amounts of system resources, but they may take a long time to return the requested results.
The common problems are: unneeded joins, redundant calculations, poorly performing filters, too much sorting, and processing data that will not be in the end result.
Although adding more computing power will lower the amount of time that it takes for the program to run, this will not eliminate any of the extra work that the program is doing.
For instance, a reporting query could read an entire transaction table although the report is only going to contain data for the current month. Although adding additional workers will make reading the transaction table go faster, filtering the data before it’s read can help decrease the total number of operations required.
To address the issue: Examine the query’s execution plan to find the most expensive steps. Whenever possible, apply filters directly to the data sources; only pull out those columns that are needed; make your transformations easier; and do not process the exact same data multiple times.
In addition, using built-in functions and optimizing your query will help you avoid unnecessary calculations in Spark.
5. Memory Limitations Can Restrict Performance
Some data-processing workloads need significant amounts of memory to perform operations such as joining data, aggregating data, sorting data, caching data, and producing intermediate results.
A system can use several methods when it does not have enough memory to complete its tasks. It can write some of the intermediate data to disk; it can do more garbage collection than usual; or it can simply fail at completing the task.
Adding more workers will help as long as you can properly assign the workload to each worker. However, adding more workers does not fix problems with a single task that uses too much memory, nor does it fix issues where your queries create very large intermediate result sets.
For example, if you aggregate a lot of data together, you could end up with a couple of partitions that have way too much data in them. This would mean those tasks will still be memory intensive even though there are plenty of workers on the cluster.
How to Fix This: Check the Executor Memory Metrics, Spill Activity, Garbage Collection Time, and Task Sizes. Eliminate unneeded intermediate data; handle skew; select an appropriate number of partitions. After you have dealt with inefficiencies, adjust the Compute Configuration if the Workload truly requires more Memory.
6. Network Communication Can Limit Scalability
The use of distributed computing relies upon communication among the different workers, the various types of storage systems, and any external service.
When a workload has high amounts of data being sent over the network frequently, network latency and bandwidth may limit performance.
This is especially true for distributed joins, large aggregation operations, and data pipelines that transfer data from one system to another.
The addition of extra employees may not address the issue, as the newly added resources will continue to utilize the exact same communication infrastructure. Furthermore, under certain circumstances, a larger number of computer systems performing the work can lead to an increase in both coordination and communication expenses.
Identify what is generating high levels of network traffic. Eliminate unneeded data transfer, utilize the most effective join methods, limit the number of times data has to move back and forth from one system to another, and assess if you are able to process your data closer to where it originated.
The efficiency of a distributed computer system depends on the balance between how fast it can perform calculations in parallel and the expense of sending data back and forth.
7. Sequential Pipeline Dependencies Limit Parallelism
Not every data pipeline can run all operations simultaneously.
Many tasks are dependent upon the output from previous stages. A good example would be a pipeline that ingests data, validates that data, transforms the data, and generates a report.
The overall duration of the pipeline is determined by the total amount of time required for completion of all the stages that must be finished prior to starting the next stage.
The addition of additional computing power to a subsequent processing step cannot provide a benefit when that step is idle while awaiting the completion of a previous processing step.
To fix this issue: Map the dependencies of your pipeline, then determine which stages can be executed simultaneously without causing any issues. Optimize those stages that are taking a long time to finish, eliminate unnecessary dependencies, and utilize incremental processing whenever applicable.
The main objective of the work described herein was to enhance the overall process (or “pipeline”) used by the organization to produce results rather than to focus on optimizing a single part of that process that did not cause the slowdown.
How to Identify the Actual Data Processing Bottleneck
Businesses need to identify how much time and money they are using before investing in more equipment.
1. Measure Performance Before Making Changes
Record the workload execution time, throughput, data volume, and resource utilization.
In the case of recurring pipelines, evaluate performance across several runs. Evaluating performance across several runs will assist you in determining if there is a real performance bottleneck as opposed to normal variations in either the size of your workload or the level of activity in your system.
2. Examine Execution Plans and Task Metrics
The tools for analyzing Apache Spark performance (such as the Spark UI) provide data regarding how well your Spark jobs are performing. These tools will allow you to see what is happening with each job, each stage of a job, each task within a stage, all of the shuffle activities that have occurred, and the spill metrics for each stage.
Identify stages with a few tasks that take a much larger amount of time compared to other tasks. These types of stages can point towards data skew or unevenly sized partitions.
Also determine how the workload is spending most of its time; i.e., whether it is scanning data, shuffling records, performing calculations, or waiting on external resources.
3. Check Resource Utilization
The low CPU usage during a slow job could mean that the work is being delayed because of storage access times, networking issues, or some other type of dependency.
A high amount of CPU usage could indicate a very computationally intensive workload. However, just because there is a high amount of CPU usage doesn’t mean you need to add more workers.
Other symptoms of an issue include memory pressure, disk spills, and failed executors.
4. Change One Major Factor at a Time
After you find what seems to be the bottleneck, create a specific change and evaluate how it compares to your baseline workload.
For instance, if you are planning to modify your cluster size, change the query structure and update the storage configuration at the same time, then it is recommended that you first optimize your join strategy, improve the way data is arranged on disk, or modify how you partition the data.
This makes it easier to determine which change actually improved performance.
Real-World Example: Why a Larger Spark Cluster Didn’t Help
In a situation where a company is processing customer transactions in Databricks each evening, as the company’s business expands, so does the length of time it takes to process these transactions, which will cause delays in the creation of reports for the next day.
The engineering team adds more Spark working nodes in anticipation that their jobs will be completed sooner. Unfortunately, this does little to improve performance.
The team finds that one large join has skewed data after reviewing the Spark user interface. While most tasks finish within a reasonable amount of time, there are a couple of partitions with an excessively large amount of records. Additionally, the job is shuffling too much data since it processes column values that are irrelevant to the final output.
The group addresses this issue by removing unneeded columns, enhancing their join strategies, and employing correct methods to address skew.
The team will then measure the performance of their changes by comparing the execution time, the amount of data shuffled, and the total amount of computing resources used.
The results indicate that redesigning the workload will provide greater value than simply increasing the number of nodes in a cluster.
In this example, I am showing you how to determine what the bottleneck is first and then how to scale your system.
Best Practices for Data Processing Performance Optimization
Organizations can enhance their overall productivity and manage their infrastructure expenses through the implementation of a formal, structured approach to optimizing their operations.
Optimize before scale. Evaluate the logic used for queries, how data is organized (layout), and the performance characteristics of your system (metrics) before adding additional computing capacity.
Minimize the number of data movements. Minimize expensive shuffles, repeated transfers, and large intermediate datasets.
Determine how to better distribute your workload. Analyze the data for any potential skew and/or partitions that may result in some tasks taking significantly longer than others to complete. This will help to reduce the overall time it takes to complete the entire job.
The use of the correct storage format for your data is essential to maximize query performance. For example, using a columnar storage format, such as Parquet or ORC, will result in less data being accessed when running analytical queries. Additionally, creating optimized tables can also decrease the volume of data that must be read during query execution.
Monitor how resources are being used. Monitor CPU, memory, storage, network traffic, and how long tasks take to execute to determine how your workload behaves.
The scalability of the system should be evaluated through testing. The amount of compute resources available to the system should be increased while maintaining control over the environment in which these tests are conducted, and then it should be determined if the increased resource usage provided a benefit to the workload.
Calculate the cost of a change against how well it performs. Use the amount of CPU/Memory (or other resources) used and the speed at which the application runs to assess if an improvement is worth doing for your organization.
Pipelines should be continuously monitored. Tracking recurring performance variations can help identify potential bottlenecks in advance of their impact on critical reporting and/or operations.
These practices assist organizations in increasing data pipeline performance by using existing resources rather than continually expanding their infrastructure as a primary method for improving performance.
Conclusion
Increasing compute will help with data processing performance if the workload is truly bound by CPU or memory, or is simply not able to be processed in parallel. It will not, however, automatically correct for bad queries, data skew, excessive shuffling, slow storage access, network bottlenecks, or sequential pipelines.
To be able to make changes that will result in the greatest benefit to your company’s bottom line, you should first find out what the primary problem area is (the bottleneck), determine how much it costs the company in terms of time, money, etc., and then implement an appropriate fix for that specific problem area before adding more resources.
By analyzing how their applications run on the cloud (using execution plans), making sure their data is distributed evenly across all of the machines they use for their application, eliminating any extra processing steps that are not needed, and watching what resources each machine uses to run their application, many companies will find that they can improve the speed at which their application runs and lower the amount of money they spend on cloud computing.
In conclusion, optimizing data processing is not just about having more computing power. It is also about utilizing existing resources more effectively.
Organizations that use performance monitoring along with effective data engineering practices will develop more rapid, flexible, and economical data pipelines.