How to evaluate the CPU and Mem usage for speccific command/docker in linux? How to evaluate the CPU and Mem usage for speccific command/docker in linux? docker docker

How to evaluate the CPU and Mem usage for speccific command/docker in linux?


You can view statistics for container(s) using the docker stats command.

For example;

docker stats containera containerbCONTAINER           CPU %               MEM USAGE / LIMIT     MEM %               NET I/O               BLOCK I/Ocontainera          0.00%               24.15 MB / 1.041 GB   2.32%               1.8 MB / 79.37 kB     0 B / 81.92 kBcontainerb          0.00%               24.95 MB / 1.041 GB   2.40%               1.798 MB / 80.72 kB   0 B / 81.92 kB

Or, see processes running in a container using docker top <container>

docker top containeraUID                 PID                 PPID                C                   STIME               TTY                 TIME                CMDroot                4558                2850                0                   21:13               ?                   00:00:00            sh -c npm install http-server -g && mkdir -p /public && echo "welcome to containera" > /public/index.html && http-server -a 0.0.0.0 -p 4200root                4647                4558                0                   21:13               ?                   00:00:00            node /usr/local/bin/http-server -a 0.0.0.0 -p 4200

Limiting resources

Docker compose (like docker itself) allows you to set limits on resources for a container, for example, limiting the maximum amount of memory used, cpu-shares, etc.

Read this section in the docker-compose yaml reference, and the docker run reference on "Runtime constraints on resources"


There are some good answers in the question: Peak memory usage of a linux/unix process

TL;DR: /usr/bin/time -v <command> or use valgrind.

That should help you get an idea for how much memory you need to assign as the limit for your app but CPU is a bit different beast. If your app is CPU bound then it will use all the CPU you give it no matter what limit you set. Also, in Kubernetes you assign cores (or millicores) to apps so it's not always terribly useful to know what % of the CPU was used on any particular machine as that won't readily translate to cores.

You should give your app as many CPU cores as you feel comfortable with and that allows your app to succeed in an acceptable amount of time. That will depend on cost and how many cores you have available in your cluster. It also depends a bit on the architecture of your app. For instance, if the application can't take advantage of multiple cores then there isn't much use in giving it more than 1.

In case you have any longer running apps, you could try installing Kubedash. If you have Heapster installed then Kubedash uses the built in metrics for Kubernetes to show you average and max CPU/Memory utilization. It helps a lot when trying to figure out what requests & limits to assign to a particular application.

Kubedash screenshot

Hope that helps!