Monday, May 21, 2012

Alternatives usage


Alternatives allows you to toggle between several version of the installed binary using symlink. Alternatives has a default administrative directory as /var/lib/alternatives where it keeps all the metadata


Most common usage of alternatives are
alternatives --install
alternatives --config
alternatives --remove

usage: alternatives --install
update-alternatives --install "/usr/bin/java" "java" "/usr/java/default/bin/java" 3

lrwxrwxrwx. 1 root root 12 Feb 22 20:04 /usr/sbin/update-alternatives -> alternatives

ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 35 Jun  8  2010 /etc/alternatives/java -> /usr/lib/jvm/jre-1.4.2-gcj/bin/java


[root@pg ~]# alternatives --config java

There is 1 program that provides 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java


update-alternatives --install /usr/bin/java java /usr/bin/jade 3

[root@pg ~]# alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
   2           /usr/bin/jade

Enter to keep the current selection[+], or type selection number:



[root@pg ~]# alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
 + 2           /usr/bin/jade

Enter to keep the current selection[+], or type selection number:


[root@pg ~]# ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 13 Apr 24 01:33 /etc/alternatives/java -> /usr/bin/jade



Why apache shows multiple processes?


The multiple apache processes we see is by design to handle multiple requests. Those multiple processes is basically listeners with multiple threads, so that it can handle simultaneous traffic more efficiently.

By default, apache spawns10 processes and each process generally takes about 10MB. Assuming all the sub processes takes the same memory its about 100MB for apache running on a machine.

Example of apache running:
#top -U nobody

Memory: 8064M phys mem, 2620M free mem, 12G total swap, 9550M free swap

   PID USERNAME LWP PRI NICE  SIZE   RES STATE    TIME    CPU COMMAND
 14436 nobody     1  59    0   12M 3272K sleep    0:09  0.00% httpd
 14435 nobody     1  59    0   12M 3232K sleep    0:08  0.00% httpd
 17184 nobody     1  59    0   12M 4488K sleep    0:06  0.00% httpd
 14437 nobody     1  59    0   12M 4152K sleep    0:06  0.00% httpd
 17182 nobody     1  59    0   12M 4040K sleep    0:06  0.00% httpd
 14439 nobody     1  59    0   12M 3272K sleep    0:06  0.00% httpd
 16956 nobody     1  59    0   12M 4032K sleep    0:05  0.00% httpd
 14438 nobody     1  59    0   12M 3272K sleep    0:04  0.00% httpd
 17579 nobody     1  59    0   12M 3208K sleep    0:04  0.00% httpd
 17183 nobody     1  59    0   12M 3144K sleep    0:03  0.00% httpd



The defaults in httpd.conf include :


StartServers 8

MinSpareServers 5

User apache


That means start 8 listeners (total 9 processes - root httpd process + 8 servers) and have a minimum of 5 idle listeners at all times (dynamically creating new listeners as necessary). The 'User' directive controls which non-root account the listeners run as (usually 'apache' or 'nobody').

There are lots of other related directives but, unless you have low traffic and are trying to save memory, I wouldn't recommend changing the defaults.