r/linuxadmin • u/TheDevilKnownAsTaz • Oct 29 '25
Everyone kept crashing the lab server, so I wrote a tool to limit cpu/memory
Hey everyone,
I’m not a real sysadmin or anything. I’ve just always been the “computer guy” in my grad lab and at a couple jobs. We’ve got a few shared machines that everyone uses, and it’s a constant problem where someone runs a big job, eats all the RAM or CPU, and the whole thing crashes for everyone else.
I tried using systemdspawner with JupyterHub for a while, and it actually worked really well. Users had to sign out a set amount of resources and were limited by systemd. The problem was that people figured out they could just SSH into the server and bypass all the limits.
I looked into schedulers like SLURM, but that felt like overkill for what I needed. What I really wanted was basically systemdspawner, but for everything a user does on the system, not just Jupyter sessions.
So I ended up building something called fairshare. The idea was simple: the admin sets a default (like 1 CPU and 2 GB RAM per user), and users can check how many resources are available and request more. Systemd enforces the limits automatically so people can’t hog everything.
Not sure if this is something others would find useful, but it’s been great for me so far. Just figured I’d share in case anyone else is dealing with the same shared server headaches.
121
u/xtigermaskx Oct 29 '25 edited Oct 29 '25
This is neat. I manage clusters and use slurm if you ever want to try it's not too big an undertaking if you were able to build this.
Some folks over at /r/hpc may like this.
39
u/archontwo Oct 29 '25
Kudos..
Good to scratch your itch.
You could improve it significantly with cgroups as they have been in Linux for a long time now.
You might want to flex those budding sysadmin muscles.
Good luck.
11
u/not-your-typical-cs Oct 29 '25
This is incredibly solid!!! I built something similar but for GPU partitioning I'll take a look at your repo, star it so I can follow your progress Here's mine in case you're curious: https://github.com/Oabraham1/chronos
3
u/TheDevilKnownAsTaz Oct 29 '25
Edit: Claude was use a lot during this project’s development.
3
u/Odd_Cauliflower_8004 Oct 29 '25
Use lxc containers with limited resources and let them ssh into those instead.
13
u/CelDaemon Oct 29 '25
Aaaand it has a
CLAUDE.md... :/5
u/xagarth Oct 29 '25
curl internet | sudo bash
should be banned globally.
How's your thing better than CFS?
You wrote this or claude did?
325
u/H3rbert_K0rnfeld Oct 29 '25
Don't sell yourself short. Look up the history of Linux. It was just a thing a guy made for class. His post to newsgroups was just like yours.
Make your thing fun to use. Support it. Don't be jerky if some says Hey about this? You never know where the project will take you.
2
u/whenwillthisphdend Oct 29 '25
for interactiv and perpetual run jobs which is what i gathered from your comments, our lab treats them as shared workstation. I simply retrict concurrent users to two logins at any one time. And if they still manage to crash each other, then they can duke it out amongst themselves/have a conversation. Or move on to one of the other 8 workstations we have available. What ends up happening is regular users will tend to keep using the same workstation, and people start to remember who is on what station and organise themselves accordingly. Never had any issues with this method, and we have almost 20 people in our group! (we also have a cluster but that's another story)
2
u/wolfGhost23 Oct 31 '25
I join the contribution of several users in recommending that you use Containers, it would be worth looking at whether LXC or Docker. That way you can manage resources at a high level with cgroups
52
u/[deleted] Oct 29 '25
You may want to check out /etc/security/limits.conf :)
7
u/skillzz_24 Oct 29 '25
This is pretty cool I must say, but is it really fair to say you wrote it if the whole thing is vibe coded? Don't mean to slam on you, but it's a little misleading. Either way, dope project.
9
u/crackerjam Oct 29 '25
Personally I have no use for this, but it is a very neat project. Good job OP!
1
u/8fingerlouie Oct 29 '25
Why not simply use cgroups ?
I’ve been using FreeBSD on servers for so long that rctl was the first thing that popped into mind.
It’s quite simple, to limit “bob”, simply :
With cgroups you can achieve something similar, but in typical Linux fashion it’s not quite as polished :
As far as I know, there’s no “easy” userland tool for the job though.
1
u/BXBGAMER Oct 30 '25
Can this maybe used in pod/k8s context?
1
u/_link89_ Oct 31 '25
You may eventually find that managing a shared server or even a cluster involves not just resource fairness, but also job scheduling, hardware isolation, and software environment isolation. Utilizing specialized queue management software, such as Slurm or OpenPBS, or container-based solutions like k3s, will likely be a more sustainable approach.
1
u/Beautiful-Click-4715 Oct 31 '25
Mr no fun zone over here
1
u/officialigamer Nov 02 '25
Does it only have 12GB of RAM? Seens a bit low for a server
1
u/stu66er Nov 02 '25
Sorry if it’s a stupid question, but isn’t this what k8s is for?
2
u/01001000011001010 Oct 30 '25
r/commandline
2
u/throwpoo Oct 30 '25
As a slurm admin, this looks pretty good for smaller system! Definitely gonna give it a go.
2
u/aieidotch Oct 29 '25
you might want to look at zram, and nohang.
1
u/kobumaister Oct 29 '25
Nice job!
1
u/SnooChocolates7812 Oct 29 '25
Nice one 👍
1
u/rwu_rwu Oct 29 '25
Nice.
1
u/crazyjungle Oct 29 '25
Interesting, can come handy when different "me" are trying to overload the server at different time ;p
1
u/circularjourney Oct 29 '25
Did you try systemd-nspawn?
Add some resource limits to that and you're good to go.
1
u/ptrxyz Oct 30 '25
cgroups?
1
u/Significant-Till-306 Nov 01 '25
Open source it, make it a python pypi downloadable. What you have is a neat tool others will find useful. Not really a dev ops guys is literally every dev ops guy while doing dev ops things.
0
u/SaladOrPizza Oct 29 '25
Like the idea but CPU and memory are ment to be used.
0
u/Ctaehko Oct 31 '25
cool project but just tell the people in the lab to stop overusing the server and stop being a dick. also consider upgrades if resources are such a big deal
-9
u/stufforstuff Oct 29 '25
A server that only has 12G - why?
0
u/[deleted] Oct 29 '25
[deleted] — view deleted comment
1
u/[deleted] Oct 29 '25
[removed] — view removed comment