2

I want to limit a user on my system to only be able to use one core of my system.

After searching, I found this, but I can't figure out how to use it.

I would also like to limit the use of that core to a specific percentage to prevent abuse.

squillman
  • 37,883
  • 12
  • 92
  • 146
Jacob Pedersen
  • 123
  • 1
  • 4

1 Answers1

5

The approach of limiting cores/cpu usage is most likely not what you want. Is it that you have a user who likes to run multicore/intensive tasks, and it ends up slowing down the whole server? The solution is to "nice" that user automatically.

In your /etc/security/limits.conf, you would want to add an entry for your abusive user (-19 to 19, with 19 being the lowest priority):

username    -       priority        19

Basically this means setting that user to run at a lower priority. If nobody else is running processes, then this user can consume the extra available CPU (idle CPU is wasted CPU). But if anything else is running, this user's processes will yield CPU. I've heard that servers are designed to run optimally at 100% cpu, and that you can't bank unused CPU cycles to use later.

Background: I have a Linux server that runs at 100% CPU 24x7 on all cores. It simultaneously runs computation intensive financial analysis software, a MySQL DB, a Tomcat instance, and Apache/PHP. The financial software will eat as much CPU and cores they can get, so I have them at priority 19. I want my Tomcat and Apache/PHP servers to be responsive, so I set them at -2 or -3. The web pages come up just as fast with or without the financial software running, thanks to properly managing priorities.

Joshua Huber
  • 817
  • 6
  • 7
  • Ah. This is probably a better approach for me :) Thanks! – Jacob Pedersen Jun 09 '14 at 16:42
  • shouldn't that be `nice 19`? – gdkrmr Nov 04 '19 at 19:56
  • @gdkrmr Logically it should be, though it's not implemented that way. See https://linux.die.net/man/5/limits.conf Maybe think of `nice` as the verb, and `priority` as the noun. If you have a process you want to demote, you `nice` its `priority`. This also shows up in the `renice` command, Example doing ```renice -n 10 406326``` returns feedback that looks like this: ```406326 (process ID) old priority 0, new priority 10``` – Joshua Huber Nov 05 '19 at 18:11