Cgroups with systemd simple

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen


Servicedateien bearbeiten

  • Lassen Sie uns die Unit-Datei selbst bearbeiten.
  • Die maximale CPU-Auslastung soll begrenzt werden
  • einmal 20% und einmal 40%

Unit Dateien

  • cat /etc/systemd/system/gen-load-20.service
[Unit]
Description=CPU usage limiting test

[Service]
Type=oneshot
ExecStart=/usr/local/bin/generate_load.sh
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
CPUQuota=20%

[Install]
WantedBy=default.target
  • cat /etc/systemd/system/gen-load-40.service
[Unit]
Description=CPU usage limiting test

[Service]
Type=oneshot
ExecStart=/usr/local/bin/generate_load.sh
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
CPUQuota=40%

[Install]
WantedBy=default.target

Das Skript

  • cat /usr/local/bin/generate_load.sh
#!/bin/bash
/usr/bin/cat /dev/urandom > /dev/null &
  • chmod +x /usr/local/bin/generate_load.sh

Starten der Dienste

  • systemctl start gen-load-20.service
  • systemctl start gen-load-40.service
  • systemd-cgtop

Status

  • systemd-cgtop
Control Group                      Tasks   %CPU   Memory  Input/s Output/s
/                                    108   66.6   816.5M        -        -
system.slice                          17   62.5    80.2M        -        -
system.slice/gen-load-40.service       1   41.9   300.0K        -        -
system.slice/gen-load-20.service       1   20.4   300.0K        -        -