cgroups – use to control your cpu and memory

cgroups is a kernel feature and with userspace utilities, we can use the feature to control the cpu and memory for per process. So, lets first install the required tools.

sudo yum install libcgroup-tools

Now, we need to enable the service.

sudo systemctl enable cgconfig.service
sudo systemctl enable cgred.service

cgconfig.service is to enable configuration for cgroups and
cgred.service is to enable configuration for cgroups for processes depending on the name.

Now, we will need to configure the cgroups and configure the groups for the processes. So, lets open up the configuration files and do some configuration:

Here we will use firefox as the group name and use firefox as an example to restrict the memory to 700Mb and cpu to 10%. Since we do not have any other group configured right now, so max being 1024 – 100 shares would be around 10%.

First, open up the /etc/cgconfig.conf file and add the following. You would need to replace below with your username.

group firefox {
perm {
task {
uid = ;
gid = ;
}
admin {
uid = ;
gid = ;
}
}

cpu{
cpu.shares=”102″;
}
cpuset{
cpuset.cpus=0;
cpuset.mems=0;
}
memory {
memory.limit_in_bytes=”700M”;
memory.max_usage_in_bytes=”0″;
}
}

Now, we edit the /etc/cgrules.conf file and add the following:

:sandbox cpu,memory firefox
::firefox cpu,memory firefox

All done. Now, time to test.

First restart the services.

sudo systemctl restart cgconfig.service
sudo systemctl restart cgred.service

Check, if the cgroup is created. Go to directory:

/sys/fs/cgroup/memory or /sys/fs/cgroup/cpu

and check directory firefox exists.

Note: You can check the cgroup mount directory with mount command to see where your cgroups are mounted.

Now, start firefox, check the pid and check the file /proc//cgroup and you should see something like this:

11:hugetlb:/
10:perf_event:/
9:blkio:/
8:net_cls:/
7:freezer:/
6:devices:/
5:memory:/firefox
4:cpuacct,cpu:/firefox
3:cpuset:/
2:name=systemd:/user.slice/user-1000.slice/session-1.scope

and this is it.

Enhanced by Zemanta

Monitor your system with sysusage.

First some information on sysusage:

Description :
SysUsage continuously monitor your systems informations and generate
periodical graph reports using rrdtool or javascript jqplot library.
All reports are shown throught a web interface.

SysUsage grabs all system activities using Sar and system commands allowing
you to keep tracks of your computer or server activity during his life.
It is a great help for performance analysis and resources management. The
threshold notification can alarm you when the system capabilities are
reached by sending SMTP messages or throught Nagios reports.

By default it will monitor all you need to know on your server activity, it
is written in Perl and should works on all Unix like plateforms. It doesn’t
require a Database system like MySQL or PostgreSQL but lie on rrdtool. In
addition you can embeded your own plugins written in any programing language.

Since release 5.0 SysUsage can be run from a centralized place where
collected statistics will be stored and where graphics will be rendered.
Unless other monitoring tools with lot of administration work, SysUsage is
design to have the lesspossible things to configure and a high level of admin
system knowledge. Each server can also be self monitored and you just have to
connect your browser to the web interface to know his health level.

SysUsage is design with simplicity in mind. I want all relevant statistics
from my servers within an intuitive web interface and without spending too
much time to configure it, if you know Nagios, you know what I mean. You will
especially like SysUsage for that.

And now for the installation:

sudo yum install sysusage sysusage-httpd

Once you have installed, you would need to enable the crontab to collect the data. And the sysusage-httpd is for the apache server configure to enable you to access http://localhost/sysusage

And you are done. It pretty good to see the overall system usage wrt to CPU, Disk and network.

Enhanced by Zemanta

zswap – compcache, compressed swap for better performance

First, here is a link to article on compcache.

http://code.google.com/p/compcache/wiki/CompilingAndUsingNew

zswap is already in the kernel and you can see the documentation in the kernel documentation. Here is the name of the file if you need:

/usr/share/doc/kernel-doc-$(uname -r)/Documentation/vm/zswap.txt

Here is the overview, in case you do not want to install kernel-doc

Overview:

Zswap is a lightweight compressed cache for swap pages. It takes pages that are
in the process of being swapped out and attempts to compress them into a
dynamically allocated RAM-based memory pool.  zswap basically trades CPU cycles
for potentially reduced swap I/O.  This trade-off can also result in a
significant performance improvement if reads from the compressed cache are
faster than reads from a swap device.

NOTE: Zswap is a new feature as of v3.11 and interacts heavily with memory
reclaim.  This interaction has not be fully explored on the large set of
potential configurations and workloads that exist.  For this reason, zswap
is a work in progress and should be considered experimental.

Some potential benefits:
* Desktop/laptop users with limited RAM capacities can mitigate the
    performance impact of swapping.
* Overcommitted guests that share a common I/O resource can
    dramatically reduce their swap I/O pressure, avoiding heavy handed I/O
    throttling by the hypervisor. This allows more work to get done with less
    impact to the guest workload and guests sharing the I/O subsystem
* Users with SSDs as swap devices can extend the life of the device by
    drastically reducing life-shortening writes.

Zswap evicts pages from compressed cache on an LRU basis to the backing swap
device when the compressed pool reaches it size limit.  This requirement had
been identified in prior community discussions.

To enabled zswap, the “enabled” attribute must be set to 1 at boot time.  e.g.
zswap.enabled=1

 

Enhanced by Zemanta