Skip to content

Instantly share code, notes, and snippets.

@rayjanoka
Last active August 24, 2021 02:38
Show Gist options
  • Save rayjanoka/91d7ef29067d1fc291a11e1aa3805498 to your computer and use it in GitHub Desktop.
Save rayjanoka/91d7ef29067d1fc291a11e1aa3805498 to your computer and use it in GitHub Desktop.
Script and systemd service to apply I/O highest priority and best effort scheduling class to the etcd process
cat <<'EOT' >/usr/local/bin/ionice-etcd.sh
#!/usr/bin/env bash
echo "Starting ionice etcd process watcher..."
while true; do
PID=$(pgrep etcd)
if [ "$PID" != "" ]; then
if [ "$(ionice -p $PID)" != "best-effort: prio 0" ]; then
echo "Setting I/O highest priority and best effort scheduling class for etcd PID: $PID"
ionice -c2 -n0 -p $PID
fi
fi
sleep 60
done
EOT
chmod 0755 /usr/local/bin/ionice-etcd.sh
cat <<EOT >/etc/systemd/system/ionice-etcd.service
[Unit]
Description=ionice for etcd
After=kubelet.service
[Service]
DevicePolicy=closed
ExecStart=/usr/local/bin/ionice-etcd.sh
PrivateTmp=yes
ProtectSystem=strict
Restart=on-failure
TimeoutStartSec=10
[Install]
WantedBy=multi-user.target
EOT
systemctl daemon-reload
systemctl enable ionice-etcd
systemctl start ionice-etcd
@rayjanoka
Copy link
Author

rayjanoka commented Aug 23, 2021

Written for Ubuntu

This I/O disk tuning is detailed in the etcd docs: https://etcd.io/docs/v3.2/tuning/#disk

This service will watch the etcd process in case it is restarted and re-apply the tuning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment