DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowThanksgiving DealsAmazon USThanksgiving week: Black Friday picks start earlyAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
FREEDOM251

Freedom251 › Blog

Why a PySpark Job Can Finish 95% in Minutes—Then Stall on One Task

By Freedom251 Team · · 9 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

A PySpark job that appears 95% complete after four minutes can still need 40 minutes because Spark reports progress by tasks, not by equal portions of elapsed time. One task may own a much larger shuffle partition, a heavily repeated key, or a slow executor. Data skew is a credible hypothesis, not a conclusion from the progress bar alone. Confirm it in the Spark UI by comparing the tail task with its peers—especially duration, shuffle-read bytes, records, spill, and executor details—before changing code or configuration.

Why can the last Spark task take longer than all the others?

Spark divides a stage into tasks, and a stage cannot finish until every required task finishes. The progress display therefore exaggerates completion when most partitions are easy and one partition is expensive. “95% complete” may mean that 95% of task attempts have reported success, not that 95% of the data, CPU work, or wall-clock time has been processed.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A common pattern is a shuffle stage with many ordinary partitions and one oversized partition. A reducer assigned that partition must read its shuffle blocks, deserialize records, perform joins or aggregations, spill to disk if memory is insufficient, and write output. The other tasks can finish while that reducer continues. The same visual symptom can come from a slow executor, an I/O problem, expensive user-defined code, or repeated task failures, so the long tail is a symptom rather than a diagnosis.

The incident in the headline cannot be assigned a definite cause without its Spark UI metrics, physical plan, key distribution, Spark version, and executor logs. Skew becomes more likely when the slow task has substantially more input, shuffle data, or records than its peers.

Popular on Amazon
Sale
Silkland 40Gbps USB C 90 Degree Right Angle Adapter 2 Pack, 240W USB4 | Male to Female Extender, 8K@60Hz, Thunderbolt 4/3, Steam Deck, ROG Ally, MacBook, Switch 2, iPhone 18/17/16/15, Quest 3 VR
  • 【90 Degree Full Function USB C Adapter】Supports the latest USB4 standard for up to 40Gbps of bandwidth, 8K video support, and up to 240W Fast charging; Support USB PD 3.1 Extended Power Range (EPR) including 140W, 180W and 240W. Your productivity is easily doubled. *Warm Tip: For the best fit, please make sure the USB-C port is fully exposed; thick or bulky cases may affect compatibility.
  • 【Reliable Quality】Made from high-quality, scratch-resistant aluminum alloy, delicate metal frame. get excellent wear resistance and heat dissipation. Non-Slip Design for easier insertion and removal.
  • 【Small and portable】Ultra thin size, ultra compact design, a petite physique that matches the minimalist design of your modern laptops. Coming with a slim figure that won't block the port next to the one it's plugged into.
  • 【Compatibility】Widely work with most usb c, thunderbolt 4/3 devices. Compatibilit for ROG Ally, Steam Deck, Switch, MacBook Pro, Quest 3 VR headset, Surface Book 2, iPhone 18/17/16/15, Samsung Galaxy S23/S22/S21, Note 20/10, Google Pixel, ChromeBook, etc.
  • 【Excellence Customer Support】If you experience any issues or cable failure, simply reach out to our dedicated customer service team. We provide a prompt response within 18 hours, providing you with the necessary technical support to resolve any concerns.

How do I tell whether data skew is responsible?

Compare the outlier task with the other tasks in the same stage. A large duration gap combined with an unusually large shuffle read or record count supports a skew explanation; duration alone does not prove it.

  1. Identify the stage. In the Spark UI, open the job and then the stage containing the long-running task. Note the stage description and link it to the SQL query plan or the PySpark operation that created it.
  2. Read the stage summary. Look at task-duration distribution, input and output, shuffle read and write, records, and spill. Percentiles are more informative than the average because a single tail task can distort the mean.
  3. Open the task table. Sort by duration, shuffle read, records, and spill. Compare the slow task with median and 75th-percentile peers. Databricks presents comparing maximum duration with the 75th percentile—and a gap of about 50%—as a screening heuristic. That is provider guidance, not a universal Apache Spark threshold; treat it as a prompt to investigate rather than a pass/fail rule.
  4. Check the executor. If the task has ordinary input but much longer runtime, inspect executor identity, garbage collection, disk or network errors, and task logs. A single unhealthy or contended worker can create a tail unrelated to key skew.
  5. Inspect the plan and keys. For a join or aggregation, determine which columns define the shuffle and count their frequencies. A small number of very frequent keys, such as a default or unknown identifier, can concentrate work in one partition.

The Spark UI guidance on long stages describes the task-level metrics and spill signals worth examining. Use the same investigative method on other Spark distributions, while recognizing that labels and dashboards can differ.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What does a skewed partition look like in the Spark UI?

A skewed partition typically stands out in several metrics at once. Its task duration is far above neighboring tasks, and its shuffle-read bytes or records are also much larger. High memory or disk spill can appear because the reducer must process more data than the others. The combination is stronger evidence than any single number.

For example, suppose 199 tasks read roughly similar amounts while one task reads many times more shuffle data and processes a disproportionate record count. That pattern is consistent with a hot key or uneven partitioning. If all tasks read similar amounts but one executor spends much longer in garbage collection or has slow storage, the likely remedy is operational rather than a repartitioning strategy.

Remember that Spark’s task count is not a data-volume percentage. A stage with 200 tasks can show 199 completed tasks while the remaining task still owns a large fraction of the bytes. A progress bar cannot reveal that imbalance.

Also popular on Amazon
Sale
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

When can Adaptive Query Execution fix the tail?

Adaptive Query Execution (AQE) can use runtime statistics to re-optimize a Spark SQL plan during execution. Apache Spark’s performance-tuning documentation says AQE has been enabled by default since Spark 3.2.0 and defines it as re-optimizing a query plan in the middle of execution from accurate runtime statistics. Its skew handling is specific: it targets qualifying skewed shuffle partitions in supported joins, not every skewed PySpark transformation.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check the deployed Spark release and the physical plan before assuming AQE is active. A managed service may apply its own defaults or limits. In Spark 3.5.6 documentation, a skewed join partition must exceed both the configured skew-factor multiple of the median partition size and the configured byte threshold. The documented default skew factor is 5.0. A partition that is merely larger than its neighbors but below the byte threshold will not qualify under those rules.

Use the current Spark SQL performance-tuning documentation for the release actually running on your cluster, and compare it with the Spark 3.5.6 threshold documentation when that is the version in use. Do not copy a 3.5.6 default into a different release without checking its configuration reference.

AQЕ may split or otherwise handle a skewed join partition when the join is eligible and the thresholds are met. It will not automatically rebalance every groupBy, window, Python UDF, file-writing operation, or custom RDD transformation. Confirm the adaptive plan and runtime statistics in the UI or query-execution details.

Which fix fits the execution pattern?

Choose a remedy only after you know whether the bottleneck is a supported skew join, a hot key in another operation, an actually small join side, or a faulty executor. Each option changes the execution plan in a different way.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Also popular on Amazon
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Observed pattern Candidate response Important limitation
Skewed shuffle partition in an eligible SQL join Enable and verify AQE skew-join handling; review factor and byte thresholds for the deployed version Does not cover every PySpark transformation; thresholds are version-dependent
One join side is genuinely small enough for cluster memory Evaluate a broadcast join or broadcast hint Broadcasting an oversized relation can exhaust executor memory or trigger failures
A few hot keys dominate a join or aggregation Salt hot keys, then remove the salt after the operation, or pre-aggregate before the join Requires preserving correctness; extra rows and a second aggregation may increase work
Uneven output partition sizes after a query Consider REBALANCE with AQE where supported Targets output distribution, not every upstream skew cause
Normal input but one slow worker or storage path Inspect executor logs, node health, I/O, garbage collection, and retries Repartitioning or adding executors does not repair a faulty worker

Broadcast a safely small side

If one relation is genuinely small, broadcasting it can avoid shuffling that side and prevent a large-side partition from waiting on a join shuffle. Validate its size under real serialization and executor-memory conditions. A relation that is “small” in a catalog estimate can still be too large to broadcast after expansion or projection.

Salt a hot key

Salting creates several synthetic buckets for records sharing a hot key, allowing their work to spread across reducers. The other side of the join must be expanded or matched consistently, and the salt must be removed or aggregated afterward. Apply this only when the transformed join preserves the intended results; it is not a generic switch and can increase data volume.

Pre-aggregate before the expensive operation

If the business operation permits it, aggregate or deduplicate records before the join or shuffle. Reducing repeated rows early lowers shuffle volume and can reduce the impact of a dominant key. Verify that early aggregation does not change required ordering, row-level detail, or join semantics.

Rebalance output deliberately

For output partitions that are uneven after a query, Databricks documents using REBALANCE with AQE to help produce more even output files. This is different from proving that a hot key caused an upstream join tail. Treat it as an output-layout technique, not a universal skew cure.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Will repartitioning or adding more executors solve one hot task?

Not necessarily. A plain repartition can move the same hot key to another partition without splitting the key’s work, and more executors cannot parallelize a single oversized partition by themselves. Repartitioning helps when the partitioning expression is genuinely uneven and the operation allows a better distribution; it is not evidence-based treatment for every long task.

Also popular on Amazon
Sale
BENFEI USB C Hub 5-in-1 with 4K HDMI(Certified), 100W Power Delivery, 3 USB-A, Silicone Cable, Aluminum Case Compatible with MacBook Pro/Air, iPad Pro, iMac, iPhone 15 Pro/Pro Max, XPS, Thinkpad
  • Portable and powerful USB-C HUB: BENFEI USB Type-C HUB, with super-soft and knot-free silicone woven design cable, meets most mobile office needs. Compact, lightweight, stylish, and powerful portable USB C Hub equipped with 1 x HDMI port, 1 x 100W charging, and 3 x USB ports. 18-month warranty, 24-hour response, to ensure you feel at ease when using our product.
  • Design centered on comfort and reliability: Thanks to BENFEI's end-to-end in-house cable production capability, in-house PCBA and assembly capability, using the industry's most advanced silicone woven design and process, 20cm cable in length, no knots, super-soft, the HUB is easy to use in all scenarios: laptop, tablet, stand etc. Super-soft, 25000+ life cycles, to meet your daily carrying and office needs.
  • 100W Charging: Support up to 90W USB C pass-through charging via Type-C port to keep your laptop powered. 10W is reserved for other interface operations. No data and video function on the Type-C port.
  • 4K HDMI Display: The HDMI port supports media display at resolutions up to 4K 30Hz, keeping every incredible moment detailed and ultra vivid. Please note that the C port of the Host device needs to support video output.
  • Transfer Files in Seconds: Transfer files and from your laptop at speeds up to 10 Gbps with USB A 3.2 port. Extra 2 USB A 2.0 ports are perfectly for your keyboards and mouse.

Likewise, increasing executor count may leave the tail unchanged if all other tasks already have capacity and one reducer still owns the same data. Make such changes only after measuring partition sizes and understanding the shuffle boundary.

Should I enable speculative execution?

Speculation is designed for slow task attempts, not imbalanced input. Apache Spark’s Spark 4.3.0 configuration documentation lists spark.speculation as false by default and describes relaunching tasks that are unusually slow compared with peers.

Speculation can help when one executor or node is intermittently slow: a duplicate attempt may finish on a healthier worker. It does not divide an oversized partition. Launching a second copy of the same task simply repeats the same heavy input and can consume additional cluster resources. Enable it only after executor-level evidence points to stragglers, and verify the release-specific speculation settings in the Spark configuration documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What is a practical investigation workflow?

Use this sequence before editing the job:

  1. Record the environment. Capture Spark version, deployment type, AQE and speculation settings, SQL configuration, and the exact job or query.
  2. Locate the tail stage. From the job page, open the stage with the long task and identify the associated DataFrame, SQL, or RDD operation.
  3. Compare peers. Export or note task duration, shuffle-read bytes, records, spill, input size, executor, and attempt number for the outlier and representative peers.
  4. Separate volume from hardware. Large data or record gaps point toward skew; similar volumes with one slow executor point toward node, I/O, garbage collection, or user-code issues.
  5. Check the physical plan. Confirm the shuffle and join strategy, whether the plan is adaptive, and whether runtime statistics show a qualifying skewed partition.
  6. Inspect key frequencies. Find dominant values in the join or grouping columns. Include null, empty, default, and “unknown” values, which often behave as accidental hot keys.
  7. Select one scoped change. Try the remedy that matches the branch: AQE for an eligible skew join, broadcast for a safe small side, salting or pre-aggregation for a hot key, or infrastructure investigation for an executor problem.
  8. Validate semantics and operations. Check row counts, duplicate behavior, null handling, output-file distribution, memory use, and failure rates after the change. A shorter stage that changes results is not a successful optimization.

Provider-specific advice, including guidance for AWS Glue or other managed Spark services, may not map exactly to a self-managed cluster. Treat service defaults and UI labels as implementation details to verify in that environment.

What information is still missing from the 95%-in-four-minutes example?

The headline provides no task metrics, partition sizes, key frequencies, physical plan, Spark release, or logs. Consequently, it cannot establish that data skew caused the 40-minute tail. The defensible conclusion is conditional: investigate skew first if the outlier carries disproportionate shuffle data or records, but keep slow executors, I/O, spill, expensive code, and retries in the differential diagnosis.

Also popular on Amazon
𝟒𝐏𝐚𝐜𝐤 𝐔𝐩𝐠𝐫𝐚𝐝𝐞𝐝 USB to USB C Adapter,Type-C Female to A Male Charger Converter for iPhone 18 Charger,iWatch Ultra SE 9 10,iPhone 17 Pro Max 16 15 14,Samsung S25,AirPods,iPad,Car,Xbox
  • 【Read before You Buy】 Note: This adapter is USB 2.0 version and cannot transmit HDM, VGA, or other video signals. Nevertheless, they are fully capable of charging devices,duplicating files, and can be seamlessly integrated with USB-C earphones, wireless network adapters, and SD card adapters.
  • 【Easy to Use and Safe】Thanks to modern manufacturing techniques, we've made these adapters sufficiently compact so that they can remain inserted in your device without noticeable protrusion or inconvenience. This means you don't have to constantly plug and unplug them, reducing the likelihood of wear and misalignment, and making them more convenient to carry around.
  • 【Reliable Quality】Engineered for enhanced durability, durable aluminum alloy shell material,get excellent wear resistance and heat dissipation,the male USB C and female USB connectors & the male USB and female USB C connectors are designed to be plugged and unplugged up to 20000 times. Provides data transfer, device charging, memory space expansion, and additional computer peripherals.
  • 【Think more for you】Do you need to connect a USB-C-enabled device to an odd device that only has USB-A ports? Then these USB-A male to USB-C female adapters are made for you.Simply insert the adapter into the USB-A port on the device, and you can instantly connect your USB-C device to the device that originally didn't have the correct connection port.
  • 【Trusted xiwxi Quality and Service】As a responsible brand seller, you will receive xiwxi's 12-month Quality assurance and lifetime friendly customer service, you're not just buying a product,you're investing in peace of mind with all-round quality and exceptional customer service.

Do not tune by the progress percentage alone. Save the stage details and plan from the actual run, then make the smallest change that addresses the measured bottleneck.

Frequently Asked Questions

Can a single Spark task process more than one partition?

A task normally processes one partition of its stage, while an input partition can represent very different amounts of data. A large shuffle partition therefore creates a long task even when every task has the same nominal role.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How can I find the hot key causing a skewed join?

Profile the join-key distribution before the shuffle, counting rows per key and examining the largest values separately from the median. Include null and placeholder values, then compare those counts with the partition sizes shown in the Spark UI.

Does AQE change results or only performance?

AQE is intended to change physical execution choices while preserving the query’s logical result. Custom salting, early aggregation, and filtering require their own correctness checks because they alter the dataflow and may affect duplicates or null behavior.

Why did the same code behave differently on another Spark cluster?

Spark release, SQL configurations, adaptive defaults, executor sizing, storage, and managed-service patches can all change the physical plan and task distribution. Compare the deployed version and effective configuration rather than assuming a setting from another cluster applies.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply. Prices as of November 23, 2026 11:29 am GMT+0530.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.