Skip to content

Commit

Permalink
Add max_connections_max_queue_length command and test
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Nov 28, 2008
1 parent 6fd4f2e commit ca8d6ef
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
@@ -1,4 +1,4 @@
NGINX_DIR = "../nginx-0.6.33" # change me
NGINX_DIR = "../nginx-0.6.34" # change me
THIS_DIR = $(shell pwd)

default: compile
Expand Down
44 changes: 39 additions & 5 deletions max_connections_module.c
Expand Up @@ -12,7 +12,6 @@

/* 0.5 seconds until a backend SLOT is reset after client half-close */
#define CLIENT_CLOSURE_SLEEP ((ngx_msec_t)500)
#define MAX_QUEUE_LENGTH (1000)

typedef struct {
ngx_uint_t max_connections;
Expand Down Expand Up @@ -57,6 +56,7 @@ static ngx_uint_t max_connections_rr_index;
/* forward declarations */
static char * max_connections_command (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char * max_connections_queue_timeout_command (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char * max_connections_max_queue_length_command (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static void * max_connections_create_conf(ngx_conf_t *cf);

#define RAMP(x) (x > 0 ? x : 0)
Expand All @@ -76,6 +76,13 @@ static ngx_command_t max_connections_commands[] =
, 0
, NULL
}
, { ngx_string("max_connections_max_queue_length")
, NGX_HTTP_UPS_CONF|NGX_CONF_TAKE1
, max_connections_max_queue_length_command
, 0
, 0
, NULL
}
, ngx_null_command
};

Expand Down Expand Up @@ -296,10 +303,11 @@ dispatch (max_connections_srv_conf_t *maxconn_cf)
assert(!r->connection->error);
assert(peer_data->backend == NULL);

ngx_log_debug2( NGX_LOG_DEBUG_HTTP
ngx_log_debug3( NGX_LOG_DEBUG_HTTP
, r->connection->log
, 0
, "max_connections dispatch (queue timeout: %ui, maxconn: %ui)"
, "max_connections dispatch (max_queue_length: %ui, queue timeout: %ui, maxconn: %ui)"
, maxconn_cf->max_queue_length
, maxconn_cf->queue_timeout
, maxconn_cf->max_connections
);
Expand Down Expand Up @@ -569,6 +577,11 @@ max_connections_init(ngx_conf_t *cf, ngx_http_upstream_srv_conf_t *uscf)
return NGX_OK;
}

/* TODO This function is probably not neccesary. Nginx provides a means of
* easily setting scalar time values with ngx_conf_set_msec_slot() in the
* ngx_command_t structure. I couldn't manage to make it work, not knowing
* what I should be using for the two offset parameters.
*/
static char *
max_connections_queue_timeout_command (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
Expand Down Expand Up @@ -596,6 +609,27 @@ max_connections_queue_timeout_command (ngx_conf_t *cf, ngx_command_t *cmd, void
return NGX_CONF_OK;
}

/* TODO same as above */
static char *
max_connections_max_queue_length_command (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_upstream_srv_conf_t *uscf =
ngx_http_conf_get_module_srv_conf(cf, ngx_http_upstream_module);

max_connections_srv_conf_t *maxconn_cf =
ngx_http_conf_upstream_srv_conf(uscf, max_connections_module);

ngx_str_t *value = cf->args->elts;
ngx_int_t n = ngx_atoi(value[1].data, value[1].len);
if (n == NGX_ERROR) {
return "invalid number";
}

maxconn_cf->max_queue_length = n;

return NGX_CONF_OK;
}

static char *
max_connections_command (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
Expand Down Expand Up @@ -623,7 +657,6 @@ max_connections_command (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
/* 2. set the number of max_connections */
maxconn_cf->max_connections = (ngx_uint_t)max_connections;
maxconn_cf->queue_length = 0;
maxconn_cf->max_queue_length = MAX_QUEUE_LENGTH;

return NGX_CONF_OK;
}
Expand All @@ -637,7 +670,8 @@ max_connections_create_conf(ngx_conf_t *cf)
if (conf == NULL) return NGX_CONF_ERROR;
max_connections_rr_index = 0;
conf->max_connections = 1;
conf->queue_timeout = 1000; /* default queue timeout 5 seconds */
conf->max_queue_length = 10000; /* default max queue length 10000 */
conf->queue_timeout = 10000; /* default queue timeout 10 seconds */
return conf;
}

4 changes: 4 additions & 0 deletions test/maxconn_test.rb
Expand Up @@ -375,6 +375,10 @@ def queue_timeout
@options[:queue_timeout]
end

def max_queue_length
@options[:max_queue_length]
end

def fail_timeout
@options[:backend_timeouts] || 10
end
Expand Down
3 changes: 3 additions & 0 deletions test/nginx.conf.erb
Expand Up @@ -15,6 +15,9 @@ http {
<% if queue_timeout %>
max_connections_queue_timeout <%= queue_timeout %>;
<% end %>
<% if max_queue_length %>
max_connections_max_queue_length <%= max_queue_length %>;
<% end %>
<% end %>
}

Expand Down

0 comments on commit ca8d6ef

Please sign in to comment.