Author: Curt Sampson --- pkg.orig/src/mod_fastcgi.c (revision 4423) +++ pkg/src/mod_fastcgi.c (working copy) @@ -256,6 +256,13 @@ applications prefer SIGUSR1 while the rest of the world would use SIGTERM *sigh* */ + + /* + * If this limit is >= 0, and the queue of requests waiting for + * a FastCGI backend to become free would become larger than + * this, send a 503 response instead of queueing the request. + */ + signed short request_queue_limit; } fcgi_extension_host; /* @@ -1193,6 +1193,7 @@ { "allow-x-send-file", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 15 */ { "strip-request-uri", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 16 */ { "kill-signal", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 17 */ + { "request-queue-limit", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 18 */ { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } }; @@ -1220,6 +1220,7 @@ host->break_scriptfilename_for_php = 0; host->allow_xsendfile = 0; /* handle X-LIGHTTPD-send-file */ host->kill_signal = SIGTERM; + host->request_queue_limit = -1; fcv[0].destination = host->host; fcv[1].destination = host->docroot; @@ -1241,6 +1241,7 @@ fcv[15].destination = &(host->allow_xsendfile); fcv[16].destination = host->strip_request_uri; fcv[17].destination = &(host->kill_signal); + fcv[18].destination = &(host->request_queue_limit); if (0 != config_insert_values_internal(srv, da_host->value, fcv)) { return HANDLER_ERROR; @@ -3124,6 +3124,19 @@ host = hctx->host; } + /* overload check */ + if (host->request_queue_limit >= 0 && host->load > host->request_queue_limit) { + if (p->conf.debug > 0) { + log_error_write(srv, __FILE__, __LINE__, "sbsd", + "request for ", con->uri.path, + "rejected; current load is ", host->load); + } + fcgi_connection_close(srv, hctx); + con->http_status = 503; + con->mode = DIRECT; + return HANDLER_FINISHED; + } + /* ok, create the request */ switch(fcgi_write_request(srv, hctx)) { case HANDLER_ERROR: --- pkg.orig/doc/fastcgi.txt (revision 4423) +++ pkg/doc/fastcgi.txt (working copy) @@ -111,6 +111,7 @@ "broken-scriptfilename" => , # OPTIONAL "disable-time" => , # optional "allow-x-send-file" => # optional + "request-queue-limit" => , # OPTIONAL ), ( "host" => ... ) @@ -146,6 +147,11 @@ again :"allow-x-send-file": controls if X-LIGHTTPD-send-file headers are allowed + :"request-queue-limit": is optional, and defaults to -1. + If this limit is >= 0, and the queue of requests waiting + for a FastCGI process to become available to serve them + would become larger than this, send a 503 response + instead of queueing the request. If bin-path is set: