Skip to content
Permalink
Browse files

Add configuration options for tuning MapCache connection pool

  • Loading branch information
jbo-ads committed Dec 13, 2019
1 parent 620974e commit 01ab731e0b1cc7d77156a0ec553d82b7480cc3e5
@@ -312,15 +312,15 @@ static void mod_mapcache_child_init(apr_pool_t *pool, server_rec *s)
int i,rv;
for(i=0;i<cfg->aliases->nelts;i++) {
mapcache_alias_entry *alias_entry = APR_ARRAY_IDX(cfg->aliases,i,mapcache_alias_entry*);
rv = mapcache_connection_pool_create(&(alias_entry->cp),pool);
rv = mapcache_connection_pool_create(alias_entry->cfg, &(alias_entry->cp),pool);
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "creating a child process mapcache connection pool on server %s for alias %s", s->server_hostname, alias_entry->endpoint);
if(rv!=APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, "failed to create mapcache connection pool");
}
}
for(i=0;i<cfg->quickaliases->nelts;i++) {
mapcache_alias_entry *alias_entry = APR_ARRAY_IDX(cfg->quickaliases,i,mapcache_alias_entry*);
rv = mapcache_connection_pool_create(&(alias_entry->cp),pool);
rv = mapcache_connection_pool_create(alias_entry->cfg, &(alias_entry->cp),pool);
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "creating a child process mapcache connection pool on server %s for alias %s", s->server_hostname, alias_entry->endpoint);
if(rv!=APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, "failed to create mapcache connection pool");
@@ -210,7 +210,7 @@ static void load_config(mapcache_context *ctx, char *filename)
apr_pool_destroy(config_pool);
}
config_pool = tmp_config_pool;
mapcache_connection_pool_create(&ctx->connection_pool, config_pool);
mapcache_connection_pool_create(cfg, &ctx->connection_pool, config_pool);

return;

@@ -694,7 +694,7 @@ int main(int argc, char * argv[])
mapcache_context_init(&ctx);
ctx.config = mapcache_configuration_create(ctx.pool);
ctx.log = mapcache_log;
mapcache_connection_pool_create(&ctx.connection_pool, ctx.pool);
mapcache_connection_pool_create(ctx.config, &ctx.connection_pool, ctx.pool);


/////////////////////////////////////////////////////////////////////////////
@@ -875,6 +875,12 @@ struct mapcache_cfg {
/* return 404 on potentially blocking operations (proxying, source getmaps,
locks on metatile waiting, ... Used for nginx module */
int non_blocking;

// Parameters for connection_pool:
// - cp_hmax defines the maximum number of open connections at the same time
// - cp_ttl defines the maximum amount of time in microseconds an unused connection is valid
int cp_hmax;
int cp_ttl;
};

/**
@@ -1643,7 +1649,7 @@ struct mapcache_pooled_connection {
typedef void (*mapcache_connection_constructor)(mapcache_context *ctx, void **connection, void *params);
typedef void (*mapcache_connection_destructor)(void *connection);

MS_DLL_EXPORT apr_status_t mapcache_connection_pool_create(mapcache_connection_pool **cp, apr_pool_t *server_pool);
MS_DLL_EXPORT apr_status_t mapcache_connection_pool_create(mapcache_cfg *cfg, mapcache_connection_pool **cp, apr_pool_t *server_pool);
mapcache_pooled_connection* mapcache_connection_pool_get_connection(mapcache_context *ctx, char *key,
mapcache_connection_constructor constructor,
mapcache_connection_destructor destructor,
@@ -1230,6 +1230,28 @@ void mapcache_configuration_parse_xml(mapcache_context *ctx, const char *filenam
}
}

config->cp_hmax = 1024;
config->cp_ttl = 60*1000*1000;
if((node = ezxml_child(doc,"connection_pool")) != NULL) {
ezxml_t cp_param_node;
char *endptr;
if ((cp_param_node = ezxml_child(node,"max_connections")) != NULL) {
config->cp_hmax = (int)strtol(cp_param_node->txt,&endptr,10);
if (*endptr != 0 || config->cp_hmax < 0) {
ctx->set_error(ctx, 400, "failed to parse max_connections %s "
"(expecting a positive integer)", cp_param_node->txt);
return;
}
}
if ((cp_param_node = ezxml_child(node,"time_to_live_us")) != NULL) {
config->cp_ttl = (int)strtol(cp_param_node->txt,&endptr,10);
if (*endptr != 0 || config->cp_ttl < 0) {
ctx->set_error(ctx, 400, "failed to parse time_to_live_us %s "
"(expecting a positive integer)", cp_param_node->txt);
return;
}
}
}

cleanup:
ezxml_free(doc);
@@ -74,11 +74,11 @@ static apr_status_t mapcache_connection_container_destructor(void *conn_, void *
}


apr_status_t mapcache_connection_pool_create(mapcache_connection_pool **cp, apr_pool_t *server_pool) {
apr_status_t mapcache_connection_pool_create(mapcache_cfg *cfg, mapcache_connection_pool **cp, apr_pool_t *server_pool) {
apr_status_t rv;
*cp = apr_pcalloc(server_pool, sizeof(mapcache_connection_pool));
(*cp)->server_pool = server_pool;
rv = apr_reslist_create(&((*cp)->connexions), 1, 5, 1024, 60*1000000,
rv = apr_reslist_create(&((*cp)->connexions), 1, 5, cfg->cp_hmax, cfg->cp_ttl,
mapcache_connection_container_creator,
mapcache_connection_container_destructor,
NULL,
@@ -300,7 +300,7 @@ ngx_http_mapcache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "no mapcache <service>s configured/enabled, no point in continuing.");
return NGX_CONF_ERROR;
}
mapcache_connection_pool_create(&ctx->connection_pool,ctx->pool);
mapcache_connection_pool_create(ctx->config, &ctx->connection_pool,ctx->pool);
ctx->config->non_blocking = 1;

ngx_http_core_loc_conf_t *clcf;
@@ -1120,7 +1120,7 @@ int main(int argc, const char **argv)
mapcache_configuration_post_config(&ctx,cfg);
if(ctx.get_error(&ctx))
return usage(argv[0],ctx.get_error_message(&ctx));
mapcache_connection_pool_create(&ctx.connection_pool, ctx.pool);
mapcache_connection_pool_create(cfg, &ctx.connection_pool, ctx.pool);
}

#ifdef USE_CLIPPERS

0 comments on commit 01ab731

Please sign in to comment.
You can’t perform that action at this time.