Fair shared hosting

Traditional shared hosting has always suffered from the “bad neighbor problem”: your site runs fine until another user on the machine decides to encode 20 video files and all of the sudden your site is very sluggish.

That problem is now history on our centos6 servers thanks to a relatively unknown feature recently added to the linux kernel: cgroups.

cgroups allow admins to define various groups and various rules for which processes should go into which groups. Each group can then be allocated various resources or resource priorities relative to other groups.

Here is how cgroups get rid of the traditional “bad neighbor problem” in shared hosting:


  • Imagine a CPU-intensive script called “cpu-eater”
  • Imagine that user A runs 3 instances of the script (process 1, 2 and 3) and users B and C each run one instance of that script (process 4 and 5)
  • Without cgroups each of these 5 processes gets allocated the same amount of CPU (20% each if all the CPU power is available) which means that user A gets 60% in total and user B and C get 20% each. User A is being a bad neighbor and that’s not fair to users B and C.
  • With cgroups we can configure it so that each user gets their own cgroup and all of a user’s processes go in that user’s cgroup. We then configure it so that all cgroups have the same CPU priority. This means that users A, B and C each get 33.3% of the CPU to run their “cpu-eater” scripts which is fair.

Note that cgroups keep all the CPU power available to processes who want it: if there are only two CPU-intensive processes on the machine they’ll get 50% CPU each. If there is only one CPU-intensive process on the machine it’ll get 100% CPU.

Also, this example mentions CPU usage but cgroups can do the same for disk IOs and network IOs.

We’ve been running cgroups on all of our Centos6 servers for a few months and we’ve seen great results! No longer can a single user affect all other users on the machine.

This entry was posted in Server setup. Bookmark the permalink.

3 Responses to Fair shared hosting

  1. Great news that finally convinced me it’s time to move from web142 (US) to one of the EU servers. I haven’t had many problems, but every now and then a bad neighbor has made my sites grind to a halt.

  2. Is this feature enabled on web306? Right now a user is compiling some java thing, and maxing out all four CPU cores, rendering the system’s SSH prompt not very responsive.

  3. remi says:

    Nicola: Yes it’s enabled on Web306. If you need CPU then the OS should give you as much CPU as the other users. I see a user compiling Java now but the prompt is still responsive. Are you sure the SSH prompt sluggishness you experienced wasn’t due to something else like network latency?

Leave a Reply

Your email address will not be published. Required fields are marked *