How much memory and cpu nginx and nodejs in each container needs? How much memory and cpu nginx and nodejs in each container needs? nginx nginx

How much memory and cpu nginx and nodejs in each container needs?


I will never recommend a hard memory limit while running container in ECS.

Plus you can not determine memory for the idle state of the container so better to have look on some benchmark for Nginx while node memory vary from application to the application also poor code might consume more memory than good and managed application.

NGINX used one worker, 15% CPU and 1MB of memory to serve 11,500 requests per second.

Benchmarks have shown NGINX lightweight

Now based on your traffic EXPECTED_REQUST/11500 = Required memory

While the memory of Nodejs is really critical and totally depend on your code if the application does not close file or request properly it will hit the max memory sooner then expected, so go for memory reservation.

memoryReservation

The soft limit (in MiB) of memory to reserve for the container. When system memory is under contention, Docker attempts to keep the container memory to this soft limit; however, your container can consume more memory when needed

For example, if your container normally uses 128 MiB of memory, but occasionally bursts to 256 MiB of memory for short periods of time, you can set a memoryReservation of 128 MiB, and a memory hard limit of 300 MiB. This configuration would allow the container to only reserve 128 MiB of memory from the remaining resources on the container instance, but also allow the container to consume more memory resources when needed.

ECS memoryReservation

So better to do not set hard limit that is called memory.

The amount (in MiB) of memory to present to the container. If your container attempts to exceed the memory specified here, the container is killed. The total amount of memory reserved for all containers within a task must be lower than the task memory value, if one is specified.


The easiest way to determine this, is empirically, using docker stats -because the utilized resources vary proportionally to the requests per seconds your app will receive.

At idle expect ~10MB of memory for both containers and ~0 CPU usage :)

CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS4be92e1cd6bf        elastic_germain     0.00%               6.68MiB / 15.65GiB    0.04%               5.68kB / 0B         0B / 0B             117c5552053782        modest_black        0.00%               4.543MiB / 15.65GiB   0.03%               6.37kB / 0B         0B / 8.19kB         2

You should not exceed 128MB for the nginx, unless you plan to enable content caching.
As for the node container, 512MB should be more than enough.

These values are relative to the real traffic the app shall receive: trying to forecast these the numbers ahead of time is just an educated guess if the expected traffic is unknown or vaguely guessed.

The good news is that the maximum theoretical limit is just as much as your host’s kernel scheduler allows. A stateless app can go beyond that point, using horizontal scaling, across multiple docker nodes.