Plesk

High CPU usage for “sa-learn” and “spamtrain” processes in a server with Plesk

Symptoms

High CPU usage for sa-learn and spamtrain processes in the Plesk server.

Cause

Since the sa-learn script is used by spamassassin to learn the specific properties of spam from a folder that supposedly contains only spam emails.
CPU usage of the sa-learn process depends on the number of emails in mailboxes and their size. In turn, if the number of emails is huge - CPU over usage is expected.

Resolution

To work around the issue, use one of the following solutions:

Create a wrapper script that will launch sa-learn with low priority:

  1. Connect to the server using SSH.

  2. Use nice or ionice utilities to decrease the priority of sa-update from the cron tasks.

  3. Create a wrapper file which will execute sa-learn with the lowest CPU priority:

    # cp -a /usr/bin/sa-learn{,.orig}
    # echo "/bin/nice 19 /usr/bin/perl -T -w /usr/bin/sa-learn.orig $@" > /usr/bin/sa-learn
    # chmod +x /usr/bin/sa-learn

    Note: In Debian based OS the correct path is /usr/bin/nice

Lower the priority of the currently running processes:

Set the lowest priority to the currently running sa-learn processes execute the following:

# ps auxwf | grep -v grep | grep sa-learn | awk {'print $2'} | xargs -i renice 19 {}

Note: Process priority values range from -20 to 19. A process with the nice value of -20 is considered to be on top of the priority. And a process with nice value of 19 is considered to be low on the priority list.

Disable the sa-update functionality:

Disable the sa-update execution by moving 60sa-update and spamassassin files from /etc/cron.daily to a different location:

# mv /etc/cron.daily/60sa-update /root

Exit mobile version