Tips to Improve Spark Job Execution Speed

Explore top LinkedIn content from expert professionals.

Summary

Improving Spark job execution speed means making your data processing tasks run faster and more smoothly by adjusting how Spark handles computing resources, partitions, and joins. Spark is a powerful tool for big data analytics, but without proper setup and tuning, jobs can be slow and costly.

  • Right-size resources: Choose cluster settings that match your workload by balancing memory, CPU cores, and node types to avoid both underpowered and oversized setups.
  • Repartition data: Spread data across partitions based on key columns to help Spark process tasks in parallel and prevent slowdowns from uneven workloads or data skew.
  • Use broadcast joins: When joining a large table with a small one, consider broadcasting the small table so Spark avoids heavy data shuffling and speeds up the merge process.
Summarized by AI based on LinkedIn member posts
  • View profile for Jakub Lasak

    Helping 20k+ Databricks Data Engineers become seniors | Spark, Delta Lake, Unity Catalog | ex-Uber

    15,602 followers

    Say we're processing a dataset of 500 GB in Databricks. How would you configure the cluster to achieve optimal performance? If you’ve ever waited hours for a Spark job to finish or wasted credits on an oversized cluster, you know how critical proper sizing is. Here’s a practical guide to configuring your Databricks cluster for a 500 GB workload, based on best practices and real-world experience. 📊 𝗣𝗮𝗿𝘁𝗶𝘁𝗶𝗼𝗻𝗶𝗻𝗴: 𝗙𝗼𝗰𝘂𝘀 𝗼𝗻 𝗦𝗵𝘂𝗳𝗳𝗹𝗲 𝗣𝗮𝗿𝘁𝗶𝘁𝗶𝗼𝗻𝘀, 𝗡𝗼𝘁 𝗧𝗮𝗯𝗹𝗲 𝗣𝗮𝗿𝘁𝗶𝘁𝗶𝗼𝗻𝘀 For datasets under 1 TB, avoid manual table partitioning. Instead, leverage Delta Lake’s Liquid Clustering and auto-compaction features to optimize file sizes and layout without the complexity of static partitions. Shuffle partitions are where Spark parallelizes your work during joins, aggregations, and shuffles. Rule of thumb: Aim for 128–256 MB per shuffle partition. Calculation: 500 GB × 1024 MB/GB ÷ 200 MB/partition ≈ 2560 partitions Set this with spark.sql.shuffle.partitions = 2560. Adaptive Query Execution (AQE) will fine-tune this at runtime. ⚙️ 𝗖𝗹𝘂𝘀𝘁𝗲𝗿 𝗦𝗶𝘇𝗶𝗻𝗴: 𝗘𝘅𝗲𝗰𝘂𝘁𝗼𝗿𝘀, 𝗖𝗼𝗿𝗲𝘀, 𝗮𝗻𝗱 𝗠𝗲𝗺𝗼𝗿𝘆 Cores per executor: Keep it between 2–5 cores. I recommend 4 cores per executor for balanced CPU utilization and manageable JVM overhead. Total cores: You don’t need one core per partition. Instead, size your cluster to process many partitions in parallel without overwhelming resources. Example: 16 worker nodes × 8 cores each = 128 total cores. This means 128 partitions processed concurrently, with the rest queued. - Memory per core: Allocate 4–8 GB RAM per core depending on workload complexity. Example: 128 cores × 6 GB = 768 GB total executor memory. Spread across 16 nodes → ~48 GB RAM per node for executors (leaving headroom for OS and overhead). Node type: Use memory-optimized instances for shuffle-heavy workloads. For cost savings, consider spot instances with autoscaling enabled. ⚖️ 𝗛𝗮𝗻𝗱𝗹𝗶𝗻𝗴 𝗗𝗮𝘁𝗮 𝗦𝗸𝗲𝘄 Detect skew: Use the Spark UI to spot tasks that take significantly longer than others. Mitigate skew: Enable Adaptive Query Execution (AQE) (default in modern Databricks runtimes). AQE dynamically optimizes skewed joins and shuffle partitions. If AQE isn’t enough, apply salting: add a random prefix to skewed keys before shuffle joins, then remove it after. 💡 𝗙𝗶𝗻𝗮𝗹 𝗧𝗶𝗽𝘀: - Don’t trust defaults. Always check and tune spark.sql.shuffle.partitions based on your data size - Monitor jobs. Look for garbage collection pauses, data spills, and skewed task durations - Iterate. Start with a conservative cluster size and scale based on observed metrics 📝 𝗧𝗟;𝗗𝗥 - Shuffle partitions: ~2560 (200 MB each) - Executors: 4 cores per executor - Total cores: ~128 (e.g., 16 nodes × 8 cores) - Memory per core: 4–8 GB (start with 6 GB) - Node type: Memory-optimized, spot instances - Skew handling: Enable AQE, use salting if needed How do you tune your jobs? #Databricks

  • View profile for MONU KUMAAR

    Serving Notice Period | Senior Data Engineer | Databricks Certified Professional | Azure . Scala· Databricks · PySpark · Delta Lake | Lakehouse Architecture & Real-Time Pipelines | 5TB+/day at Scale | Gen AI × Data

    15,471 followers

    🔁 How I Optimized a PySpark Job That Was Taking 2 Hours – Now It Finishes in Just 10 Minutes! Performance tuning is a data engineer’s secret superpower 💪 — and I recently had the chance to use it on a PySpark job that was painfully slow. 📍 The Problem: A daily ETL job processing 100M+ rows was taking over 2 hours to complete. It was clogging up the pipeline and delaying downstream processes. ⚙️ What I Did to Optimize It: ✅ 1. Caching I cached intermediate DataFrames that were reused multiple times. This reduced repeated computations and I/O. df.cache() ✅ 2. Partitioning Input data was poorly partitioned. I used repartition() based on a high-cardinality column, which balanced the load across executors. df = df.repartition("customer_id") ✅ 3. Broadcast Joins Switched a skewed join to use broadcast join for a smaller dimension table (30K rows). It prevented massive data shuffling. df = fact_df.join(broadcast(dim_df), "key") ✅ 4. Predicate Pushdown Filtered early in the pipeline instead of after joins. This significantly reduced the volume of data being shuffled. df = df.filter(col("status") == "active") 📈 Result: Runtime reduced from 2 hours → 10 minutes 🚀 Cluster cost dropped by 70% Downstream jobs now start early — smoother scheduling! 💡Takeaway: PySpark is powerful, but without optimization, it can also be painfully slow. Understanding how Spark executes under the hood makes all the difference. Have you had a similar experience optimizing PySpark or Spark jobs? Let’s exchange tips in the comments 👇 #PySpark #DataEngineering #ApacheSpark #BigData #ETL #PerformanceOptimization #SparkSQL #TechLeadership #DataPipeline #BroadcastJoin #PredicatePushdown #Partitioning #Caching

  • View profile for Rahul Agrawal

    Snowflake Developer | Data Engineer | SQL & Python | ETL/ELT Pipelines | Cloud Data Warehousing | 9+ Years Data Experience I also share data analytics & Snowflake content with 18K+ audience. Open to collaboration

    18,254 followers

    Mastering Spark Optimization: A Data Engineer’s Edge Working with Apache Spark is powerful — but without the right optimizations, even the best clusters can struggle. Over the years, I’ve realized that Spark optimization is not just about cutting costs, but about unlocking real performance and scalability. Here are some key Spark optimization techniques every data engineer should keep in their toolkit: 🔹 1. Optimize Data Formats Use columnar formats like Parquet or ORC instead of CSV/JSON. They reduce storage size and speed up queries significantly. 🔹 2. Partitioning & Bucketing Partition data wisely on frequently used keys. Use bucketing for joins on large datasets to avoid costly shuffles. 🔹 3. Caching & Persistence Cache intermediate results when reused across stages, but be mindful of memory overhead. 🔹 4. Broadcast Joins For small lookup tables, use broadcast joins to avoid shuffle-heavy operations. 🔹 5. Shuffle Optimization Minimize wide transformations. Use reduceByKey instead of groupByKey to cut down on shuffle size. 🔹 6. Adaptive Query Execution (AQE) Enable AQE in Spark 3+ to dynamically optimize joins and shuffle partitions at runtime. 🔹 7. Resource Tuning Right-size executors, cores, and memory. More is not always better — balance matters. 🔹 8. Avoid UDF Overuse Use Spark SQL functions where possible. Built-in functions are optimized at the Catalyst level, while UDFs can be a performance bottleneck. ✨ The real game-changer: Optimization is not one-size-fits-all. Profiling your jobs and understanding data characteristics is the key. 👉 What’s your go-to Spark optimization technique that saved you the most time (or cost)? #ApacheSpark #DataEngineering #BigData #Optimization #PerformanceTuning

  • View profile for Sandhya Paghdar

    Azure Data Engineer | Databricks Engineer

    4,899 followers

    ⚡ How I Optimized a Spark Job from 45 min ➡️ 5 min in Databricks Last month, I was working on a batch ETL pipeline in Databricks that processed ~200M rows daily using PySpark. But… the job consistently took ~45 minutes, and sometimes even failed due to driver memory pressure. 🔍 Root Cause Analysis: ❌ Skewed Joins – One side had highly uneven partitions (~90% data in one key). ❌ Shuffling Chaos – Huge data shuffles due to default join strategy. ❌ Unoptimized File Sizes – Tiny Parquet files (lots of overhead). ✅ Optimization Steps I Took: Handled Data Skew ➤ Used salting technique + broadcast join for small dimension table ➤ Result: Reduced shuffle size by 80% Partitioning + Caching ➤ Repartitioned big DataFrame on join key before merge ➤ Cached intermediate result selectively File Compaction with Delta Lake ➤ Ran OPTIMIZE on Delta table to merge small files ➤ Enabled Z-Ordering for better query performance Spark Config Tuning ➤ Tuned spark.sql.shuffle.partitions and auto broadcast thresholds ➤ Switched to Photon Runtime (where supported) 🚀 Result: 🔹 Initial Runtime: 45 mins 🔹 After Optimization: ~5 mins consistently 🔹 Bonus: Saved compute cost, improved pipeline reliability, and no more memory errors! Performance tuning in Spark is a mix of art and science — understanding data volume, partitioning, joins, and file size makes all the difference. #Databricks #ApacheSpark #DeltaLake #BigData #AzureDataEngineer #DataOptimization #PySpark #DataEngineering

  • View profile for Ehsan khosravi esfarjani

    Data Engineer

    22,706 followers

    Databricks DAG Analyzer (Spark Optimization Tool) Over the past few weeks, I’ve been working on something that I believe many Data Engineers will find extremely useful — especially anyone who deals with complex ETL pipelines, slow-running Spark jobs, or ambiguous execution plans in Databricks. I built an Advanced Databricks DAG Analyzer: a fully automated Spark execution-plan intelligence engine that performs more than 60 deep optimization checks on any DataFrame. The goal was simple: Make Spark performance debugging predictable, transparent, and fast — without manually reading 1,000-line physical plans. Why I Built This Anyone who has debugged large ETL workloads in Databricks knows the pain: Physical plans change across DBR versions Shuffle and join strategies are not always obvious AQE hides or reshapes stages dynamically Data skew often goes unnoticed until jobs spill to disk Partitioning decisions depend on cluster, schema, and data shape Reading execution plans manually is slow and error-prone What This Analyzer Does The tool recursively parses Spark’s logical, physical, formatted, and JSON plans to derive insights that are normally buried deep inside internal structures. 1. Tree-based plan parsing Stable across DBR 14+, even when operator names change. It can detect Spark operations such as: Repartition Rebalance Exchange BHJ / SMJ / SHJ WindowExec Expand, SortExec, RangePartition, AQE Coalesce 2. Data-level intelligence Automatically checks: Data skew (approxQuantile-based) Cardinality (top 3 high-cardinality columns) Partition balance File count + file size distribution Column counts, nested types, wide table patterns 3. Execution-plan intelligence Detects: Expensive shuffles Join strategies Window functions Sort/Exchange hotspots Redundant operations AQE behavior (broadcast, coalesce, skew splitting) Memory spill risk 4. Infrastructure-aware decisions Uses cluster config + dataset size to evaluate: Optimal partition counts Output partition strategy Repartition/coalesce misuse Join output explosion Aggregation risk 5. 60+ Optimization Signals For each priority, it produces: Bottleneck type Severity Estimated impact Code pattern reference Clear recommendation Healthy/Warning/Bottleneck status GitHub: https://lnkd.in/gygp9Epu

  • View profile for Vanaja S

    Analytics | Modeler | BI | AWS, Azure, GCP | Reports | Transforming Data into Strategic Insights | HIPAA | High-Performance Data Pipelines | Ensure Data Quality | Visualization

    3,106 followers

    Partitioning in Spark: The Silent Performance Multiplier One of the biggest lessons I've learned while working on large-scale data platforms is that Spark performance is often determined less by the code you write and more by how your data is partitioned. Many teams focus heavily on optimizing transformations, joins, and cluster sizing, but overlook partitioning strategy. The result? ❌ Jobs running for hours instead of minutes ❌ Unnecessary cloud compute costs ❌ Data skew issues ❌ Thousands of small files affecting downstream analytics ❌ Executors sitting idle while a few struggle with massive partitions The reality is simple: 🔹 Too Few Partitions Poor parallelism Resource underutilization Long-running tasks Bottlenecks during processing 🔹 Too Many Partitions Excessive scheduling overhead Small file problem Increased metadata management Slower query performance The goal is not to maximize or minimize partitions. ✅ The goal is to find the right partitioning strategy based on data volume, workload pattern, cluster resources, and downstream consumption requirements. A few practices that have consistently improved performance in enterprise data platforms: ✔ Monitor data skew before large joins ✔ Tune spark.sql.shuffle.partitions instead of relying on defaults ✔ Use repartition() strategically before joins and aggregations ✔ Use coalesce() before writing outputs to avoid small files ✔ Consider both Spark partitions and storage partitions separately ✔ Continuously validate partition sizes as data volumes grow The difference between an average Spark job and a highly optimized Spark job often comes down to a single question: 👉 "Are your partitions helping your cluster work in parallel, or are they becoming the bottleneck?" In modern data engineering, partitioning is not just a Spark concept—it's a cost optimization strategy, a scalability strategy, and a performance strategy. Better partitioning = Faster pipelines + Lower costs + Happier users. What is the biggest Spark partitioning challenge you've faced in production—data skew, small files, shuffle bottlenecks, or executor imbalance? #DataEngineering #DataEngineer #BigData #DataPipelines #ETL #ELT #DataArchitecture #DataIntegration #DataModeling #DataLake #DataWarehouse #DataMart #DataPlatform #DataInfrastructure #DataManagement #DataGovernance #DataQuality #DataValidation #DataLineage #Metadata #DataCatalog #MasterDataManagement #DataSecurity #DataCompliance #GDPR #HIPAA #BatchProcessing #RealTimeData #StreamingData #EventDrivenArchitecture #DistributedSystems #ScalableSystems #CloudComputing #CloudData #AWS #Azure #GCP #MultiCloud #Snowflake #Databricks #DeltaLake #Redshift #BigQuery #Synapse #ApacheSpark #PySpark #SparkSQL #Hadoop #Hive #HDFS #Kafka #ApacheAirflow #DBT #Informatica #Talend #SSIS #NiFi #Flink #Storm #Python #SQL #Scala #Java #ShellScripting #RESTAPI #GraphQL #Microservices #Docker #Kubernetes #Terraform #CI_CD #DevOps #DataOps #MLOps

  • View profile for Santhosh J

    Data Engineer | Big Data Developer | Big Data Engineer | Databricks | Scala | Python | Spark | SQL | Hadoop | Hive | AWS Glue | AWS EMR | AWS Red Shift | AWS IAM | Shell Scripting | DSA | AWS Lambda | AWS | Snow Flake

    2,222 followers

    𝐌𝐚𝐬𝐭𝐞𝐫𝐢𝐧𝐠 𝐒𝐩𝐚𝐫𝐤 𝐎𝐩𝐭𝐢𝐦𝐢𝐳𝐚𝐭𝐢𝐨𝐧: 𝐀 𝐃𝐚𝐭𝐚 𝐄𝐧𝐠𝐢𝐧𝐞𝐞𝐫’𝐬 𝐄𝐝𝐠𝐞 Working with Apache Spark is powerful — but without the right optimizations, even the best clusters can struggle. Over the years, I’ve realized that Spark optimization is not just about cutting costs, but about unlocking real performance and scalability. Here are some key Spark optimization techniques every data engineer should keep in their toolkit: 🔹 1. Optimize Data Formats Use columnar formats like Parquet or ORC instead of CSV/JSON. They reduce storage size and speed up queries significantly. 🔹 2. Partitioning & Bucketing Partition data wisely on frequently used keys. Use bucketing for joins on large datasets to avoid costly shuffles. 🔹 3. Caching & Persistence Cache intermediate results when reused across stages, but be mindful of memory overhead. 🔹 4. Broadcast Joins For small lookup tables, use broadcast joins to avoid shuffle-heavy operations. 🔹 5. Shuffle Optimization Minimize wide transformations. Use reduceByKey instead of groupByKey to cut down on shuffle size. 🔹 6. Adaptive Query Execution (AQE) Enable AQE in Spark 3+ to dynamically optimize joins and shuffle partitions at runtime. 🔹 7. Resource Tuning Right-size executors, cores, and memory. More is not always better — balance matters. 🔹 8. Avoid UDF Overuse Use Spark SQL functions where possible. Built-in functions are optimized at the Catalyst level, while UDFs can be a performance bottleneck. #PySpark #BigData #DataEngineering #Spark #PySparkLearning #CloudData #ETL #DataProcessing #MachineLearning #Analytics #TechCareer #Coding #AI #DataPipeline #DataScience

  • View profile for Hetvi Shah

    Data Analyst | Data Scientist | Python | SQL | Power BI | Machine Learning | Healthcare Analytics | ETL | Azure | Open to U.S. Opportunities

    3,048 followers

    Junior data engineers write Spark like it's pandas. Then they wonder why their job takes 4 hours instead of 4 minutes. The 6 things that separate a senior Spark engineer from a junior one are not the syntax. They are the mental model of how Spark actually runs your code. Here are the 6 Spark patterns every senior DE knows cold 👇 𝟏. 𝐓𝐡𝐞 𝐒𝐡𝐮𝐟𝐟𝐥𝐞 (your #1 enemy) → Wide transformations move data across executors → groupBy, join, distinct, orderBy all trigger shuffles → Each shuffle = network + disk + slow ↳ Senior Sparkers count their shuffles. 𝟐. 𝐏𝐚𝐫𝐭𝐢𝐭𝐢𝐨𝐧𝐢𝐧𝐠 𝐒𝐭𝐫𝐚𝐭𝐞𝐠𝐲 → Partition by columns you filter on (predicate pushdown) → Repartition vs coalesce → Avoid 200 small files OR 1 giant file ↳ Wrong partitioning makes good code slow. 𝟑. 𝐁𝐫𝐨𝐚𝐝𝐜𝐚𝐬𝐭 𝐉𝐨𝐢𝐧𝐬 → Small table (< 10MB)? broadcast(df) joins it → Avoids the shuffle entirely → AQE (Adaptive Query Execution) auto-picks in Spark 3+ ↳ The simplest 10x speedup in Spark. 𝟒. 𝐃𝐚𝐭𝐚 𝐒𝐤𝐞𝐰 → One key has 90% of the data → Causes "long tail" stragglers, jobs that never finish → Fixes: salting, skew hints, AQE skew join handling ↳ Skew is why "100M rows" can hang on 1 executor for hours. 𝟓. 𝐂𝐚𝐜𝐡𝐢𝐧𝐠 + 𝐏𝐞𝐫𝐬𝐢𝐬𝐭𝐢𝐧𝐠 → Reuse DataFrames across actions? Cache once → Pick the right storage level (MEMORY_ONLY vs DISK) → Unpersist when done. Memory is a budget. ↳ Most "Spark is slow" complaints = missing cache. 𝟔. 𝐂𝐨𝐥𝐮𝐦𝐧𝐚𝐫 𝐅𝐨𝐫𝐦𝐚𝐭𝐬 → Parquet > CSV. Always. In every case. → Predicate pushdown + column pruning + compression → Delta / Iceberg add ACID + time travel on top ↳ CSV in your data lake = 10x your cost. The honest mental model: → Junior: writes correct logic, ignores execution → Mid: reads the SQL plan, fixes obvious shuffles → Senior: designs for the cluster shape from the start The trap most teams fall into: ~ Treating Spark like pandas (collect() on a 1B-row DF) ~ Never running explain() ~ Caching everything by default (uses memory you need elsewhere) ~ Ignoring data layout (CSV in the lake, no partitions) Save this. Read your next Spark UI with these 6 in mind. Which Spark pattern bit your team last? 👇 #ApacheSpark #DataEngineering #BigData #PySpark #Lakehouse

  • View profile for Sai Sneha Chittiboyina

    Senior Network Engineer| Firewall & Cloud Security Expert | Network Automation | Cisco ISE | SD-WAN | Palo Alto | AWS Azure & GCP| Cisco, Aruba & Enterprise WAN/LAN Specialist

    7,826 followers

    Your Spark job is not slow. Your fundamentals are. If your pipeline takes 2 hours, shuffles 500GB, and spills to disk — you don’t need a bigger cluster. You need better engineering. Over the years, I’ve seen Spark workloads improve 5–10x just by fixing shuffle strategy, partition sizing, and file layout — without increasing infra cost. Visual summary below 👇 🔴 1️⃣ Excessive Shuffle = Performance Killer When 500GB moves across executors, you're paying for: • Network I/O • Disk I/O • Serialization overhead ✅ What works: • Filter early • Use broadcast joins strategically • Enable AQE • Repartition only when required 500GB shuffle ➝ 50GB shuffle 🟠 2️⃣ Disk Spill = Silent Job Destroyer If Spark spills 200GB to disk, memory planning failed. Disk I/O can make your job 10x–100x slower. ✅ Fix it by: • Right-sizing partitions (~128–200MB) • Handling data skew explicitly • Avoiding unnecessary wide transformations • Proper executor memory configuration Well-designed partitions ➝ Zero spill 🔴 3️⃣ Small Files = Distributed System Nightmare 10,000 files × 5MB = Scheduler overhead + metadata pressure + slow scans. Distributed systems prefer fewer, well-sized files. ✅ Solution: • Auto Optimize (Delta) • Run OPTIMIZE regularly • Target 128–256MB file size Cleaner layout = faster scans + better parallelism. 🔥 Real impact I’ve seen: • Runtime: 2 hours ➝ 20 minutes • Shuffle: 500GB ➝ 50GB • Disk spill: Eliminated • No extra cluster cost Spark performance isn’t magic. It’s understanding how the engine actually executes your code. Great data engineers don’t just write transformations — they understand execution. What’s the biggest Spark performance issue you’ve solved recently? 💬 If this resonates, share your perspective 🔁 Spread the thought #DataEngineering #ApacheSpark #BigData #Databricks #DataArchitecture #PerformanceOptimization #CloudComputing #C2C #C2H

Explore categories