Ticket #967: mod_fastcgi.patch.4424

File mod_fastcgi.patch.4424, 3.0 kB (added by Curt Sampson <cjs@cynic.net>, 1 year ago)
Line 
1 Index: src/mod_fastcgi.c
2 ===================================================================
3 --- src/mod_fastcgi.c   (revision 4423)
4 +++ src/mod_fastcgi.c   (working copy)
5 @@ -250,6 +250,13 @@
6         to die and decrements its afterwards */
7  
8         buffer *strip_request_uri;
9 +
10 +       /*
11 +         * If this limit is >= 0, and the queue of requests waiting for
12 +         * a FastCGI backend to become free would become larger than
13 +         * this, send a 503 response instead of queueing the request.
14 +        */
15 +       signed short request_queue_limit;
16  } fcgi_extension_host;
17  
18  /*
19 @@ -1179,6 +1186,8 @@
20                                                 { "allow-x-send-file", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },      /* 15 */
21                                                 { "strip-request-uri",  NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },      /* 16 */
22  
23 +                                               { "request-queue-limit", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },      /* 17 */
24 +
25                                                 { NULL,                NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
26                                         };
27  
28 @@ -1204,6 +1213,7 @@
29                                         host->disable_time = 60;
30                                         host->break_scriptfilename_for_php = 0;
31                                         host->allow_xsendfile = 0; /* handle X-LIGHTTPD-send-file */
32 +                                       host->request_queue_limit = -1;
33  
34                                         fcv[0].destination = host->host;
35                                         fcv[1].destination = host->docroot;
36 @@ -1224,6 +1234,7 @@
37                                         fcv[14].destination = &(host->break_scriptfilename_for_php);
38                                         fcv[15].destination = &(host->allow_xsendfile);
39                                         fcv[16].destination = host->strip_request_uri;
40 +                                       fcv[17].destination = &(host->request_queue_limit);
41  
42                                         if (0 != config_insert_values_internal(srv, da_host->value, fcv)) {
43                                                 return HANDLER_ERROR;
44 @@ -3024,6 +3035,19 @@
45                 host = hctx->host;
46         }
47  
48 +       /* overload check */
49 +       if (host->request_queue_limit >= 0 && host->load > host->request_queue_limit) {
50 +               if (p->conf.debug > 0) {
51 +                       log_error_write(srv, __FILE__, __LINE__, "sbsd",
52 +                                       "request for ", con->uri.path,
53 +                                       "rejected; current load is ", host->load);
54 +               }
55 +               fcgi_connection_close(srv, hctx);
56 +               con->http_status = 503;
57 +               con->mode = DIRECT;
58 +               return HANDLER_FINISHED;
59 +       }
60 +
61         /* ok, create the request */
62         switch(fcgi_write_request(srv, hctx)) {
63         case HANDLER_ERROR:
64 Index: doc/fastcgi.txt
65 ===================================================================
66 --- doc/fastcgi.txt     (revision 4423)
67 +++ doc/fastcgi.txt     (working copy)
68 @@ -111,6 +111,7 @@
69           "broken-scriptfilename" => <boolean>, # OPTIONAL
70            "disable-time" => <integer>, # optional
71            "allow-x-send-file" => <boolean> # optional
72 +         "request-queue-limit" => <integer>, # OPTIONAL
73         ),
74          ( "host" => ...
75          )
76 @@ -146,6 +147,11 @@
77                  again
78    :"allow-x-send-file": controls if X-LIGHTTPD-send-file headers
79                  are allowed
80 +  :"request-queue-limit": is optional, and defaults to -1.
81 +                If this limit is >= 0, and the queue of requests waiting
82 +                for a FastCGI process to become available to serve them
83 +                would become larger than this, send a 503 response
84 +                instead of queueing the request.
85  
86    If bin-path is set:
87