Dockerrun aws hardcoded memory
Asked Answered
D

1

9

In a Multi-container Docker environment in Elasticbeanstalk, defining the memory is mandatory in the Dockerrun.aws.json and I would like to know what are the best practices to to deal with the hardcoded values of the memory.

Especially when we need to adjust the instance type we need to adjust the memory values as well.

Is there a way to specify a sort of percentage instead of exact numbers ?? Maybe a suggestion for @aws

This is a Dockerrun.aws template example:

{
  "AWSEBDockerrunVersion": 2,
  "containerDefinitions": [
    {
      "name": "container-1",
      "image": "image-1.com/image-xxxxxx",
      "memory": 512
    },
    {
      "name": "container-2",
      "image": "image-2.com/image-xxxxxx",
      "memory": 256
    },
    {
      "name": "container-3",
      "image": "image-3.com/image-xxxxxx",
      "memory": 256
    }
  ]
}
Diarist answered 22/2, 2019 at 9:33 Comment(0)
H
7

I am not an AWS internal, but we used AWS Elastic Beanstalk as well as more advanced deployment strategies (e.g. custom CloudFormation templates) for our application. Here are a few notes from my personal experience as a DevOps engineer using these services:

  • It is best practice to define the memory in MiB inside the file Dockerrun.aws.json as explained by the docs. [1]
  • You do not need to define a memory hard-limit. A memory soft-limit is sufficient, as stated by the docs: "Specify a non-zero integer for one or both of the memory or memoryReservation parameters in container definitions." [1]
  • The memory or memoryReservation reservation must be provided to AWS Elastic Beanstalk because it is using AWS ECS as the underlying service which requires one of those values. It places containers on EC2 instances using the ECS agent and has to know how much space to reserve for each container.
  • The upscaling/downscaling issue described above (i.e. "adjust the instance type") should not be an issue unless your application is memory-bound, because you can always set a very low memoryReservation value for CPU-bound applications. See [2] for a great explanation of the differences between soft and hard memory limits. Also keep in mind: "The Docker daemon reserves a minimum of 4 MiB of memory for a container, so you should not specify fewer than 4 MiB of memory for your containers." [3]
  • If you want more flexibility/control, you can always move from AWS Elastic Beanstalk to an ECS deployment using Infrastructure as Code via AWS CloudFormation.
  • If you are interested in how things work under the hood in AWS ECS, please visit the following great blog post by AWS: How Amazon ECS manages CPU and memory resources. [4]

References

[1] https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_v2config.html
[2] https://mcmap.net/q/348500/-aws-ecs-task-memory-hard-and-soft-limits
[3] https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html
[4] https://aws.amazon.com/de/blogs/containers/how-amazon-ecs-manages-cpu-and-memory-resources/

Hereunto answered 22/3, 2020 at 21:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.