Jaime Frutos Morales's blog


How to bind a process to a specific CPU(s) on GNU/Linux

Filed under: Linux, SysAdmin — acidborg @ 13:07

Disclaimer: This recipe is focused on SMP computers only.

Description: CPU affinity is a scheduler property that binds a process to a given set of CPUs on the system, so that the system scheduler won’t run this process on any other CPUs. By default, the scheduler tries to keep processes on the same CPU as long as it makes sense for performance reasons, so forcing CPU affinity is useful only in some cases (per processor licensing, testing, broken hardware, etc).

CPU affinity is represented as a bitmask (given in hexadecimal), with the lowest order bit corresponding to the first logical CPU and the highest order bit corresponding to the last logical CPU. Examples:

  • CPU #0: 0x00000001
  • CPU #1: 0x00000002
  • CPU #2: 0x00000004
  • CPU #3: 0x00000008
  • CPU #0 and CPU #1: 0x00000003
  • CPU #2 and CPU #3: 0x0000000C
  • All CPUs: 0xFFFFFFFF

Taskset is a command used to set or retrieve the CPU affinity of a running process given its PID or to launch a new command with a given CPU affinity.


  • Debian/Ubuntu systems: sudo apt-get install util-linux
  • Red Hat/ Fedora systems: sudo yum install util-linux


  • Retrieve the CPU affinity of a running process: taskset -p PID
    taskset -p 1276
    pid 1276's current affinity mask: 3
  • Set the CPU affinity of a running process: taskset -p MASK PID
    taskset -p 0x00000001 9030
    pid 9030's current affinity mask: 3
    pid 9030's new affinity mask: 1
  • Run a new command with a given CPU affinity: taskset MASK COMMAND

You can check if taskset is working using top and pressing “1” to show all CPUs.



How to configure mod_deflate for Apache on Ubuntu 10.10

Filed under: SysAdmin, Ubuntu — acidborg @ 12:51

Description: mod_deflate is an Apache module which “provides the DEFLATE output filter that allows output from your server to be compressed before being sent to the client over the network.” (from its web). This means that you save some bandwidth in exchange for some CPU cycles compressing the data your Apache server sends.

Installation: If you have Apache installed, you don’t need additional packages, because this module belongs to the package “apache2.2-common“.


  1. Enable the mod_deflate module: sudo a2enmod deflate
  2. Edit /etc/apache2/mods-enabled/deflate.conf with the following content:
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript application/javascript application/ecmascript application/rss+xml text/x-js
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  3. Restart Apache: sudo /etc/init.d/apache2 restart

NOTE: There are some old versions of some browsers which don’t support this kind of compression, although it’s included in RFC 2616 (HTTP/1.1). http-compression.com has more info about it.


How to upgrade from Ubuntu 10.04 (Lucid) to Ubuntu 10.10 (Maverick)

Filed under: Linux, Ubuntu — acidborg @ 11:47

The upgrade is similar to the previous ones:

  1. Replace “lucid” for “maverick” in /etc/apt/sources.list : sudo sed -i 's/lucid/maverick/g' /etc/apt/sources.list
  2. Upgrade your system: sudo apt-get update && sudo apt-get -y dist-upgrade
  3. Reboot: sudo shutdown -r now


How to install and configure Ganglia on Red Hat Enterprise Linux 5

Filed under: Linux, SysAdmin — acidborg @ 13:34

Description: Although Gangliais a scalable distributed monitoring system for high-performance computing systems such as clusters and Grids” (from its web), I’m going to explain how to set up Ganglia as a monitoring system for a group of computers which are neither part of a cluster nor a grid. Ganglia has very low per-node overheads and high concurrency, which makes it perfect to monitor a huge group of servers. I’m going to use one server to collect all data from the nodes. The collector server will run the web front-end for simplicity reasons, although you can install the web front-end on any other server if you need it.


  1. Add the EPEL repositories to your systems.
  2. Install the data collector (gmetad), the monitoring daemon (gmond) and the web front-end on the collector server: yum install ganglia ganglia-gmetad ganglia-web ganglia-gmond
  3. install gmond on each node you want to monitor: yum install ganglia ganglia-gmond

Configuration on the collector server (for example: collector.mycompany.com):

  1. Edit /etc/gmetad.conf and modify the line which begins with “data_source“. Example:
    data_source "my servers" 60 localhost

    This will collect data from the groups of machines tagged as “my servers” every 60 seconds. It will use localhost as the source of the info.

  2. Edit /etc/gmond.conf and modify the following part:
    cluster {
    name = "my servers"
    owner = "unspecified"
    latlong = "unspecified"
    url = "unspecified"
    udp_send_channel {
    host = collector.mycompany.com
    port = 8649
    udp_recv_channel {
    port = 8649
    tcp_accept_channel {
    port = 8649

    This allows collector.mycompany.com to receive monitoring data from every node on port 8649(UDP).

  3. Restart the collector daemon (gmetad): service gmetad restart
  4. Restart the node daemon (gmond): service gmond restart

Configuration on each node you want to monitor (except collector.mycompany.com):

  1. Edit /etc/gmond.conf and modify the following part:
    cluster {
    name = "my servers"
    owner = "unspecified"
    latlong = "unspecified"
    url = "unspecified"
    udp_send_channel {
    host = collector.mycompany.com
    port = 8649
    /*udp_recv_channel {
    tcp_accept_channel {

    This tells gmond to send the info to collector.mycompany.com on port 8649(UDP).

  2. Restart gmond: service gmond restart

After a few minutes, you will have your monitoring data available through: collector.mycompany.com/ganglia .

Blog at WordPress.com.