

# Using the managed scaling profile for AWS Glue

The managed scaling profile is an AWS Glue managed configuration that automatically scales the number of workers for your job. You control it with one job parameter, `--scaling-profile`, which currently supports two values: `balanced` (turn the profile on) and `disabled` (turn it off). A run that uses the profile starts with a single executor, adds executors while tasks wait to run, and removes idle executors when they are not needed. The run grows up to the maximum number of workers that you set.

With the managed scaling profile, AWS Glue manages the size of your Spark cluster for you. You choose the worker type and the maximum number of workers, and AWS Glue chooses how many executors to run at each point in the run. This helps you match resources to the work, so that short jobs stay small and jobs with sustained work grow to use the capacity that you allow.

The managed scaling profile is an AWS Glue managed alternative to auto scaling. When a run sets both `--scaling-profile balanced` and `--enable-auto-scaling true`, the managed scaling profile takes priority. For more information about auto scaling, see [Using auto scaling for AWS Glue](auto-scaling.md).

This topic covers the following topics.
+ [Availability](#scaling-profile-availability)
+ [Jobs that get the managed scaling profile by default](#scaling-profile-default)
+ [What the managed scaling profile does during a run](#scaling-profile-run-behavior)
+ [Worker values with the managed scaling profile](#scaling-profile-worker-values)
+ [Enabling the managed scaling profile in AWS Glue Studio](#scaling-profile-enabling)
+ [Turning the managed scaling profile on and off](#scaling-profile-turning-on-off)
+ [Considerations and limitations](#scaling-profile-considerations)
+ [Examples](#scaling-profile-example)
+ [Error messages](#scaling-profile-errors)
+ [Metrics and observability](#scaling-profile-observability)
+ [Frequently asked questions about the managed scaling profile](#scaling-profile-faq)

## Availability
<a name="scaling-profile-availability"></a>

The managed scaling profile is available for Spark ETL jobs (`glueetl`) on AWS Glue 6.0 and later.

For a job that uses `auto` as its AWS Glue version, AWS Glue applies the managed scaling profile based on the AWS Glue version that it resolves for the run. AWS Glue allows the run on AWS Glue 6.0 and later and rejects it on AWS Glue 5.1 and earlier.

AWS Glue adds the managed scaling profile only on supported versions. It doesn't add the profile to a job on an earlier version. Upgrading an existing job to AWS Glue 6.0 or later doesn't apply the profile automatically. An upgrade behaves like any other job update, so you opt in by adding `--scaling-profile balanced`. For more information, see [Jobs that get the managed scaling profile by default](#scaling-profile-default).

## Jobs that get the managed scaling profile by default
<a name="scaling-profile-default"></a>

AWS Glue adds `--scaling-profile balanced` to the default arguments of a new job when all of the following conditions are true:

1. The job is a Spark ETL job (`glueetl`) on AWS Glue 6.0 and later.

1. The request doesn't set `--scaling-profile`.

1. The request doesn't set `--enable-auto-scaling true`.

1. The request doesn't set both `WorkerType` and `NumberOfWorkers`.

When AWS Glue adds the managed scaling profile by default, `--scaling-profile balanced` appears in the job's default arguments, which you can see with `GetJob`. It doesn't appear in `GetJobRun`.

When you set both `WorkerType` and `NumberOfWorkers`, the job opts out of getting the managed scaling profile by default and runs at that fixed size with no profile. If you also set `--scaling-profile balanced` explicitly, the job still turns the managed scaling profile on and uses `NumberOfWorkers` as the maximum.

AWS Glue adds the managed scaling profile by default only to new jobs that you create on AWS Glue 6.0 and later. It doesn't add the profile to an existing job, including a job that you update or upgrade to AWS Glue 6.0 or later. An upgrade behaves like any other job update, so AWS Glue doesn't apply the profile automatically. AWS Glue also doesn't add the profile on versions that don't support it. To turn the profile on for an existing job, add `--scaling-profile balanced` to the job's default arguments. AWS Glue never adds `disabled` on its own.

## What the managed scaling profile does during a run
<a name="scaling-profile-run-behavior"></a>

A run that uses the managed scaling profile uses a default maximum of 100 workers of the default worker type, `G.1X.GRAVITON` ([Worker types](https://docs.aws.amazon.com/glue/latest/dg/worker-types.html#graviton-worker-types)), and starts with a single executor. AWS Glue manages the number of executors within that maximum. You choose the worker type and the maximum number of workers, and AWS Glue manages the rest.

The following table describes how a run behaves with the managed scaling profile.


| Behavior | What happens | 
| --- | --- | 
| Starting size | The run starts with 1 executor. | 
| Minimum | The run keeps at least 1 executor. | 
| Maximum | The run uses at most your number of workers minus one, because one worker runs the Spark driver. For example, 100 workers allow 99 executors. | 
| Adding executors | AWS Glue adds executors after tasks have waited a few seconds, and keeps adding executors at a regular interval while tasks keep waiting. Each request is larger than the previous one. | 
| How many it adds | AWS Glue adds enough executors to run about half of the waiting tasks at once. | 
| Removing idle executors | AWS Glue removes an executor after it sits idle without work, and waits longer before it removes an executor that holds cached data. | 
| Executors that hold shuffle data | An executor that holds shuffle data, such as from a join or a groupBy, stays allocated until Spark no longer needs that data or until the run ends. | 

## Worker values with the managed scaling profile
<a name="scaling-profile-worker-values"></a>

For a Spark ETL job that uses the managed scaling profile, AWS Glue sets the worker type and the number of workers from the values in your request. The following table shows the result for each combination of worker values.


| The request sets | Result | 
| --- | --- | 
| No worker values | `G.1X.GRAVITON`, 100 workers | 
| Only `WorkerType`, for example `G.2X` | The selected worker type, 100 workers | 
| Only `NumberOfWorkers` N | `G.1X.GRAVITON`, N workers | 
| Both `WorkerType` and `NumberOfWorkers` | The worker type and number of workers as sent | 
| Only `MaxCapacity` | The AWS Glue default worker type, with the capacity converted to workers, as without the profile | 

For Spark ETL jobs on AWS Glue 6.0 and later, a request can set one or both of `WorkerType` and `NumberOfWorkers`. If you set only one value, AWS Glue fills in the other. This applies whether or not the job turns the managed scaling profile on, because it isn't gated on using the profile. `CreateJob`, `UpdateJob`, and `StartJobRun` all accept a single value. A `StartJobRun` that sets one value takes the other from the job.

Without the profile, a job that sets only `WorkerType` gets 10 workers, and a job that sets only `NumberOfWorkers` gets the AWS Glue default worker type for its version.

For streaming jobs, set both `WorkerType` and `NumberOfWorkers`, or neither value. A streaming job can't set only one value.

On AWS Glue 6.0 and later, the managed scaling profile also supports AWS Graviton (arm64) worker types. For Spark ETL jobs, the profile supports the `G.1X` through `G.16X` and `R.1X` through `R.8X` worker types on Graviton (for example, `G.1X.GRAVITON` and `R.1X.GRAVITON`). For more information, see [AWS Graviton (arm64) workers](worker-types.md#graviton-worker-types).

## Enabling the managed scaling profile in AWS Glue Studio
<a name="scaling-profile-enabling"></a>

On the **Job details** tab in AWS Glue Studio, set **Glue version** to **Glue 6.0** or later. The **Scaling profile** field appears.
+ For **Scaling profile**, choose **Balanced** to turn on the managed scaling profile. AWS Glue allocates workers for you and scales them over the job run.
+ Set the **Maximum number of workers** to define the maximum number of workers that the managed scaling profile can scale up to.

For information about turning the managed scaling profile on or off with a job parameter, see [Turning the managed scaling profile on and off](#scaling-profile-turning-on-off).

The following screenshot shows the **Job details** tab in AWS Glue Studio, with **Scaling profile** set to **Balanced** and the **Maximum number of workers** field.

![The AWS Glue Studio Job details tab, showing the Scaling profile field set to Balanced and the Maximum number of workers field.](https://docs.aws.amazon.com/glue/latest/dg/images/managed-scaling-profile-enable-studio.png)


## Turning the managed scaling profile on and off
<a name="scaling-profile-turning-on-off"></a>

You set `--scaling-profile` in a job's default arguments, in its non-overridable arguments, in a single run's `Arguments`, or in a trigger action's arguments. The value is not case-sensitive.

Non-overridable arguments are job arguments that a single run's `Arguments` can't change. You set them in the `NonOverridableArguments` field of `CreateJob` or `UpdateJob`. For example, the following non-overridable argument turns the managed scaling profile on for every run of the job:

```json
"NonOverridableArguments": {
    "--scaling-profile": "balanced"
}
```

The following table shows how to turn the profile on and off.


| To do this | Do the following | 
| --- | --- | 
| Use the managed scaling profile on an existing AWS Glue 6.0 or later ETL job | Add `--scaling-profile balanced` to the job's default arguments. | 
| Use the managed scaling profile for one run only | Add `--scaling-profile balanced` to that run's `Arguments`. | 
| Turn the managed scaling profile off for a job | Set `--scaling-profile disabled`. Removing the parameter doesn't turn the profile off. | 
| Turn the managed scaling profile off for one run | Add `--scaling-profile disabled` to that run's `Arguments`. | 
| Use auto scaling instead | Set `--enable-auto-scaling true` together with `--scaling-profile disabled`. | 
| Run a fixed number of workers | Set `--scaling-profile disabled`, without `--enable-auto-scaling true`, and set the number of workers. | 
| Change the worker type or the maximum | Edit `WorkerType` or `NumberOfWorkers` as usual. The scaling profile keeps working. | 

A run's `Arguments` override a job's default arguments, but not its non-overridable arguments. A job that has `balanced` in its non-overridable arguments uses the profile on every run. When a run has both `--scaling-profile balanced` and `--enable-auto-scaling true`, the managed scaling profile takes priority.

## Considerations and limitations
<a name="scaling-profile-considerations"></a>

The managed scaling profile is not supported for the following:
+ Streaming ETL jobs
+ Python shell jobs
+ Ray jobs
+ Interactive sessions
+ AWS Glue version 5.1 and earlier

AWS Glue rejects the `--scaling-profile` parameter on these job types and versions. For the error messages, see [Error messages](#scaling-profile-errors).

Keep the following considerations in mind when you use the managed scaling profile.
+ Removing the parameter doesn't turn the profile off. An `UpdateJob` request whose default arguments leave out `--scaling-profile` keeps a saved value of `balanced` or `disabled`. To turn the profile off, set `--scaling-profile disabled`. On the console, a parameter that you delete from **Job parameters** comes back after you save. A value in the non-overridable arguments is removed like any other argument.
+ Terraform shows a pending change until you add the parameter. If your job got the managed scaling profile by default, Terraform shows a pending removal of `--scaling-profile` on every plan. The removal has no effect when you apply it. To stop the pending change, add `--scaling-profile balanced` to your Terraform configuration.
+ AWS CloudFormation reports drift on the default arguments of jobs that got the profile by default. Drift means that a stack's actual resource configuration differs from the configuration defined in its template. For more information, see [Detecting unmanaged configuration changes to stacks and resources](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/detect-drift-stack.html).
+ CloudFormation resets worker counts that you set outside the template. A job whose worker count you changed outside its template, for example to 35, goes back to its template size on the next change to that job that uses the template. To keep a specific size, put the worker values in the template.
+ Set the managed scaling profile explicitly in your templates. In CloudFormation, CDK, and Terraform, set `--scaling-profile balanced` or `disabled` only for Spark ETL jobs on AWS Glue 6.0 and later. Don't set it on other job types or versions, where AWS Glue rejects it. If a shared module applies the same arguments to every job, add `--scaling-profile` only to the Spark ETL jobs on AWS Glue 6.0 and later, not to every job.
+ The `--scaling-profile` parameter is reserved. If your own scripts use a parameter named `--scaling-profile` with a value other than `balanced` or `disabled`, rename that parameter. A job that already had such a value continues to run with the value ignored, and keeps the value unchanged when you update the job. A trigger whose saved action has such a value keeps starting runs, but `UpdateTrigger` fails until you change the value.
+ When you turn the managed scaling profile off, the job keeps its maximum worker count. A job that you set to `--scaling-profile disabled` without `--enable-auto-scaling true` keeps its worker values, for example 100, and runs and is billed at that fixed size. The change takes effect on the next run without any disruption. To use fewer resources, lower `NumberOfWorkers` or turn on auto scaling.
+ If a Usage Profile sets a maximum number of workers below 100 and sets no default, it rejects a new job that sets no worker values, because the profile's default of 100 workers exceeds the maximum. To fix this, set a worker count within the maximum, set `--scaling-profile disabled`, or add a default to the Usage Profile.
+ A trigger action's `--scaling-profile` value overrides the job's value for every run that the trigger starts. A `disabled` value in a trigger action turns the managed scaling profile off for those runs.
+ Repeating a `CreateJob` request for an existing job can fail, because AWS Glue now adds the managed scaling profile and its worker values. A script that repeats the same `CreateJob` request for a job that you created before this launch, without worker values or `--scaling-profile`, gets `IdempotentParameterMismatchException`. To update an existing job, call `GetJob` or `UpdateJob` instead.

## Examples
<a name="scaling-profile-example"></a>

In the following examples, replace the role ARN, bucket name, and job name with your own values.

The following AWS CLI example creates an AWS Glue 6.0 job with the managed scaling profile and its defaults.

```bash
PROMPT> aws glue create-job \
  --name my-etl-job \
  --role arn:aws:iam::111122223333:role/MyGlueJobRole \
  --glue-version 6.0 \
  --command Name=glueetl,ScriptLocation=s3://amzn-s3-demo-bucket/scripts/my_etl_job.py,PythonVersion=3 \
  --default-arguments '{"--scaling-profile":"balanced"}'
```

The job gets `G.1X.GRAVITON` with a maximum of 100 workers. Omitting `--default-arguments` gives the same result, because new AWS Glue 6.0 and later ETL jobs get the managed scaling profile by default.

The following AWS CLI example sets a smaller maximum and keeps the profile.

```bash
PROMPT> aws glue create-job \
  --name my-etl-job \
  --role arn:aws:iam::111122223333:role/MyGlueJobRole \
  --glue-version 6.0 \
  --command Name=glueetl,ScriptLocation=s3://amzn-s3-demo-bucket/scripts/my_etl_job.py,PythonVersion=3 \
  --worker-type G.1X.GRAVITON \
  --number-of-workers 20 \
  --default-arguments '{"--scaling-profile":"balanced"}'
```

The following AWS CLI example turns the profile off for one run.

```bash
PROMPT> aws glue start-job-run --job-name my-etl-job --arguments '{"--scaling-profile":"disabled"}'
```

The following CloudFormation example creates the same job.

```yaml
MyEtlJob:
  Type: AWS::Glue::Job
  Properties:
    Name: my-etl-job
    Role: arn:aws:iam::111122223333:role/MyGlueJobRole
    GlueVersion: "6.0"
    Command:
      Name: glueetl
      ScriptLocation: s3://amzn-s3-demo-bucket/scripts/my_etl_job.py
      PythonVersion: "3"
    DefaultArguments:
      "--scaling-profile": balanced
```

The following Terraform example creates the same job with the `aws_glue_job` resource.

```hcl
resource "aws_glue_job" "my_etl_job" {
  name         = "my-etl-job"
  role_arn     = "arn:aws:iam::111122223333:role/MyGlueJobRole"
  glue_version = "6.0"

  command {
    name            = "glueetl"
    script_location = "s3://amzn-s3-demo-bucket/scripts/my_etl_job.py"
    python_version  = "3"
  }

  default_arguments = {
    "--scaling-profile" = "balanced"
  }
}
```

## Error messages
<a name="scaling-profile-errors"></a>

The following table lists the error messages for the `--scaling-profile` parameter and the situations that cause them.


| Situation | Message | 
| --- | --- | 
| A value other than `balanced` or `disabled` | `Invalid value "<value>" for job argument --scaling-profile. The supported values are "balanced" and "disabled".` | 
| `--scaling-profile` on any other job type or AWS Glue version | `Job argument --scaling-profile is only supported for Glue ETL (glueetl) jobs on Glue 6.0 and later.` | 
| `--scaling-profile` in `CreateSession` | `Argument --scaling-profile is not supported for interactive sessions.` | 
| Only one of `WorkerType` or `NumberOfWorkers` on a streaming job, or on an AWS Glue version earlier than 6.0. On AWS Glue 6.0 and later ETL jobs, you can set just one value. | `Please set both Worker Type and Number of Workers.` | 

## Metrics and observability
<a name="scaling-profile-observability"></a>

You can monitor a run that uses the managed scaling profile with the same metrics, logs, and billing information as other AWS Glue jobs. For more information, see [Monitoring and billing for auto scaling](auto-scaling-observability.md).

## Frequently asked questions about the managed scaling profile
<a name="scaling-profile-faq"></a>

1. **What is the managed scaling profile?**

   The managed scaling profile is an AWS Glue managed configuration that automatically scales the number of workers for your job. You turn it on with `--scaling-profile balanced`. A run that uses the profile starts small, adds executors while tasks wait, and removes idle executors, up to the maximum number of workers that you set.

1. **Why does my new job use the managed scaling profile by default?**

   New Spark ETL jobs on AWS Glue 6.0 and later get `--scaling-profile balanced` in their default arguments when the request sets no conflicting values. For more information about the conditions that make a new job use the managed scaling profile, see [Jobs that get the managed scaling profile by default](#scaling-profile-default).

1. **How do I turn off the managed scaling profile?**

   Set `--scaling-profile disabled`. Removing the parameter doesn't turn the profile off, because AWS Glue keeps the saved value. For more information about turning the managed scaling profile on and off, see [Turning the managed scaling profile on and off](#scaling-profile-turning-on-off).

1. **How am I billed for a run that uses the managed scaling profile?**

   For pricing details, see the [AWS Glue pricing](https://aws.amazon.com/glue/pricing/) page.

1. **Why does Terraform show a pending change for `--scaling-profile`?**

   If your job got the profile by default, Terraform shows a pending removal of `--scaling-profile` on every plan until your configuration includes the parameter. Applying the plan changes nothing. To stop the pending change, add `--scaling-profile balanced` to your configuration.