Open jimdigriz opened 6 years ago
For my personal use, I have constructed a horrifying workaround that halts the Docker service and brings down its network interfaces when no containers are running. It likely breaks things, but I'll take that over sacrificing a good percentage of my laptop's battery life. Put this in the system crontab to run every minute:
pgrep -af '/docker($| )' || \
(docker ps -q | grep . || \
(systemctl stop docker && \
ip -brief link show | \
awk '{ print $1 }' | \
grep -E '^(docker0|br-[0-9a-f]{12})$' | \
xargs -INAME ip link set dev NAME down \
) \
)
I have a docker
script on my PATH that takes care of re-starting the service automatically when it's needed, as well as re-running with sudo
unless on macOS:
#!/usr/bin/env bash
export PATH="${PATH/$(dirname "$0"):/}"
if [[ "$OSTYPE" != darwin* ]] && [[ "$EUID" != 0 ]]; then
if command -v systemctl >/dev/null; then
sudo systemctl start docker
fi
sudo docker "$@"
else
docker "$@"
fi
Improvements welcome.
Expected behavior
When docker has nothing to do, argubly even when it does as it should be only the applications in the containers eating CPU time, it should let the CPU drop into low power sleep mode. It currently wakes the machine at least 80 times a second preventing this so it toasts battery life.
Over five years ago the Linux world went tickless and it highlighted a lot of software was found to really be awful for power saving as they utilised idle polling loops typically 10->200hz. Over time, and a pile of bug reports later, the world seemed to rediscover event driven software design :)
Docker missed the memo.
Actual behavior
dockerd
has a 50hz idle poll loop,docker-containerd
has a 30hz idle poll loop.For comparison, Firefox is 4hz, Chrome is 3hz, and XOrg is 10hz.
Steps to reproduce the behavior
Run
powertop
, notice that when there are no containers, you are not even using docker, it is waking your laptop up to do seemingly nothing at 50hz (ondockerd
) and 30hz (ondocker-containerd
).Run
strace
showsselect()
(probably in your main idle loop) with timeouts set totv_nsec=20000
, that always return justETIMEOUT
.Output of
dpkg -s docker-ce
:Output of
docker version
:Output of
docker info
: