Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerrun aws hardcoded memory

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
    }
  ]
}
like image 858
user11100640 Avatar asked Feb 22 '19 09:02

user11100640


1 Answers

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://stackoverflow.com/a/44764770/10473469
[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/

like image 78
Martin Löper Avatar answered Sep 22 '22 11:09

Martin Löper