Might have found an easy way to limit CPU usage on my server

See this.

Probably going to get more block storage from BuyVM, and use it for Nextcloud. But want to limit the CPU, so they don’t have to throttle me or terminate me. I’ll test it by limiting this site’s user to 1%. Or maybe limit the RAM to 1MB or so. If the site gets an error, it worked.

I could pay Google, but the block storage isn’t that much.

Looks like I need to enable accounting. How do I do that? By editing /etc/systemd/system.conf. Sites still work though, do I need to reboot? Or set the limit to 0? Rebooting didn’t fix anything. 12M is enough RAM? It’s using over 300.

Does that only work for non daemons? WordPress still works, I’d think it uses over 1M of RAM. Setting to 0 does nothing. Should crash the server.

Looks like it doesn’t apply to system stuff. Only the SSH user.

Not easy, as it only works for logged in users. What’s the point in that on a server? The user for this site isn’t logging in by SSH. I think if it used systemd for the PHP processes, you could do it.

So make a shell script that gets all processes running by user and limit to 1% using cpulimit? Or better, do it the lazy way, and limit everything to 1%, the backups will take forever probably.

This might do it, sort of, set it to 5, so each process gets 5%. Kind of useless though. I want a 25% max limit for everything. That is, I never want the entire server using more then 25%. The instructions are for initd, not systemd.

But the actual script might work. There’s got to be a better way though. I’ll be over 25%, with ten processes using 5% each.

You probably only need a script that limits the one process using too much.

I made a service file for that script, it’s better then nothing. I did change the limit to 25% though. Who knows if I’ll put Nextcloud on it. Still need to limit the CPU, since it’s not dedicated. Bots hammering my site, will have a long ass wait now.

256 GB of block storage from BuyVM is $1.25 per month, less then 200 GB from Google. I’m already paying for the server. There’s 0 available though. So perhaps Google is a better idea.