Tips to increase socket (fds) on Linux or Unix systems for network admin

(Last Updated On: May 14, 2010)

Tips to increase socket (fds) on Linux or Unix systems for network admin
If you ever come across a challenge in your Linux or Unix kernel development, one of the biggest roadblocks is the number of file descriptors (also known as fds or sockets) certain processes have access to. These are obviously set by network administrators with root access in to the box. These same file descriptors can either enhance or degrade the performance of any server using HTTP for the internet. The number you set depends on if the server will be used for either a client or used for something like an email server.
Note that the following instructions can be used by either PAM (pluggable authentication modules) or ssh-ing into a remote server.
You can check the system limits, do:
1. cat /proc/sys/fs/file-max
If you need any changes to surive after rebooting, make changes in /etc/sysctl.conf and edit:
# Maximum number of open files permitted
fs.file-max = 65535

To reload any changes to this file, do: sysctl -p /etc/sysctl.conf.
You can make further changes by following any of these recommendations:
[Find out where __FD_SETSIZE is defined]
% grep “#define __FD_SETSIZE” /usr/include/*.h /usr/include/*/*.h
/usr/include/bits/types.h:#define __FD_SETSIZE 1024
/usr/include/linux/posix_types.h:#define __FD_SETSIZE 1024

Alternately your system may use tabs in which case
something like this should do the trick:
% grep -E “#define\W+__FD_SETSIZE” /usr/include/*.h /usr/include/*/*.h

[Make a local copy of these files]
% cp /usr/include/bits/types.h include/bits/types.h
% cp /usr/include/linux/posix_types.h include/linux/posix_types.h

[Modify them so that they look something like
#define __FD_SETSIZE 65535

[Recompile httperf and/or your server so that it uses a larger file
descriptor set size by using -I include during compliation, this
will allow the compiler/pre-processor to use the new include files
rather than the default versions]

To check and modify limits per shell.
[Using csh: openfiles and descriptors show that the limit here is 1024]
% limit
cputime unlimited
filesize unlimited
datasize unlimited
stacksize 8192 kbytes
coredumpsize 0 kbytes
memoryuse unlimited
descriptors 1024
memorylocked unlimited
maxproc 8146
openfiles 1024

[To increase this to 65535 for all users (as root)]
# vi /etc/security/limits.conf

[Modify or add “nofile” (number of file) entries – note
that a userid can be used in place of *]
* soft nofile 65535
* hard nofile 65535

# vi /etc/pam.d/login
[Add the line]
session required /lib/security/pam_limits.so

[On many systems this will be sufficient – log in as a regular
user and try it before doing the following steps]

[These steps may be required depending on how PAM and ssh are configured
[Note on some systems – Debian?]
# vi /etc/pam.d/ssh
[Note on other systems – RedHat]
# vi /etc/pam.d/sshd
[Add the line]
session required /lib/security/pam_limits.so

# vi /etc/ssh/sshd_config
[May need to modify or add the line]
UsePrivilegeSeparation no

[Restart the ssh daemon]
[Note on some systems – Debian?]
# /etc/init.d/ssh reload
[Note on other systems – RedHat]
# /etc/rc.d/init.d/sshd reload

Also, if you need to do any of these manually. Do in In tcsh
limit descriptors 65535

In bash, do
ulimit -n 65535

Hopefully, these tips will help out any Linux or Unix network administrator. This is also helpful for those wanting to get into either Java or C++ development positions at investment banks.

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Subscribe For Latest Updates

Sign up to best of business news, informed analysis and opinions on what matters to you.
Invalid email address
We promise not to spam you. You can unsubscribe at any time.


Check NEW site on stock forex and ETF analysis and automation

Scroll to Top