免責聲明

Disclaimer (免責聲明)
繼續閱覽代表您接受以上的免責聲明.
To continue reading means you accept the above disclaimer.

2015年3月4日 星期三

docker resource management, memory limit

//===
https://docs.docker.com/reference/commandline/cli/#run
https://docs.docker.com/reference/run/#runtime-constraints-on-cpu-and-memory

-c === --cpu-shares [cpu weighting]
--cpu [number of cpu cores]
--cpuset [set of cpu cores]

-m [memory limit]

-memory-swap=""
[Total memory usage (memory + swap), set '-1' to disable swap ]

$ docker run -it --rm -m 128m -c 512 image_name

$ docker top container_name
$ docker


//=== https://goldmann.pl/blog/2014/09/11/resource-management-in-docker/#_example_managing_the_cpu_shares_of_a_container

?? --vm , --vm-bytes, --vm-hang

"""...
Every new container will have 1024 shares of CPU by default. This value does not mean anything, when speaking of it alone. But if we start two containers and both will use 100% CPU, the CPU time will be divided equally between the two containers because they both have the same CPU shares (for the sake of simplicity I assume that there are no other processes running).

If we set one container’s CPU shares to 512 it will receive half of the CPU time compared to the other container. But this does not mean that it can use only half of the CPU. If the other container (with 1024 shares) is idle — our container will be allowed to use 100% of the CPU. That’s another thing to note.


...
To allow execution only on the first core:

docker run -it --rm --cpuset=0 stress --cpu 1

To allow execution only on the first two cores:

docker run -it --rm --cpuset=0,1 stress --cpu 2


...
$ docker run -it --rm -m 128m stress --vm 1 --vm-bytes 128M --vm-hang 0
stress: info: [1] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd
The stress tool will create one process and try to allocate 128MB of memory to it.
It works fine, good. But what happens if we try to use more than we have actually allocated for the container?

$ docker run -it --rm -m 128m stress --vm 1 --vm-bytes 200M --vm-hang 0
stress: info: [1] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd
It works too. Surprising? ...

... by default the memory.memsw.limit_in_bytes value is set to twice as much as the memory parameter we specify...
... What does the memory.memsw.limit_in_bytes parameter say? It is a sum of memory and swap.
This means that Docker will assign to the container -m amount of memory as well as -m amount of swap.

...
With the above information we can run our example again.
This time we will try to allocate over twice the amount of memory we assign.
This should use all of the memory and all of the swap, then die.

$ docker run -it --rm -m 128m stress --vm 1 --vm-bytes 260M --vm-hang 0
stress: info: [1] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd

stress: FAIL: [1] (415) <-- worker 6 got signal 9 stress: WARN: [1] (417) now reaping child worker processes ...


..."""

沒有留言:

張貼留言