VPS have limited CPU and RAM usage. This is why it is hard to mine on VPS not being blocked for high consumption. I try to mine on Xeon Skylake 1 Core 2 Gb Ram.
1. Optimize Xmrig config.json
Get config.json from Xmrig wizard [1]. After first run xmrig will add many lines to your config. And you need to look at the next lines.
Under randomx object: "mode": "light" - this makes xmrig uses 256 Mb of Ram.
Under randomx object: "1gb-pages": false - this is by default, use 2mb huge pages.
Under cpu object: "rx": [0] - this means use only one thread for RandomX algorythm.
Read Xmrig docs [2] for better understanding.
2. Limit cpu usage
There are some linux packeges like cpu-tool, cpulimit described on [3]. But if your VPS has systemd it is more reliable to give this work to systemd [4]. I do not promote systemd, but currently I use Centos 7 on VPS.
I wrote my systemd slice file:
$ cat /etc/systemd/system/xmrig.slice
[Slice]
CPUQuota=30%
MemoryMax=1G # Limit service to 1 gigabyte
Xmrig run looks like this:
systemd-run --slice=xmrig.slice /root/xmrig
Checking top xmrig uses only 30% of cpu.
Xmrig on VPS 30% cpu usage
Sources
1. Xmrig wizard https://xmrig.com/wizard
2. Xmrig docs config.json https://xmrig.com/docs/miner/config/cpu
3. Linux tools for limiting cpu: https://linoxide.com/limit-cpu-usage-processes-linux/
4. Systemd cgroups for limiting cpu: https://wiki.archlinux.org/title/Cgroups