An Introduction to Resource Management on Ubuntu Server

I recently wanted to limit CPU usage on my Ubuntu Karmic workstation. Since libcgroup is included in the upcoming Karmic release, setting up cgroups on an Ubuntu server has never been easier.

The Goal

My needs were as follows:

  • My machine is dedicated to running an Apache Web Server and I would like for it to have priority on the CPU whenever it’s needed.
  • I have an occasional user on my system that chews up CPU like it’s going out of style and slows down my web server. In this example, we’ll call this user kirkland.

The goal is to only allow kirkland CPU cycles when no other process is requesting them. Similar to a sponge, kirkland will be throttled to 0 if my apache daemon is really busy.

Getting There

  1. Install libcgroup:
    $ sudo aptitude install libcgroup cgroup-bin
  2. Edit /etc/cgconfig.conf, define a sponge group:
    group sponge {
     perm {
         task {
             uid = kirkland;
             gid = kirkland;
         }
         admin {
             uid = root;
             gid = root;
         }
     }
     cpu {
         cpu.shares = 1;
     }
    }
    mount {
     cpu = /mnt/cgroups/cpu;
     cpuacct = /mnt/cgroups/cpuacct;
    }
  3. Edit /etc/cgrules.conf, assign kirkland to the sponge group:
    kirkland         cpu             sponge/
    * * sysdefault/
  4. Restart cgconfig and cgred services:
    $ sudo service cgconfig restart
    $ sudo service cgred restart
    Processes created by kirkland should now automatically get moved into the sponge cgroup and will only recieve CPU cycles when no other processes are in need.

For more information about libgroup, you can visit the libcgroup project page. And for cgroups in general see the current kernel documentation.

blog comments powered by Disqus