VM CPU usage at 100% - docker

CPU usage on our metrics box is at 100% intermittently causing:
'Internal server error' when rendering Grafana dashboards
The only application running on our machine is Docker with 3 subcontainers
cadvisor
graphite
grafana
Machine spec
OS Version Ubuntu 16.04 LTS
Release 16.04 (xenial)
Kernel Version 4.4.0-103-generic
Docker Version 17.09.0-ce
CPU 4 cores
Memory 4096 MB
Memory reservation is unlimited
Network adapter mgnt
Storage
Driver overlay2
Backing Filesystem extfs
Supports d_type true
Native Overlay Diff true
Memory swap limit is 2.00GB
Here is a snippet from cAdvisor:
The kworker and ksoftirqd processes change status constently from 'D' to 'R' to 'S'
Are the machine specs correct for this setup?
How can I get the CPU usage to 'normal' levels?

By default, a Docker container (just like any process on host) has access to all memory and cpu resources of the machine.
Docker provides options to limit the container resource consumption. You check the following doc dedicated to Limiting a container's resources.

Related

Initiate multiple replicas of each container on one VPS with multiple cores when using Docker Swarm?

I have a VPS running Ubuntu 20.04 with 8 CPU cores. I'm planning to use Docker in Swarm mode to serve the frontend (Vue), backend (Django) and database (PostgreSQL) through a docker-compose.yml file.
When I execute docker swarm init, Docker starts 3 containers (frontend, backend and database).
Will a single replica of each container utilize all 8 CPU cores? Or should I initiate more replicas to utilize all 8 CPU cores of my VPS?
By default, if you do not change any of the default settings or set any limits inside the compose files (resource constraints more on this - https://docs.docker.com/config/containers/resource_constraints/ or compose https://docs.docker.com/compose/compose-file/compose-file-v3/#resources), container has unlimited CPU limit and unlimited MEM limit. So one replica of each service will have ALL of the memory available if the application has means to use it.
You would probably still want to look into more replicas for options on rolling updates (updates of the SW with limited or close to zero downtime).

How to increase disk space and memory limits for docker using console?

I easily managed to do this on the desktop version of Docker via preferences, but how can I do this using console on a remote linux server?
The limits you are configuring in the Docker Desktop UI are on the embedded Linux VM. All containers run within that VM, giving you an upper limit on the sum of all containers. To replicate this on a remote Linux server, you would set the physical hardware or VM constraints to match your limit.
For individual containers, you can specify the following:
--cpus to set the CPU shares allocated to the cgroup. This can be something like 2.5 to allocate up to 2.5 CPU threads to the container. Containers attempting to use more CPU will be throttled.
--memory or -m to set the memory limit in bytes. This is applied to the cgroup the container runs within. Containers attempting to exceed this limit will be killed.
Disk space for containers and images is controlled by the disk space available to /var/lib/docker for the default overlay2 graph driver. You can limit this by placing the directory under a different drive/partition with limited space. For volume mounts, disk space is limited by where the volume mount is sourced, and the default named volumes go back to /var/lib/docker.

Couchbase with docker: maximum allowed quota for the node is 368MB error although docker has 3GB of ram

For education I try to run a couchbase from docker on a t3a.nano aws instance (512MB).
https://docs.couchbase.com/server/5.1/install/getting-started-docker.html
Just at the beginning, at Couchbase > New Cluster > Configure I get
insufficient memory to satisfy memory quota for the services (requested quota is 1024MB, maximum allowed quota for the node is 368MB)
I added 2GB of swap to host aws vm. And tried running docker container with
-m 2048m --memory-swap 3000m
but it doesn't help.
Whre is the problem? Docker vm has memory set on cmd. How can I deceive docker or couchbase about available memory ?
(I don't mind swapping, I just wanna play with it).
[ec2-user#ip-10-0-0-11 ~]$ free -h
total used free shared buff/cache available
Mem: 461M 322M 15M 156K 122M 127M
Swap: 2,0G 87M 1,9G
You have to increase the VM RAM. Per default it's 1Go.
To do this, go to the VirtualBox interface, stop the VM and modify RAM.

Bandwidth and Disk space for Docker container

Does docker container get the same band-width as the host container? Or do we need to configure min and(or) max. I 've noticed that we need to override default RAM(which is 2 GB) and Swap space configuration if we need to run CPU intensive jobs.
Also do we need to configure the disk-space ? Or does it by default get as much space as the actual hard disk.
Memory and CPU are controlled using cgroups by docker. If you do not configure these, they are unrestricted and can use all of the memory and CPU on the docker host. If you run in a VM, which includes all Docker for Desktop installs, then you will be limited to that VM's resources.
Disk space is usually limited to the disk space available in /var/lib/docker. For that reason, many make this a different mount. If you use devicemapper for docker's graph driver (this has been largely deprecated), created preallocated blocks of disk space, and you can control that block size. You can restrict containers by running them with read-only root filesystems, and mounting volumes into the container that have a limited disk space. I've seen this done with loopback device mounts, but it requires some configuration outside of docker to setup the loopback device. With a VM, you will again be limited by the disk space allocated to that VM.
Network bandwidth is by default unlimited. I have seen an interesting project called docker-tc which monitors containers for their labels and updates bandwidth settings for a container using tc (traffic control).
Does docker container get the same band-width as the host container?
Yes. There is no limit imposed on network utilization. You could maybe impose limits using a bridge network.
Also do we need to configure the disk-space ? Or does it by default get as much space as the actual hard disk.
It depends on which storage driver you're using because each has its own options. For example, devicemapper uses 10G by default but can be configured to use more. The recommended driver now is overlay2. To configure start docker with overlay2.size.
This depends some on what your host system is and how old it is.
In all cases network bandwidth isn't explicitly limited or allocated between the host and containers; a container can do as much network I/O as it wants up to the host's limitations.
On current native Linux there isn't a desktop application and docker info will say something like Storage driver: overlay2 (overlay and aufs are good here too). There are no special limitations on memory, CPU, or disk usage; in all cases a container can use up to the full physical host resources, unless limited with a docker run option.
On older native Linux there isn't a desktop application and docker info says Storage driver: devicemapper. (Consider upgrading your host!) All containers and images are stored in a separate filesystem and the size of that is limited (it is included in the docker info output); named volumes and host bind mounts live outside this space. Again, memory and CPU are not intrinsically limited.
Docker Toolbox and Docker for Mac both use virtual machines to provide a Linux kernel to non-Linux hosts. If you see a "memory" slider you are probably using a solution like this. Disk use for containers, images, and named volumes is limited to the VM capacity, along with memory and CPU. Host bind mounts generally get passed through to the host system.

Docker cpu shares and garant minimum allocated CPU for container

I develop a application which runs in three containers on my development box with a quadcore with hyperthreading, meaning there are 8 cores to be used by the system and docker.
Thy CPU allocation for the containers is done by docker-compose as follows:
redis: cpu_shares: 1024
mysql: cpu_shares: 1024
app: cpu_shares: 4096
I am troubled by timing out requests to redis. The load is minimal, but the utilization of redis is in bursts with longer breaks, at least in the development environment.
Hence, I assume docker is not assigning enough CPU shares to the redis container. I thought allready to put a constant artificial load on redis to let docker assign more CPU shares to it.
Is there an other way of ensuring a certain CPU share for a container?
With Docker for Mac your containers are all running in a HyperKit VM. The VM has an allocation of CPU and memory which is a subset of the total on your Mac.
You can change the allocation in Preferences - by default the Docker VM has 2 CPUs and 2GB RAM.

Resources