sábado, 8 de noviembre de 2008

File Descriptors

A file descriptor is a handle created by a process when a file is opened. There is a limit to the amount of file descriptors per process. The default Solaris file descriptor limit is 64.

If the file descriptor limit is exceeded for a process, you may see the following errors:

"Too Many Open Files"
"Err#24 EMFILE" (in truss output)

To display a process' current file descriptor limit, run /usr/proc/bin/pfiles pid | grep rlimit on Solaris systems.

Display system file descriptor settings:
ulimit -Hn (hard limit, cannot be exceeded)
ulimit -Sn / ulimit -n (soft limit may be increased to hard limit value)

Increasing file descriptor settings for child processes (example):
$ ulimit -Hn
1024
$ ulimit -Sn
64
$ ulimit -Sn 1024
$ ulimit -Sn
1024

Solaris kernel parameters:
rlim_fd_cur: soft limit

It may be dangerous to set this value higher than 256 due to limitations with the stdio library. If programs require more file descriptors, they should use setrlimit directly.

rlim_fd_max: hard limit

It may be dangerous to set this value higher than 1024 due to limitations with select. If programs require more file descriptors, they should use setrlimit directly.

To count number of open file descriptors:

#!/bin/bash
var=`ps -fea | grep named | grep -v pts | awk '{ print $2 }'`
for i in $var; do
npfiles=`/usr/proc/bin/pfiles -n $i | tail +3 | wc -l` ;
echo "Number of Open File Descriptors per named Process: PID=$i : Num OPFD=$npfiles";
done


http://www.princeton.edu/%7Eunix/Solaris/troubleshoot/filedesc.html



SOLUTION: Using FD_SETSIZE to allow application to use more than 1024 file descriptors

The application core dumped after attempting to access more file descriptors than allowed by the 32-bit library.

From the manpage for select(3C) :

"The default value for FD_SETSIZE (currently 1024) is larger than the default limit on the number of open files. To accommodate 32-bit applications that wish to use a larger number of open files with select(), it is possible to increase this size at compile time by providing a larger definition of FD_SETSIZE before the inclusion of.

The maximum supported size for FD_SETSIZE is 65536. The default value is already 65536 for 64-bit applications."

And from /usr/include/sys/select.h :

#ifndef FD_SETSIZE
#ifdef _LP64
#define FD_SETSIZE 65536
#else
#define FD_SETSIZE 1024
#endif /* _LP64 */
#elif FD_SETSIZE > 1024 && !defined(_LP64)
#ifdef __PRAGMA_REDEFINE_EXTNAME
#pragma redefine_extname select select_large_fdset
#else /* __PRAGMA_REDEFINE_EXTNAME */
#define select select_large_fdset
#endif /* __PRAGMA_REDEFINE_EXTNAME */
#endif /* FD_SETSIZE */

On Solaris[TM] 7, 8, 9, and 10 one can over come the 1024 32-bit library file descriptors limit by redefining the maximum allowed library limit and recompiling the source code with the following lines added.

        #define FD_SETSIZE 65535
#include

The FD_SETSIZE is the library file descriptor limit. After adjusting the library limit, it is necessary to adjust the system limit of file descriptors. This can be done by adding the following lines to the etc/system file and then rebooting.

        set rlim_fd_cur 1024
set rlim_fd_max 65535

To adjust the current soft limit of allowable system file descriptors above 1024 for an application without adjusting the system soft limit, one should use the "ulimit -n [limit]" or "limit descriptors [limit]" commands before starting applications that require more than 1024 file descriptors.

The value can not exceed the maximum in the table below.

default soft limit | default hard limit | max for stdio | max for select()

Solaris[TM] 2.4-2.6 64 1024 256 1024

Solaris[TM] 7 (32-bit) 64 1024 256 65535 (with recompile)

Solaris[TM] 7 (64-bit) 64 1024 256 65535

Solaris[TM] 8 (32-bit) 256 1024 256 65535 (with recompile)

Solaris[TM] 8 (64-bit) 256 1024 256 65535

Solaris[TM] 9 (32-bit) 256 65535 256 65535 (with recompile)

Solaris[TM] 9 (64-bit) 256 65535 256 65535

Solaris[TM] 10 (32-bit) 256 65535 256 65535 (with recompile)

Solaris[TM] 10 (64-bit) 256 65535 256 65535

Please note that for applications that use the Berkeley stdio.h interface (i.e. fopen/fclose/fread/fwrite, etc), the maximum number of open file descriptors per process is 256.

With the exception of databases and WebServers, most applications never need more than 256 open file descriptors. Also starting with Solaris[TM] 7, the plimit(1) command can be used to adjust the soft and hard limits of a running process.

plimit -n ,

The poll() system call has the number of file descriptors being polled passed in as an argument, so it has none of the above limitations.

No hay comentarios: