Article sections

    source : https://www.geekytuts.net/fix-high-server-load-and-memory-cpu-consumption-of-clamd-clamav/

    I had troubles with one of Directadmin servers which was constantly loading because clamd process. When executing top command, clamd was always top on the list. As I researched, there is no way you can limit ClamAV’s memory and CPU consumption via its configuration itself. This is how you do it.

    What you have to do is limit clamd within startup script, so that clamd will start with some limitations.

    Just open ClamAV startup script. I this case CentOS 7:

    vi /etc/systemd/system/clamd.service

    Then add this lines. Of course change according to your needs.

    IOSchedulingPriority = 7
    CPUSchedulingPolicy = 5
    MemoryLimit=256M
    CPUQuota=30%
    Nice = 19

    Your startup script should now look something like this:

    [Unit]
    Description = Generic clamav scanner daemon
    After = syslog.target nss-lookup.target network.target
    
    [Service]
    Type = simple
    ExecStartPre=-/bin/mkdir -p /var/run/clamd
    ExecStartPre=-/bin/chown -R clamav:clamav /var/run/clamd
    ExecStart = /usr/local/sbin/clamd --foreground=yes
    Restart = on-failure
    PrivateTmp = true
    IOSchedulingPriority = 7
    CPUSchedulingPolicy = 5
    MemoryLimit=256M
    CPUQuota=30%
    Nice = 19
    
    [Install]
    WantedBy = multi-user.target
    in cPanel & WHM Server