Pages

Friday, November 16, 2012

Conditional variable assignment/ substitution


Bash does support the conditional variable assignment/ substitution e.g.  below code snippet

#! /bin/bash

name=${2:-"Juned"}

if [ "$name" != "Juned" ];then
echo  "hello $name"
else
echo "bye"
fi

will define the variable name with second command line parameter , but if there is no second command line parameter then the name is defaulted to Juned

Thursday, November 8, 2012

How to increase semaphore value in linux


How to increase semaphore value in linux?
Semaphore can be described as counters used to control access to shared resources by multiple processes, They are most often used as a locking mechanism to prevent processes from accessing a particular resource while another process is performing operations on it.
Semaphore can be used when number of processes try to access the shared resource or same file,Semaphore stored in kernel, so that it can be accessed by all the processes,
# Semaphore can be identified unique id in linux kernel and it can be deleted using semdelete function,
# semaphore values can be incremented or decremented by using functions wait and signal,   
If we are using ONFS (Oracle over network file system) in linux, we need to increase the kernel.sem value to improve system performance
Increasing semaphore value in linux
[root@server ~]# sysctl -A | grep kernel.sem
kernel.sem = 250        32000   32      128

[root@server ~]# ipcs -ls
------ Semaphore Limits --------
max number of arrays = 128
max semaphores per array = 250
max semaphores system wide = 32000
max ops per semop call = 32semaphore max value = 32767


Increase semop value from 32 to 100, it can be increased upto 250 which is equal to semaphores per array,
Add the following line into /etc/sysctl.conf file,
vi /etc/sysctl.conf
kernel.sem = 250 32000 100 128

or
sysctl -w "kernel.sem = 250 32000 100 128"

or 
sysctl -w "kernel.sem=4096 512000 1600 2048"    [ Value reducing your CPU usage from avg 50% to 20%]
kernel.sem: max_sem_per_id max_sem_total max_ops_sem_call max_sem_ids
Now we have modified the kernel.sem value,
Please run the following command to update the changes,[root@server ~]# sysctl -p
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 1
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 4294967295
kernel.shmall = 268435456
kernel.sem = 250 32000 100 128net.ipv6.conf.default.forwarding = 1
net.ipv6.conf.all.forwarding = 1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0

Run ipcs command to ensure the kernel.sem value

[root@server ~]# ipcs -ls
------ Semaphore Limits --------
max number of arrays = 128
max semaphores per array = 250
max semaphores system wide = 32000
max ops per semop call = 100semaphore max value = 32767

Now system will be supported to handle numerous system call at the same time.

Reference

http://www.embeddedheaven.com/linux-semaphore-tutorial.htm

Wednesday, November 7, 2012

Complie php from source

'./configure' '--prefix=/usr' '--with-curl' '--with-bz2' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-wddx' '--with-kerberos' '--enable-ucd-snmp-hack' '--enable-shmop' '--enable-calendar' '--with-mime-magic=/usr/share/file/magic.mime' '--with-libxml-dir=/usr' '--with-libxml-dir=/usr'  '--with-apxs2=/usr/sbin/apxs' '--with-gd' '--enable-pdo' '--with-ldap=/usr' '--with-iconv-dir=/usr' '--with-xpm-dir=/usr' '--with-mysql=/usr' '--with-libdir=lib64' '--enable-mbstring' '--with-zlib=/usr' '--with-config-file-path=/etc' `--enable-pcntl`

How to check which ini file is in use by php


Run a command to find active php.ini file used by php

php -i | grep 'Configuration File'