Updated on 2026-11-06 GMT+08:00

Identifying Data Skew

Data skew mostly occurs in the shuffle phase. Mappers process data based on InputSplits, which are relatively uniform. Data skew refers to an uneven distribution of data within a table, resulting in huge differences in the volume of data assigned to different tasks (worker processes running on executors) after the shuffle phase. When data is unevenly distributed, some tasks complete quickly while others take a long time.

The job execution progress stays at 99% for a long time. On the Spark UI, most tasks in a stage have completed, with only a few running for a long time.

Procedure

To identify data skew on the History Server Web UI, perform the following steps:

  1. On the Stages page, select a stage with a long execution time.
  2. In the Show Additional Metrics table of the stage, check the Duration row for skew in execution time. Compare the values in the Max column (longest execution time) and those in the Median column (median execution time). Check other metrics in the table for skew in resource usage, such as memory (Peak Execution Memory) and disk (Input/Output Size).
  3. Locate the operator corresponding to the stage in the DAG based on the stage ID and then locate the SQL code snippet that causes data skew.

Usage Example

Find the Spark UI link of the corresponding job through the History Server or YARN/cluster scheduler. Go to the Spark UI and sort stages in descending order of duration on the Stages page to quickly locate the stage that takes the longest time.

For example, the task statistics summary of a stage is as follows:

Duration: min 6s, 25th % 8s, median 13s, 75th % 18s, max 26m40s 
Shuffle Read Size: min 2MB, median 15MB, max 12GB 

It indicates that the minimum, median, and maximum execution durations of all tasks in the stage are 6s, 13s, and 26 min and 40s, respectively. Shuffle read also exhibits an extreme long tail.

Sort tasks in the Tasks table by duration in descending order to locate a few tasks that took a long time. Switch to the Event Timeline view. You can find that most tasks completed quickly, while a few tasks ran for a long time.

Compare the Shuffle Read Size/Records of these long-tail tasks with those of normal tasks. If the volume of data read by a long-tail task is dozens of times or more the average value, data skew occurs (rather than the operators taking a long time). Click the task to view its stderr/stdout or the corresponding executor log. Based on the upstream Shuffle Read operator in the stage DAG, locate the key (such as new_uri_path_structure, cookie_x5check_userid, and cookie_userid) that caused the skew, and then locate the SQL fragment where the data skew occurs.