Nginx-ru mailing list archive (nginx-ru@sysoev.ru)
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH]  увеличение NGX_DEFAULT_RLIMIT	_NOFILE с 1024 до (40 * 1024)
 
 
On 28.02.2011 16:06, Igor Sysoev wrote:
[...]
 
2011/02/28 13:19:02 [emerg] 13753#0: open()
"/usr/share/nginx/logs/loxal.access.log" failed (24: Too many open
files)
2011/02/28 13:21:12 [emerg] 15785#0: open()
"/usr/share/nginx/logs/mbttechnology.access.log" failed (24: Too many
open files)
 
 
 
 
Это и есть ошибки при reload.
Возможно, нужно добавлять фразу "while reconfiguring".
 
 
предлагаю более простой и надежный вариант решения этой проблемы:
при старте nginx установить limit on number of open files
в (40 * 1024) вместо дефолтового для системы значения 1024.
это устранит проблему Too many open files во время service nginx reload,
при этом для worker-процессов можно будет выставить любой нужный лимит
с помощью глобальной директивы worker_rlimit_nofile в конфиге nginx.
P.S.
этот patch подходит для nginx версий 0.9.5 и 0.8.54
--
Best regards,
 Gena
 --- src/core/nginx.c.orig       2011-02-28 19:01:31.000000000 +0200
+++ src/core/nginx.c    2011-02-28 19:29:38.000000000 +0200
@@ -8,6 +8,7 @@
 #include <ngx_core.h>
 #include <nginx.h>
 
+#define NGX_DEFAULT_RLIMIT_NOFILE (40 * 1024)
 
 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle);
 static ngx_int_t ngx_get_options(int argc, char *const *argv);
@@ -199,6 +200,7 @@
 main(int argc, char *const *argv)
 {
     ngx_int_t         i;
+    struct rlimit     rlmt;
     ngx_log_t        *log;
     ngx_cycle_t      *cycle, init_cycle;
     ngx_core_conf_t  *ccf;
@@ -266,6 +268,13 @@
 
     /* TODO */ ngx_max_sockets = -1;
 
+    rlmt.rlim_cur = (rlim_t) NGX_DEFAULT_RLIMIT_NOFILE;
+    rlmt.rlim_max = (rlim_t) NGX_DEFAULT_RLIMIT_NOFILE;
+    if (setrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
+        ngx_log_stderr(0, "setrlimit(RLIMIT_NOFILE, %i) failed",
+                                     NGX_DEFAULT_RLIMIT_NOFILE);
+    }
+
     ngx_time_init();
 
 #if (NGX_PCRE)
_______________________________________________
nginx-ru mailing list
nginx-ru@xxxxxxxxx
http://nginx.org/mailman/listinfo/nginx-ru
 
 
 |