From f2e27f5154cd9f21dd2d87778712b068b178d8d0 Mon Sep 17 00:00:00 2001 From: "roberto@quantal64" Date: Fri, 7 Sep 2012 14:54:57 +0200 Subject: [PATCH] improved process limit detection --- core/utils.c | 1 + core/uwsgi.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/utils.c b/core/utils.c index 18234e57..09d79df8 100644 --- a/core/utils.c +++ b/core/utils.c @@ -1112,6 +1112,7 @@ void sanitize_args() { uwsgi.ignore_write_errors = 1; } + if (uwsgi.cheaper_count > 0 && uwsgi.cheaper_count >= uwsgi.numproc) { uwsgi_log("invalid cheaper value: must be lower than processes\n"); exit(1); diff --git a/core/uwsgi.c b/core/uwsgi.c index 0b43b15a..fdb037b7 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -1938,6 +1938,16 @@ int uwsgi_start(void *v_argv) { uwsgi_error("setrlimit()"); } } + + if (!getrlimit(RLIMIT_NPROC, &uwsgi.rl_nproc)) { + if (uwsgi.rl_nproc.rlim_cur != RLIM_INFINITY) { + uwsgi_log("your processes number limit is %d\n", (int) uwsgi.rl_nproc.rlim_cur); + if ((int)uwsgi.rl_nproc.rlim_cur < uwsgi.numproc+uwsgi.master_process) { + uwsgi.numproc = uwsgi.rl_nproc.rlim_cur - 1; + uwsgi_log("!!! number of workers adjusted to %d due to system limits !!!\n", uwsgi.numproc); + } + } + } #endif #ifndef __OpenBSD__ @@ -1970,7 +1980,6 @@ int uwsgi_start(void *v_argv) { } #endif - uwsgi_log_initial("your memory page size is %d bytes\n", uwsgi.page_size); if (uwsgi.buffer_size > 65536) {