版权信息:可以任意转载, 转载时请务必以超链接形式标明文章原文出处 ,谢谢
原文出处: http://libiao.appspot.com/2010/01/nginx_connection_fd_numbers.html
在Nginx中,每个worker进程中的连接数 默认值为512 ,也可以通过event模块下的worker_connections 这个参数来设置,
#define DEFAULT_CONNECTIONS 512
ngx_conf_init_uint_value(ecf->connections, DEFAULT_CONNECTIONS);
cycle->connection_n = ecf->connections;
打开文件数目 是通过getrlimit来获取当前系统的一个进程中open file的数目,在(ngx_event_process_init中)
if (ngx_event_flags & NGX_USE_FD_EVENT) {
struct rlimit rlmt;
if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"getrlimit(RLIMIT_NOFILE) failed");
return NGX_ERROR;
}
cycle->files_n = (ngx_uint_t) rlmt.rlim_cur;
cycle->files = ngx_calloc(sizeof(ngx_connection_t *) * cycle->files_n,
cycle->log);
if (cycle->files == NULL) {
return NGX_ERROR;
}
}
在FreeBSD 8.0中一个进程打开文件数目为3520
[kingoal@sunrise ~/tmp]$ ulimit -a
socket buffer size (bytes, -b) unlimited
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) 524288
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 3520
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 65536
cpu time (seconds, -t) unlimited
max user processes (-u) 1760
virtual memory (kbytes, -v) unlimited
swap size (kbytes, -w) unlimited