Search This Blog

Friday, June 22, 2012

Check whether hyperthreading is enabled or not ?

We can check whether hyper threading is enabled or not without checking in bios by giving following command
# cat /proc/cpuinfo
If the number of siblings and number of cores you see is same then hyper threading is not enabled. If they are not same then its enabled.
If its enabled, then "siblings" give logical cores present and "cpu core" gives actual physical cores.

Total number of cpu's is equal to maximum number of cpu id available in the result + 1.

If you want to find out how many cores are present in a particular cpu and what there numbers are then you can give following command.

#  cat /sys/devices/system/cpu/cpu2/topology/core_siblings_list

CPU affinity using taskset command in linux

In case of a machine having mulitple processor like NUMA processes generally perform better on one processor when compared to other processors. So its necessary to attach process to that particular processor so as to maximize performance. For such reasons, a tool named taskset can be used. The linux scheduler then acts according to processor affinity set by taskset command. But generally scheduler tries to keep process on same CPU as long as it supports natural affinity. So this taskset command may not work in all cases.

Command to check affinity of process with pid
# taskset -p pid
This command tells which cores have been assigned to the process with taht pid.

Command to set affinity of process
# taskset -p mask pid
This command is used to assign process with pid to cores given by that mask.

Mask is defined as follows:
It is a bitmap of processors present in the system. For example if there are 4 cores then 4 bits will be used in bitmap and if there are 8 cores then 8 bits will be used in bitmap.LSB indicates first core and MSB indicates last core. So to assign process with pid 1111 to cores 0,2,4,6 we will give following command
# taskset -p 0X55 1111
To assign it to cores 1,3,5,7 we will give following command
 # taskset -p 0Xaa 1111

Wednesday, June 20, 2012

Lock paged memory when using memcached by using memcached -k option

In case of memcached, paged memory should be locked for following reasons

1) If we reserve some paged memory for memcached then time would be saved in allocating memory for key/value pairs dynamically.
So memcached has memcached -k option to lock paged memory. But generally when you use this option you tend to get following error.

#memcached -u user -k &
warning: -k invalid, mlockall() failed: Cannot allocate memory

This occurs because by default llocked memory is only 64K. You can check this using
# ulimit -l

To change this, open /etc/security/limits.conf and then enter following lines at the end of file.

root   -     memlock   1048576

where root is the user who is going to run the memcached command from command line.

After that logout and login again and then check by using
#ulimit -l

vmap allocation for size=<> failed errror and adding kernel parameter while booting

This error arrises because the virtual memory allocated when operating system boots is limited. In order to solve this problem we have to increase virtual memory by giving external parameter to kernel when its booting.

This can be done in following way.

1)On the splash screen showing grub i.e.where operating system to be booted is shown, press e.

2)Then on the page which appears select that line which starts with the work "kernel". Again press e and go to the end of the line and write vmalloc=

3)After that press enter and boot that operating system. That would  remove that error.

Error inserting module : unknown symbol _udivdi3 undefined

This error occurs on 32 bit operating system. This won't come if you are using 64 bit operating system. If you wan't to avoid this error in 32 bit operating system then you will have to do following thing.

In your code wherever you are doing division by using "/" operator replace it by following
uint32_t do_div(uint64_t dividend, uint32_t divisor)


So a/b would be do_div(a/b).

RHEL Network card not detecting ( Troubleshooting network )

There might be many reasons for network not working as per our requirement. I am going to point out few things which I always do when there is some problem with network. And after working over all theses things for long time, I guess I will be covering most of the reasons for network not working as per our requirement.

Before you start, you can disable firewall using
#service iptables stop

1)You can use following command to configure your network adaptor
#system-config-network
After that you can give it IP address, netmask, broadcast address or allow it to take ip from dhcp server. Then you can save and quit and give following command.
#service network restart

2) #ifconfig
This is the command which you should use first to check if the network interfaces are as per your requirement. So this will confirm that network adaptor is enabled.

3)After this you can try connecting i.e. pinging some ip address in your network which is active. If ping does not work then mostly cable is not properly attached. You can use ethtool to figure that out.

#ethtool ethX
If cable is fine then it will show at the bottom "Link detected : yes"
Otherwise it will show "no" instead of "yes". In that case you can try fixing the cable properly.

4) If there is still problem you can check further information about network card and just cross check it with following command.
#ethtool -i ethX
This will show information about network card

5)You can also check whether network card driver has loaded properly by using following command.
#lsmod | grep


Friday, June 15, 2012

Installing Memcached with libevent and benchmarking it with memslap

Memcached is "Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load." Memcached is used by most of the companies today including Facebook, Craiglist, Flickr and Twitter. This is one of the thing which I worked on during my summer intern. I am just going to mention the steps for installing memcached and the problems which I faced doing it.

Installation:
1) Download libevent from  http://libevent.org/ . This is one of the dependency for installing memcached.

2) Extract it

3) Go inside extracted directory and type following things
#./configure --prefix=/usr/local
(If you don't put --prefix then chances are that later on while installing memcached it might give problems.)


# make && make install

4) Download source code of memcached from http://www.memcached.org/

5) Extract it

6) Go inside the extracted directory.
#./configure --libevent-with=/usr/local
# make && make install

7) You can check whether memcached is working by giving following command
# memcached -u nobody &
After that you can do 
# ps -el | grep memcached
to see if memcached is started.

8)Now its time to install memslap which is client for memcached. Its used for benchmarking purpose.

9) Download couchbase from http://www.couchbase.com/

10) Extract it and go inside libmemcached directory present in it.

11) Then build libmemcached.

# ./configure
# make

12) Now go inside clients directory present inside libmemcached and give following command
# ./memslap -s server_ip
to start benchmarking process. After some time (600s) you will get some output. You can vary parameters as per documentation of memslap.