Skip to content

Memory size doesn't match resource requirements for AWS Batch on Fargate

1

Hi,

I have a job definition for a Linux job running on Fargate where I specify resource requirements of 2 vCPUs and 16384 memory in container properties. However, when I run the job it reports that the available memory is 32 GB. I don't think it's specific to AWS Batch because I replicated the issue by manually starting ECS task from the task definition created by the AWS Batch and execed into the running task. The free -m command shows 32 GB of available memory as well.

It causes problems for my case because I'm trying to run a DuckDB processing inside the container and by default DuckDB uses 80 % of available memory as a memory limit. Often the Batch job is killed with OutOfMemoryError: Container killed due to memory usage reason.

I believe this is a bug.

asked 2 years ago608 views

1 Answer
-1

Thank you for bringing this issue to our attention. However, this is not a bug, but rather a result of how AWS Fargate allocates resources for containers.

When you specify memory requirements for an AWS Batch job running on Fargate, you're actually setting a minimum memory allocation. Fargate then rounds up this allocation to the nearest supported configuration. In your case, specifying 16384 MB (16 GB) of memory results in Fargate provisioning a task with 32 GB of memory, which is the next available tier.

This behavior is by design and ensures that your container has at least the amount of memory you requested, if not more. However, it can lead to unexpected results when applications like DuckDB automatically scale their resource usage based on available system memory.

To address your specific issue with DuckDB, you have a few options:

  1. Adjust your resource requirements: You could lower your memory request to 15 GB, which would result in Fargate allocating 16 GB instead of 32 GB.

  2. Configure DuckDB: Instead of relying on DuckDB's default behavior of using 80% of available memory, you can explicitly set DuckDB's memory limit to match your intended usage (e.g., 13 GB if you originally wanted 16 GB).

  3. Use container-level memory limits: You can set a memory limit for your container that matches your intended usage, preventing DuckDB from seeing the full 32 GB allocated by Fargate.

Remember, when using Fargate, both memory and vCPU requirements must be specified using supported values in the resourceRequirements section of your job definition. For example:

"resourceRequirements": [ {"type": "MEMORY", "value": "16384"}, {"type": "VCPU", "value": "2"} ]

This approach ensures that you're explicitly defining your resource needs within the constraints of Fargate's supported configurations.
Sources
Job definitions on Fargate - AWS Batch
ContainerProperties - AWS Batch

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.