RE: [squid-users] how to raise filedescriptors on kernel 2.4 and other optimizations

From: Erick Arturo Perez <cripto@dont-contact.us>
Date: Tue, 18 Jun 2002 22:15:51 -0500

Several optimizations to a linux box can be made. Some more simple than
others, here are some simple ones that work under kernel 2.4:

The ip_local_port_range "/proc/sys/net/ipv4/ip_local_port_range" defines
the local port range that is used by TCP and UDP traffic to choose the
local port. You will see in the parameters of this file two numbers: The
first number is the first local port allowed for TCP and UDP traffic on
the
server, the second is the last local port number. For high-usage systems
you may change its default parameters to 32768-61000 (first-last).
The default setup for the "ip_local_port_range" parameters under Red Hat
Linux is: "1024 4999"
. To change the values of ip_local_port_range, type the following
command on your terminal:
Under Red Hat Linux 6.1
[root@deep /]# echo "32768 61000" >
/proc/sys/net/ipv4/ip_local_port_range
Add the above commands to the "/etc/rc.d/rc.local" script file and
you'll not have to type it again the next time you reboot your system.
Under Red Hat/Mandrake 8.x Linux 6.2/7.x
Edit the "/etc/sysctl.conf" file and add the following line:
# Allowed local port range
net.ipv4.ip_local_port_range = 32768 61000
You must restart your network for the change to take effect. The command
to restart the
network is the following:
. To restart all network devices manually on your system, use the
following command:
[root@deep /]# /etc/rc.d/init.d/network restart
Setting network parameters [ OK ]
Bringing up interface lo [ OK ]
Bringing up interface eth0 [ OK ]
Bringing up interface eth1

The file-max file "/proc/sys/fs/file-max" set the maximum number of
file-handles that the Linux kernel will allocate. We generally tune this
file to improve the number of open files by increasing the value of
"/proc/sys/fs/file-max" to something reasonable like 256 for every 4M of
RAM we have: i.e. for a machine with 128 MB of RAM, set it to 8192
(128/4=32 32*256=8192).
The default setup for the "file-max" parameter under Red Hat Linux is:
"4096"
. To adjust the value of file-max to 128 MB of RAM, type the following
on your terminal:
Under Red Hat Linux 6.1
[root@deep /]# echo "8192" >/proc/sys/fs/file-max
Add the above commands to the "/etc/rc.d/rc.local" script file and
you'll not have to type it
again the next time your server reboots.
Under Red Hat Linux 6.2
Edit the "/etc/sysctl.conf" file and add the following line:
# Improve the number of open files
fs.file-max = 8192
You must restart your network for the change to take effect. The command
to restart the
network is the following:
. To restart all network devices manually on your system, use the
following command:
[root@deep /]# /etc/rc.d/init.d/network restart
Setting network parameters [ OK ]
Bringing up interface lo [ OK ]
Bringing up interface eth0 [ OK ]
Bringing up interface eth1 [ OK ]
NOTE: When you regularly receive from your server a lot of messages with
errors about running
out of open files, you might want to raise this limit. The default value
is 4096. A file server or web
server needs a lot of open files.

The inode-max file "/proc/sys/fs/inode-max" set the maximum number of
inodes handlers. We generally tune this file to improve the number of
inodes opened by increasing the "/proc/sys/fs/inode-max" to a value
roughly 3 to 4 times (8192*4=32768) the number of opened
files we have set to the "file-max" parameter above. This is because the
number of opened inodes is at least one per open file, and often much
larger for large files.
The default setup for the "file-max" parameter under Red Hat Linux is:
" 16376 "
. To adjust the value of inode-max to 128 MB of RAM, type the following
on your terminal:
Under Red Hat Linux 6.1
[root@deep /]# echo "32768" >/proc/sys/fs/inode-max
Add the above commands to the "/etc/rc.d/rc.local" script file and
you'll not have to type it again the next time your server reboots.
Under Red Hat Linux 6.2
Edit the "/etc/sysctl.conf" file and add the following line:
# Improve the number of inodes opened
fs.inode-max = 32768
You must restart your network for the change to take effect. The command
to restart the
network is the following:
. To restart all network devices manually on your system, use the
following command:
[root@deep /]# /etc/rc.d/init.d/network restart
Setting network parameters [ OK ]
Bringing up interface lo [ OK ]
Bringing up interface eth0 [ OK ]
Bringing up interface eth1 [ OK ]
NOTE: If you regularly run out of inodes, you should increase this
value. Don't forget that the value
you enter for the "inode-max" parameter depends of the "file-max" value.
A file server or web
server needs a lot of opened inodes.

Linux itself has a "Max Processes" per user limit. This feature allows
us to control the number of processes an existing user on the server may
be authorized to have. To improve performance, we can safely set the
limit of processes for the super-user "root" to be unlimited.
Edit the .bashrc file (vi /root/.bashrc) and add the following line:
ulimit -u unlimited
You must exit and re-login from your terminal for the change to take
effect. To verify that you are
ready to go, make sure that when you type as root the command ulimit -a
on your terminal, it shows "unlimited" next to max user processes.
[root@deep /]# ulimit -a
core file size (blocks) 1000000
data seg size (kbytes) unlimited
file size (blocks) unlimited
max memory size (kbytes) unlimited
stack size (kbytes) 8192
cpu time (seconds) unlimited
max user processes unlimited    this line.
pipe size (512 bytes) 8
open files 1024
virtual memory (kbytes) 2105343
NOTE: You may also do ulimit -u unlimited at the command prompt instead
of adding it to the
"/root/.bashrc" file.

Increases the system limit on open files
A process on Red Hat 6.0 with kernel 2.2.5 could open at least 31000
file descriptors this way
and a process on kernel 2.2.12 can open at least 90000 file descriptors
this way. The upper
bound seems to be available memory. To increases the number of open
files to 90000 for the root
account do the following:
Edit the .bashrc file (vi /root/.bashrc) and add the following line:
ulimit -n 90000
You must exit from your terminal and re-login for the change to take
effect. To verify that you are
ready to go, make sure that when you type as root the command ulimit -a
on your terminal, it
shows "90000" next to open files.
[root@deep /]# ulimit -a
core file size (blocks) 1000000
data seg size (kbytes) unlimited
file size (blocks) unlimited
max memory size (kbytes) unlimited
stack size (kbytes) 8192
cpu time (seconds) unlimited
max user processes unlimited
pipe size (512 bytes) 8
open files 90000    this line.
virtual memory (kbytes) 2105343
NOTE: In older 2.2 kernels, though, the number of open files per process
is still limited to 1024,
even with the above changes.

Linux has a special mount option for file systems called noatime that
can be added to each line
that addresses one file system in the "/etc/fstab" file. If a file
system has been mounted with this
option, reading accesses to the file system will no longer result in an
update to the atime
information associated with the file like we have explained above. The
importance of the noatime
setting is that it eliminates the need by the system to make writes to
the file system for files which
are simply being read. Since writes can be somewhat expensive, this can
result in measurable
performance gains. Note that the write time information to a file will
continue to be updated
anytime the file is written to. In our example bellow, we will set the
noatime option to our "/chroot"
file system.
Edit the fstab file (vi /etc/fstab) and add in the line that refer to
"/chroot" file system the noatime
option after the defaults option as show bellow:
E.I: /dev/sda7 /chroot ext2 defaults,noatime 1 2
You must Reboot your system for the change to take effect:
[root@deep /]# reboot
Then test your results with the flowing command:
[root@deep]# cat /proc/mounts
/dev/root / ext2 rw 0 0
/proc /proc proc rw 0 0
/dev/sda1 /boot ext2 rw 0 0
/dev/sda8 /cache ext2 rw 0 0
/dev/sda7 /chroot ext2 rw,noatime 0 0
/dev/sda6 /home ext2 rw 0 0
/dev/sda11 /tmp ext2 rw 0 0
/dev/sda5 /usr ext2 rw 0 0
/dev/sda9 /var ext2 rw 0 0
none /dev/pts devpts rw 0 0
If you see something like: /dev/sda7 /chroot ext2 rw,noatime 0 0,
congratulations!

The swap partition
Putting your swap partitions near the beginning of your drive may give
you some acceptable
improvement. The beginning of the drive is physically located on the
outer portion of the cylinder,
and the read/write head can cover much more ground per revolution. We
typically see partitions
placed at the end of the drive work 3MB/s slower using the hdparm -t
command.

Hope this helps!!!!
Please, any comments on this will be greatly appreciated in order to
squeeze even more performance from the linux box.

Erick A. Perez H.
cripto@c-com.net.pa
eperez@consultant.com
 

-----Original Message-----
From: GUILHEM Michel (75) [mailto:michel.guilhem@cp.finances.gouv.fr]
Sent: Martes, 18 de Junio de 2002 04:59 p.m.
To: squid-users@squid-cache.org
Subject: [squid-users] how to raise filedescriptors on kernel 2.4

The only thing i see for the kernel 2.4 is to use the command
ulimit -n 4096 for example , but with this when i compile a squid after
i got the following messages
Number of filedescriptors by default FD_SETSIZE 1024
Number of max filedescriptors we can open 4096
And when i launch the cachemgr command , the max that i can open for a
squid
is always 1024 .
Can you help me , and describes what file i have to change ( in
directory
/proc/sys .
Any clue is welcome .

Guilhem michel DGCP
Received on Tue Jun 18 2002 - 21:16:06 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 17:08:43 MST