2.4 Linux file descriptors

If you are using Linux (or other Unixes) as your server operating system you may experience a "Too many open files" error when reaching around 1000 simultaneous connections.

There is nothing to worry about: by default most Linux distributions are set to a maximum of 1024 file descriptors: each time you open a file or a socket connection you use one these descriptors and when you reach the maximum you get the error mentioned above.

You can check the value currently set in your system by typing this command in a terminal window:

ulimit -n

The value returned by the command is the current limit of your OS for all open files and open socket connections.
In order to raise this value you can use the same command followed by a new value.

Example:

ulimit -n 20000

NOTE:
These settings are not global and they only last for the duration of the user session. If you close the session or restart the server the file descriptor limit will go back to its defaults.

In order to keep the wanted values when running SmartFoxServer you should incorporate the ulimit command in the start.sh or sfs script

 

» Fixing the descriptor limit in the launch scripts

The start.sh script is used to start the JVM and the Server directly. It's a one line script that looks like this:

java -cp "./:./sfsExtensions/:lib/activation.jar:lib/commons-beanutils.jar...

All you have to do is simply add the ulimit line at the very top and save.

ulimit -n 20000
java -cp "./:./sfsExtensions/:lib/activation.jar:lib/commons-beanutils.jar...

The sfs scripts launches the native wrapper and reponds to the start, stop, console and restart commands.

Open the script with your favourite text editor and add the ulimit command in the start) section (Lines 182-183).

	start() {
	echo "Starting $APP_LONG_NAME..."
	getpid
	if [ "X$pid" = "X" ]
    
	etc...
Change it to:
	start() {
	ulimit -n 8192
	echo "Starting $APP_LONG_NAME..."
	getpid
	if [ "X$pid" = "X" ]

Save and you are ready to launch.

 


doc index