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.

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

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!
This entry was posted in Quant Development and tagged , , , , , , , on by .

About caustic

Hi i there My name is Bryan Downing. I am part of a company called QuantLabs.Net This is specifically a company with a high profile blog about technology, trading, financial, investment, quant, etc. It posts things on how to do job interviews with large companies like Morgan Stanley, Bloomberg, Citibank, and IBM. It also posts different unique tips and tricks on Java, C++, or C programming. It posts about different techniques in learning about Matlab and building models or strategies. There is a lot here if you are into venturing into the financial world like quant or technical analysis. It also discusses the future generation of trading and programming Specialties: C++, Java, C#, Matlab, quant, models, strategies, technical analysis, linux, windows P.S. I have been known to be the worst typist. Do not be offended by it as I like to bang stuff out and put priorty of what I do over typing. Maybe one day I can get a full time copy editor to help out. Do note I prefer videos as they are much easier to produce so check out my many video at youtube.com/quantlabs