I used docker-compose to run a service but it crashed, I entered the container and got resource info by 'top' as below.
top - 13:43:25 up 1 day, 6:46, 0 users, load average: 1.82, 0.74, 0.52
Tasks: 3 total, 1 running, 2 sleeping, 0 stopped, 0 zombie
%Cpu(s): 32.2 us, 22.4 sy, 0.0 ni, 40.1 id, 3.0 wa, 0.0 hi, 2.3 si, 0.0 st
KiB Mem: 2047040 total, 1976928 used, 70112 free, 172 buffers
KiB Swap: 1048572 total, 1048572 used, 0 free. 14588 cached Mem
So I think my docker is out of memory.
I've tried add
mem_limit: 5g
memswap_limit: 5g
mem_reservation: 5g
into docker-compose.yml
But it seems not work. My question is, how to enlarge docker's memory limit by docker-compose.
The docker engine has a compatiblity mode which aims to make transition from compose v2 files to v3 easier. As a result of that, it is possible to partially use the swarm config (deploy) to specifiy resource limits for standard docker-compose usage:
To run in compatiblity mode just add the --compatiblity flag like this:
docker-compose --compatibility up myservice
and you can use a compose file like this:
version: '3.5'
services:
myservice:
image: postgres:12-alpine
deploy:
resources:
limits:
cpus: '0.50'
memory: 50M
If this is on a machine running Docker Desktop, then you would have to open the Docker Desktop preferences and go to Resources section to tweak how much of your host resources the Docker Engine can use.
As stated in the documentation the following fields can be used in docker-compose to control memory and cpu resources.
deploy:
resources:
limits:
cpus: '0.001'
memory: 50M
reservations:
cpus: '0.0001'
memory: 20M
Note however, by default there are no limits for the container memory usage, so setting the memory flags will unlikely help.
Related
Upon first launch and after a period of inactivity, our custom-speech-to-text docker container takes a long time to reply (10+ seconds vs sub 1 second response times for subsequent invocations).
Here is the docker-compose lines used to run the container:
msasr:
image: mcr.microsoft.com/azure-cognitive-services/speechservices/custom-speech-to-text:2.6.0-amd64
volumes:
- ./MS_ASR_20201202:/usr/local/models
restart: always
deploy:
resources:
limits:
cpus: '4'
memory: 4G
reservations:
cpus: '4'
memory: 4G
command: Eula=accept Billing=${MS_ENDPOINT_URI} ApiKey=${MS_API_KEY}
docker-compose is run with the --compatibility flag to for the memory allocations
This problem appeared after moving to the custom-speech-to-text:2.6.0-amd64 from the cognitive-services-custom-speech-to-text:2.2.0-amd64-preview
I suppose (no proof here) that there are some elements that need to be loaded into ram and are discarded when no in use, but this has a large QOS impact later on. Is there a way to tell the instance to keep them loaded, or re-prime the system?
This symptom suggests page-outs are occurring. In the past, the following actions have very effectively solved this:
Use 8G to ensure that all locales have the resources they need without any risk of requiring swap space.
Disable swap on the host entirely if permissible.
Ensure that there are not other processes that could lead to physical memory oversubscription. In other words, ensure the sum of reservations does not exceed the physical host.
Please let me know how this goes.
Andrew
I am using db2 on docker with a self non-root installation.
Even if I set the INSTANCE_MEMORY to the minimum, it seems to reserve 4G of RAM on the server.
How can DB2 be aware of the limits setted in the docker-compose file as I run the database in a docker swarm cluster as a STACK?
The DB2 version is 11.1.4FP4.
docker --version
Docker version 18.03.1-ce, build 9ee9f40
When I look at the docker stats, it uses only about 80MiB.
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
8282c5d0c9e7 db2wse_db2.1.waalf6vljuapnxlvzhf2cb0uv 0.21% 76.83MiB / 1GiB 7.50% 0B / 0B 408MB / 6.86GB 56
My docker-compose.yml file
version: "3.3"
services:
db2:
image: docker-registry.ju.globaz.ch:5000/db2wse:11.1.4fp4
networks:
- network-db
deploy:
mode: replicated
replicas: 1
resources:
limits:
memory: 1G
networks:
network-db:
external: true
Any idea ? It is very frustrating.
Thanks a lot
I found the problem.
It was a kernel configuration in the sysctl.conf.
I had this :
cat /etc/sysctl.conf |grep vm.
vm.swappiness=10
vm.overcommit_memory=2
vm.dirty_ratio=2
vm.dirty_background_ratio=1
I removed everything setted for DB2 (put back the default configuration) and now I can take advantage of all the RAM of the hosts.
I kept this :
cat /etc/sysctl.conf |grep vm.
vm.swappiness=10
vm.max_map_count=262144
Thanks
I am running my application as a docker container in both Docker Swarm UCP (using compose.yml file) as well as in Mesos (using marathon.json file).
I have added the resource constraints in both the files.
compose.yml:
resources:
limits:
cpus: '0.50'
memory: 50M
reservations:
cpus: '0.25'
memory: 20M
marathon.json:
"cpus": 0.50,
"mem": 128.0,
"disk": 5.0
What I found out is memory is the hard limit and cpu is the soft limit. i.e. cpu limit is only for weight and priority. If mesos cpu is 1 and if two applications are running one with 0.4 cpu and the other with 0.6 cpu then app one will get 40% of the cpu cycles and app two will get 60% of the cpu cycles.
Then what is the use of limit and reservation in compose.yml file here?
Now I am trying to understand below things
How does this resource constraints work exactly?
What happens when the container exceeds these values?
reservations means that the container won't start on a node of that node doesn't have enough free resources to respect this constraint.
limits means that when a process in the container reaches that limit and tries to allocate more it will be forcefully killed.
I would like to set limitation of cpu resource, and found this docker-compose setting file below.
version: '3'
services:
redis:
image: redis:alpine
deploy:
resources:
limits:
cpus: '0.001'
memory: 50M
reservations:
cpus: '0.0001'
memory: 20M
BUT I don't know what 0.001 mean in here. It will use 0.1% of total cpu capacity? and some document said it can be set more than 1. what happen If i set more than 1?
and What is default value of resource.limits.cpus and resource.limits.cpus.memory?
By default a container has limitless access to the host's cpu. Limits allow you to configure resources that are available to a container.
A cpus value of 0.001 will mean for each one second, a 1 millisecond will be available to the container.
A value greater than 1 will make sense when you think of hosts with multi-cpus. A value of 2 for instance will mean the container will be given access for at most 2 cpus.
The limits are the maximum docker will use for the container. The reservations are how much it will set aside for the container i.e. prevent other containers from using.
CPU is measured in percentage of a second on a single CPU. So the example you have will limit you to 0.1% of a CPU (1ms/s), which might be useful for some I/O bound tasks. '1.0' would allow one CPU to be used entirely, and higher values would allow multiple CPUs to be allocated (or reserved) to the container.
This answer has some graphs showing the effects.
mem_limit is supported by docker-compose? How can I test it?
I have a following docker-compose.yml
repository:
image: myregistry/my_nginx_image
mem_limit: 60m
volumes:
- /etc/localtime:/etc/localtime
ports:
- "80:80"
How can I prove that the container actually does not exceed 60 mb of RAM?
I am using:
docker 1.3.1
docker-compose 1.1.0
Yes. Memory limitation is supported by docker-compose and value can be set as in your example with "m" for megabytes.
It is possible to check what is the memory limit set for running Docker container using "docker stats" command.
If your container name is "repository_1" then use this command:
docker stats repository_1
The result of this will be simillar to this one:
CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O
repository_1 1.93% 4.609 MiB/60 MiB 7.20% 1.832 KiB/648 B
According to documentation, simple
mem_limit: 1000000000
should be enough. I guess, you should drop "m", and use bytes instead of megabytes.
If you use docker compose v3 instead of:
mem_limit: 60m
you need to specify memory limit in deploy section:
deploy:
resources:
limits:
memory: 60m
This change is described here: https://docs.docker.com/compose/compose-file/compose-versioning/#version-2x-to-3x
You can find how configure docker to limit resources (CPU & MEMORY) and how test your restrictions in this post written last year: resource-management-in-docker.