The full answer
Find out where the time goes first, with the Spark UI and Glue's job metrics, and then fix the cause: usually reading too much data, too many small files, skewed or excessive shuffles, or workers that are too small.
1. Diagnose
- Turn on job metrics, job observability metrics and continuous logging in the job's settings, and enable the Spark UI.
- In the Spark UI, find the slowest stage. Is it reading input, shuffling for a join or aggregation, or writing output? Are a few tasks much slower than the rest (skew)? Are executors spilling to disk or failing with out-of-memory errors?
- Check the observability metrics for worker utilisation: if workers sit idle, you are paying for capacity you don't use; if they are saturated, you need more or bigger ones.
2. Read less
- Store input as Parquet or ORC, not CSV or JSON.
- On partitioned Data Catalog tables, use a pushdown predicate so only the needed partitions are read (and catalog partition predicates for tables with very many partitions).
- Select only the columns you need, early.
- Use job bookmarks so each run processes only new data rather than everything again.
3. Fix small files
- Many small input files: set
groupFilesandgroupSizeso Glue reads them in larger groups. - Small output files:
coalesceorrepartitionbefore writing, or write Iceberg and compact.
4. Fix shuffles and skew
- Broadcast small tables in joins (
F.broadcast), filter before joining, and avoid wide transformations you don't need. - Spark's adaptive query execution (on by default in current Glue versions) coalesces shuffle partitions and splits skewed ones; tune
spark.sql.shuffle.partitionsonly if the UI shows too many tiny or too few huge tasks. - Replace Python UDFs with built-in functions, which run inside the JVM.
5. Right-size the compute
- Move to a larger worker type (G.2X, G.4X and up) for heavy joins and aggregations, or memory-optimised R types for jobs that run out of memory.
- Turn on auto scaling so Glue adds and removes workers during the run.
- Use a recent Glue version for newer Spark optimisations (Glue 5.x runs Spark 3.5, Glue 6.0 Spark 4.1).
- For jobs that are not urgent, the flex execution class costs less.
6. Check the output side
- Writing to JDBC targets or Redshift can be the bottleneck: write in parallel, or stage to S3 and use
COPYfor Redshift.
Good order of work: measure, read less, fix files, fix shuffles, then add compute. Adding workers first is the most common and most expensive mistake.
Last updated 16 October 2026