Notes on reducing idle CPU usage for a Linux server. My server had several processes taking up low rates, but constant, CPU usage while not doing much of anything. I'm listing my tuning notes I used for a (very slight*) reduction in energy usage and heat.
On Ubuntu/Debian, the default setting of a sqlite backend results in mta-sts-daemon consistently using 1% of the CPU at idle. This is due to a "bug" reported/patched here. Switching to the internal backend dramaticaly cuts CPU usage.
/etc/mta-sts-daemon.yml:
cache: type: internal
This application is written in Java, and uses a MongoDB database. Both of
which could using some tuning.
One of the java threads is constantly spinning. Turns out this one is
getting performance data, and can be called less frequently with
PerfDataSamplingInterval. For Ubuntu/Debian, add the following to
/etc/default/unifi:
UNIFI_JVM_OPTS="-Xmx1024M -XX:+UseParallelGC -XX:PerfDataSamplingInterval=500"MongoDB has multiple threads doing quite a bit when nothing is really going on. One is collecting diagnostic data, which isn't used. This can be disabled by adding the following to /var/lib/unifi/system.properties:
unifi.db.extraargs=--setParameter diagnosticDataCollectionEnabled=falseAlso, I don't need to commit the journal so frequently, which I slow down with the following command line (I was unable to add it to system.properties):
echo 'db.adminCommand( { setParameter: 1, journalCommitInterval: 500 } )' | mongo localhost:27117These settings cut a bit more than half of the unifi idle CPU usage. Even with these fixes, this package remains the biggest CPU suck on my system.
I was using mrtg connecting to snmpd to get network interface usage. Turns out snmpd is collecting all kinds of other data at a fairly high frequency, which I wasn't using. A less intensive way is to use mrtg's add-on scripts to get that data.
Target[localhost_eth0]: `/usr/bin/mrtg-ip-acct eth0`
This and some other services are used infrequently, and I would like systemd to automatically start it when requested, then shut it down later. To accomplish that I wrote socketstarter.
* Combined, these only save a few dollars per year in electricity costs, but every little bit helps.
Updated 2023-03-12