Monday, November 15, 2010

Port numbers in Linux

Ports in computer networking is an application-specific or process-specific software construct serving as a communications endpoint. It is used by Transport Layer protocols of the Internet Protocol Suite, such as Transmission Control Protocol (TCP) and User Datagram Protocol (UDP). A specific port is identified by its number, commonly known as the port number, the IP address with which it is associated, and the protocol used for communication.
The Internet Assigned Numbers Authority (IANA) is responsible for maintaining the official assignments of port numbers for specific uses. However, many unofficial uses of both well-known and registered port numbers occur in practice.

The port numbers are divided into three ranges:

Well-Known/Standard Ports   (Range: 0 to 1023 )
Used by system processes that provide widely-used types of network services such as SSH, Telnet, SMTP, FTP etc

Registered Ports, and    (Range:  1024 to 49151 )
Used by specific service upon applications such as Oracle database listener (1521), MySql (3306), Microsoft Terminal server (3389) etc.

Dynamic and/or Private Ports. (Range: 49152 to 65535 )
These ports can’t be registered by IANA.  This is used for custom or temporary purposes and for automatic allocation of short-lived (or ephemeral ) ports which is used internally by application/processes. You can see these ports by running ‘netstat’ command under “Local address” column.

In Linux, the port details can be viewed by checking the /etc/services file  and the non-standard (un-registered) ports used by the server can be find using /proc/sys/net/ipv4/ip_local_port_range file.

[adevaraju@host01 ~]$ cat /proc/sys/net/ipv4/ip_local_port_range
32768   61000
[adevaraju@host01 ~]$

Finding file creation time in Linux

Question:  In Linux, is it possible to find the actual time when a file was created first?

The Answer is NO until Ext3

File creation time ISN’T maintained in Linux with file-system Ext3 or earlier version. 
It will change when file content changes. It is explained with an example here:

[adevaraju@cac1-t1 ~]$ date
Tue Nov  9 01:22:25 CST 2010                                                      # Time now is 01:22:25
[adevaraju@cac01-t1 ~]$ echo "Some text on the file " > testfile       # Creating a file
[adevaraju@cac01-t1 ~]$ ls -lc testfile
-rw-r--r-- 1 adevaraju domain users 23 Nov  9 01:22 testfile     # Shows file change time as 01:22
 [adevaraju@cac01-t1 ~]$ ls -lu testfile
-rw-r--r-- 1 adevaraju domain users 23 Nov  9 01:22 testfile     # Access time is also 01:22

[adevaraju@cac01-t1 ~]$ cat testfile                                       # Now am accessing the file
Some text on the file

 [adevaraju@cac01-t1 ~]$ ls -lc testfile                            
-rw-r--r-- 1 adevaraju domain users 23 Nov  9 01:22 testfile     # Change time remains the same
[adevaraju@cac01-t1 ~]$ ls -lu testfile
-rw-r--r-- 1 adevaraju domain users 23 Nov  9 01:23 testfile     # Access time changed to 01:23
[adevaraju@cac01-t1 ~]$ date
Tue Nov  9 01:23:32 CST 2010

[adevaraju@cac01-t1 ~]$ echo "Additional text to the file" >> testfile # file content changed
 [adevaraju@cac01-t1 ~]$ ls -lc testfile                                                                            
-rw-r--r-- 1 adevaraju domain users 51 Nov  9 01:24 testfile      # Change time changes to 01:24
[adevaraju@cacllm01-t1 ~]$ ls -lu testfile
-rw-r--r-- 1 adevaraju domain users 51 Nov  9 01:23 testfile      # But access time remains the same since we did only changes to file.
[adevaraju@cacllm01-t1 ~]$ date
Tue Nov  9 01:24:22 CST 2010
[adevaraju@cacllm01-t1 ~]$

Atlast the original file creation time (which is 01:22) is gone, we CAN’T retrieve that information.

PS:  EXT4 file-system comes out with a feature to find the File-creation time. 

Sunday, November 7, 2010

What should be an optimal Load average for a Linux server ?

When a system shows sluggish performance, we are examining Load average which reports some value. For a long time I was wondering how these values are actually calculated and what should be the ideal value for a given Linux server. 
After some serious search, I found this article which gives satisfactory explanation on Load average.

For people who don’t have time to go through these articles, here is the summary:

1.   Load average NOT to be confused with CPU percentage.

2.   Optimal Load average equals your number of CPU Cores. 
     The point of perfect utilization, meaning that the CPUs are always busy and, yet, no process ever waits for one, is the average matching the number of CPUs. If there are four CPUs on a machine and the reported one-minute load average is 4.00, the machine has been utilizing its processors perfectly for the last 60 seconds. This understanding can be extrapolated to the 5- and 15-minute averages.”

3.   Load average is good for getting a general feeling of the server's condition, but isn't the whole picture.

To make it further simple, if you have 8 CPU Cores (can be found using cat /proc/cpuinfo) on a Linux server, the ideal Load average should be around 8 (+/- 1). If its > 8, then the server resources are over-utilized and if < 8, the server isn’t running with its full potential.