6

We have an Ubuntu Server (16.04) running R-Studio Server where we do statistical simulations. Those simulations are sometimes heavy on RAM and CPU so i would like to know how memory and RAM is allocated by the core if e.g. two users are logged in and each of them runs an individual R session where they "compete" for memory and CPU.

Since none of us is a server administrator we do not really want to apply manual changes, however we are interested if RAM and CPU allocation is more less equal to all users.

Note: The R-Studio Server Pro version allows to allocate a given amount of memory to single users in a quite easy way but since we do not have the Pro version we cannot change those settings.

joaoal
  • 173

4 Answers4

5

RAM is first-come-first-serve. If userA runs 9 processes that allocate 10% of memory each, and then userB logs on, userB will see only 10% of memory left. In the event that memory is exhausted, Linux will start killing processes. The OOM killer is not tuned for multi-user, as far as I know, so it may be unfair in this scenario.

CPU time is generally allocated on a per-process basis, not per-user (but see below).

Any process which is ready to run (not sleeping, waiting on I/O, etc.) is considered for scheduling. (Processes which are not ready to run, are ignored, and so "don't count". (This is a slight oversimplification, but close enough.))

In the simplest model, if two users are running one process each, they each get roughly half of available CPU time. But if userA is running 10 processes, and userB is running 1 process, then userA gets 90% of CPU and userB gets 10% of CPU (all other things being equal).

However, the Linux scheduler can refine this by grouping processes together, and then allocating CPU time between those groupings.

Further, Linux has the capability to automatically group processes based on the session ID (typically associated with terminals, terminal windows, and/or X login sessions). This is called "autogrouping". The goal is that a single user running a heavy background task in one window, and an interactive task in another window, will still see responsive interactive performance.

Both of these capabilities are enabled by default on Ubuntu, as far as I can determine.

I cannot find information on how task groups and/or autogrouping behave in a multi-user workload. In theory, if the scheduler put each user in a separate task group, then users would always get balanced access to the CPU (50/50 for two users). However, I don't find anything that says this will happen automatically.

Further reading:

Ben Scott
  • 380
5

If you need to limit memory usage on the same server, your best bet will be to either

  1. Use two Virtual Machines, ideally KVM so that you can use the existing Ubuntu server to host the VMs. However, this will prevent you from easily sharing unused memory from one user with another.
  2. Use cgroups to limit resource usage
    2.1. https://askubuntu.com/questions/510913/how-to-set-a-memory-limit-for-a-specific-process 2.2 http://www.fernandoalmeida.net/blog/how-to-limit-cpu-and-memory-usage-with-cgroups-on-debian-ubuntu/
zymhan
  • 1,382
3

By default, users are unlimited memory-wise in Ubuntu, and in this case it's "first come, first serve". In other words, User A could use up all the memory and leave nothing for a second user.

Note though: If you configure limits, they will be always the same and not dependent on the number of current users, so you will restrict your users even if they are alone on the machine.

For the CPU, things are a bit better and the kernel scheduler will distribute CPU time between processes (not users!).

Sven
  • 100,763
-2

This will depend on what background processes are doing, what versions of the software are installed when you install Ubuntu, whether cron jobs are running, etc. The only real way to find out is to check RAM usage in all the scenarios you are interested in, no one will be able to tell you since even things like the number of processors and network cards will impact RAM usage.

You should be able to use control groups to limit the RAM usage, but I don't know if you need root permissions for that. Ideally you would create multiple virtual machines and allocate resources that way.

user
  • 1