Monday, September 27, 2010

Faster Internet Browsing Thru. Local DNS Cache

A local DNS cache can help for faster browsing since you’re caching the DNS request instead of attempting that request multiple times. The internet speed will not get any faster, but the browsing speed will improve, because on each website there are usually quite a few DNS requests for which the local DNS cache will be used, bringing the query time to almost 0.

To see how fast your current domain name servers (DNS) are, open a terminal execute below command.
]# dig yahoo.com

You Should get something like this.
*************************************************************************
; <<>> DiG 9.6.1-P1 <<>> yahoo.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42045 ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION: ;yahoo.com. IN A

;; ANSWER SECTION: yahoo.com. 20142 IN A 69.147.114.224 yahoo.com. 20142 IN A 209.131.36.159 yahoo.com. 20142 IN A 209.191.93.53

;; Query time: 50 msec

;; SERVER: 208.67.220.220#53(208.67.220.220)
;; WHEN: Wed Dec 9 13:21:48 2009
;; MSG SIZE rcvd: 75

*************************************************************************

Notice the "Query time" in bold. It's usually somewhere near 50 msec. (it depends on your domain name servers).

Run this one more time. If the query time decreases to less than 5
msec, it means your internet service provider DNS already uses some
caching method and you do not need to follow this how-to. If the
response time is almost the same and you are using a cable (broadband)
internet connection, you can use this guide to cache the DNS for faster
internet browsing.

Now, Let's Start The Practical.

Manually configuring the local DNS cache
1. Install DNSMasq:
yum install dnsmasq


2. Edit "Dnsmasq" configuration file.
vim /etc/dnsmasq.conf

3.
Now search for "listen-address" (it's on line 90 on my Ubuntu Karmic installation), remove the "#" character in front of "listen-address" and add "127.0.0.1" after the "=" (all without the quotes). Basically, this is how the "listen-address" line should look like after editing it :

listen-address=127.0.0.1


4. You can also edit the cache size if you want. Search for this in the same file: "#cache-size=150" (it's on line 432 on my Ubuntu Karmic installation), remove the "#" character in front of the line (this uncomments it) and change "150" with the size you want for you DNS cache. This is how the line should look after editing it :

cache-size=500


Note :- "500" can be any number you want.

5. Edit "/etc/resolv.conf" file & modify First Line.

nameserver 127.0.0.1
nameserver ISP_DNS1
nameserver ISP_DNS2


6. Finally "service network restart" & "service dnsmasq restart"

7.
Testing
To see the performance improvement, open a terminal and type:


dig yahoo.com
************************************************************
; <<>> DiG 9.6.1-P2 <<>> yahoo.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57501
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;yahoo.com. IN A

;; ANSWER SECTION:
yahoo.com. 20982 IN A 209.131.36.159
yahoo.com. 20982 IN A 69.147.114.224
yahoo.com. 20982 IN A 209.191.93.53

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Dec 9 14:43:41 2009
;; MSG SIZE rcvd: 75
************************************************************
0 msec. query time, because the domains are now cached.

That's it.

Tuesday, September 21, 2010

Limit CPU Usage Per Process in Linux

This practical is tested successfully on Fedora 11 i386 & CentOS 5.4 Only.

Download "cpulimit" setup file first.

wget '
http://downloads.sourceforge.net/cpulimit/cpulimit-1.1.tar.gz'

Extract it & go inside the directory.
tar -zxvf cpulimit-1.1.tar.gz

cd cpulimit-1.1

make

cp cpulimit /usr/local/sbin/
rm -rf cpulimit*

Command to run cpulimit.


To limit CPU usage of the process called firefox to 30%, enter:
# cpulimit -e firefox -l 30

To limit CPU usage of the process to 30% by using its PID, enter:

# cpulimit -p 1313 -l 30
To find out PID of the process use any of the following:

# ps aux | less


# ps aux | grep firefox


# pgrep -u nnv php-cgi


# pgrep lighttpd


You can also use absolute path name of the executable, enter:

# cpulimit -P /opt/firefox/firebox -l 30
Where,

* -p : Process PID.
* -e : Process name.
* -l : percentage of CPU allowed from 0 to 100.
* -P: absolute path name of the executable program file.

Thanks,
Nishith N.Vyas.
Call : +91 9879597301

Root Filesystem Definition.

The root filesystem is the filesystem that is contained on the same partition on which the root directory is located, and it is the filesystem on which all the other filesystems are mounted (i.e., logically attached to the system) as the system is booted up (i.e., started up).

A partition is a logically independent section of a hard disk drive (HDD). A filesystem is a hierarchy of directories (also referred to as a directory tree) that is used to organize files on a computer system. On Linux and and other Unix-like operating systems, the directories start with the root directory, which contains a series of subdirectories, each of which, in turn, contains further subdirectories, etc. A variant of this definition is the part of the entire hierarchy of directories (i.e., of the directory tree) that is located on a single partition or disk.

The exact contents of the root filesystem will vary according to the computer, but they will include the files that are necessary for booting the system and for bringing it up to such a state that the other filesystems can be mounted as well as tools for fixing a broken system and for recovering lost files from backups. The contents will include the root directory together with a minimal set of subdirectories and files including /boot, /dev, /etc, /bin, /sbin and sometimes /tmp (for temporary files).

Only the root filesystem is available when a system is brought up in single user mode. Single user mode is a way of booting a damaged system that has very limited capabilities so that repairs can be made to it. After repairs have been completed, the other filesystems that are located on different partitions or on different media can then be mounted on (i.e., attached to) the root filesystem in order to restore full system functionality. The directories on which they are mounted are called mount points.

The root filesystem should generally be small, because it contains critical files and a small, infrequently modified filesystem has a better chance of not becoming corrupted. A corrupted root filesystem will generally mean that the system becomes unbootable (i.e., unstartable) from the HDD, and must be booted by special means (e.g., from a boot floppy).

A filesystem can be mounted anywhere in the directory tree; it does not necessarily need to be mounted on the root filesystem. For example, it is possible (and very common) to have one filesystem mounted at a mount point on the root filesystem, and another filesystem mounted at a mount point contained in that filesystem.