Lesson 5 of 6 AWS Glue

Tuning Glue Jobs for Performance and Cost

This lesson explains the handful of settings that most Glue performance and cost questions come down to: worker type and count, execution class, how much data the job reads, and how it handles many small files.

Learning outcomes

After completing this lesson, you will be able to:

  • Choose worker types, auto scaling and Flex execution.
  • Read less data with pushdown predicates and bookmarks.
  • Diagnose slow jobs with observability metrics and the Spark UI.

Workers and execution

Glue job performance and cost depend on the worker type and execution settings. G.1X and G.2X workers, with one or two data processing units (DPUs) each, suit general ETL. G.4X and G.8X workers provide much more memory and compute per worker for heavy jobs, such as large joins and aggregations. Auto scaling lets Glue add and remove workers during a run, up to a configured maximum, so you pay only for what each stage needs. The Flex execution class runs non-urgent jobs on spare capacity at a lower price, accepting that they may start later. The following table summarises the settings.

SettingUse
G.1X / G.2XGeneral ETL; 1 or 2 DPU per worker
G.4X / G.8XMemory- and compute-heavy jobs, large joins and aggregations
Auto scalingGlue adds and removes workers during the run, up to the configured maximum
Flex execution classLower price for non-urgent jobs that can start later and run on spare capacity

Out-of-memory errors on the driver usually come from collecting data to it or from listing huge numbers of small files; on executors, from skewed keys or oversized partitions. Bigger workers help the latter; fixing the cause helps both.

Scenario questions

Choosing workers

Exam skills 1.2.4 · 1.4.1

Choose the worker or execution setting for each job.

Log in to try this activity Interactive activities are free with an account.

Read less data

The most effective way to make a Glue job faster and cheaper is to make it read less data. Pushdown predicates, set with push_down_predicate, filter on partition columns before the job lists any files, so only matching partitions are read. A catalogPartitionPredicate applies the filter on the server side in the Data Catalog, which also speeds up planning for tables with very many partitions.

Job bookmarks record which data a job has already processed, so incremental runs read only new files; each source in the script needs a transformation_ctx for bookmarks to work. When the input consists of many small files, the groupFiles and groupSize options combine them into larger tasks, which reduces per-file overhead.

The following diagram shows how many partitions the job lists with and without a predicate.

Why the nightly job spent an hour before processing any rows. Without a predicate, it lists and reads every partition of a table holding three years of daily data. With a pushdown predicate on the date column, it lists and reads only yesterday's partition.
Each bar stands for about thirty daily partitions.

Diagnosing jobs

When a Glue job is slow or fails, its metrics and logs show why. Job observability metrics and the Spark UI, enabled by writing Spark event logs to Amazon S3, reveal skewed stages in which a few tasks process most of the data, spills of data from memory to disk, and executors that sit idle because the job is not parallel enough.

Job run insights analyse failed runs and point to the line of the script that failed, with suggested fixes for common errors. The driver's and executors' output is in CloudWatch Logs. Together, these usually distinguish a job that needs more or larger workers from one that needs a change to its code or data layout.

Match the pairs

Diagnosing Glue jobs

Exam skills 3.3.6 · 1.2.7

Match each question with the tool that answers it.

Log in to try this activity Interactive activities are free with an account.
Worked example

A nightly Glue job reads a table partitioned by date that holds three years of data, but only needs yesterday's partition. It takes an hour, mostly before any rows are processed.

The job lists and reads every partition. Add a pushdown predicate on the date partition column (and a catalogue partition predicate if there are very many partitions) so only yesterday's files are listed and read; enable job bookmarks if it should pick up only new files. Adding workers would not fix the wasted listing.

Check yourself

What do pushdown predicates do?

Show answer

They filter partitions in the Data Catalog before reading, so the job never reads partitions it does not need.

Exam Tips

Remember for the exam

  • Use bigger workers (G.2X to G.8X) for memory-heavy jobs.
  • Flex execution lowers cost for non-urgent jobs; auto scaling adjusts worker count during a run.
  • Pushdown predicates and catalogue partition predicates avoid reading unneeded partitions.
  • Job bookmarks make incremental processing possible; groupFiles handles many small files.
  • Spark UI and observability metrics diagnose skew, spills and idle capacity.