Skip to content

Commit 01ab731

Browse files
committed
Add configuration options for tuning MapCache connection pool
1 parent 620974e commit 01ab731

File tree

8 files changed

+37
-9
lines changed

8 files changed

+37
-9
lines changed

apache/mod_mapcache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,15 @@ static void mod_mapcache_child_init(apr_pool_t *pool, server_rec *s)
312312
int i,rv;
313313
for(i=0;i<cfg->aliases->nelts;i++) {
314314
mapcache_alias_entry *alias_entry = APR_ARRAY_IDX(cfg->aliases,i,mapcache_alias_entry*);
315-
rv = mapcache_connection_pool_create(&(alias_entry->cp),pool);
315+
rv = mapcache_connection_pool_create(alias_entry->cfg, &(alias_entry->cp),pool);
316316
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);
317317
if(rv!=APR_SUCCESS) {
318318
ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, "failed to create mapcache connection pool");
319319
}
320320
}
321321
for(i=0;i<cfg->quickaliases->nelts;i++) {
322322
mapcache_alias_entry *alias_entry = APR_ARRAY_IDX(cfg->quickaliases,i,mapcache_alias_entry*);
323-
rv = mapcache_connection_pool_create(&(alias_entry->cp),pool);
323+
rv = mapcache_connection_pool_create(alias_entry->cfg, &(alias_entry->cp),pool);
324324
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);
325325
if(rv!=APR_SUCCESS) {
326326
ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, "failed to create mapcache connection pool");

cgi/mapcache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static void load_config(mapcache_context *ctx, char *filename)
210210
apr_pool_destroy(config_pool);
211211
}
212212
config_pool = tmp_config_pool;
213-
mapcache_connection_pool_create(&ctx->connection_pool, config_pool);
213+
mapcache_connection_pool_create(cfg, &ctx->connection_pool, config_pool);
214214

215215
return;
216216

contrib/mapcache_detail/mapcache_detail.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ int main(int argc, char * argv[])
694694
mapcache_context_init(&ctx);
695695
ctx.config = mapcache_configuration_create(ctx.pool);
696696
ctx.log = mapcache_log;
697-
mapcache_connection_pool_create(&ctx.connection_pool, ctx.pool);
697+
mapcache_connection_pool_create(ctx.config, &ctx.connection_pool, ctx.pool);
698698

699699

700700
/////////////////////////////////////////////////////////////////////////////

include/mapcache.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,12 @@ struct mapcache_cfg {
875875
/* return 404 on potentially blocking operations (proxying, source getmaps,
876876
locks on metatile waiting, ... Used for nginx module */
877877
int non_blocking;
878+
879+
// Parameters for connection_pool:
880+
// - cp_hmax defines the maximum number of open connections at the same time
881+
// - cp_ttl defines the maximum amount of time in microseconds an unused connection is valid
882+
int cp_hmax;
883+
int cp_ttl;
878884
};
879885

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

1646-
MS_DLL_EXPORT apr_status_t mapcache_connection_pool_create(mapcache_connection_pool **cp, apr_pool_t *server_pool);
1652+
MS_DLL_EXPORT apr_status_t mapcache_connection_pool_create(mapcache_cfg *cfg, mapcache_connection_pool **cp, apr_pool_t *server_pool);
16471653
mapcache_pooled_connection* mapcache_connection_pool_get_connection(mapcache_context *ctx, char *key,
16481654
mapcache_connection_constructor constructor,
16491655
mapcache_connection_destructor destructor,

lib/configuration_xml.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,28 @@ void mapcache_configuration_parse_xml(mapcache_context *ctx, const char *filenam
12301230
}
12311231
}
12321232

1233+
config->cp_hmax = 1024;
1234+
config->cp_ttl = 60*1000*1000;
1235+
if((node = ezxml_child(doc,"connection_pool")) != NULL) {
1236+
ezxml_t cp_param_node;
1237+
char *endptr;
1238+
if ((cp_param_node = ezxml_child(node,"max_connections")) != NULL) {
1239+
config->cp_hmax = (int)strtol(cp_param_node->txt,&endptr,10);
1240+
if (*endptr != 0 || config->cp_hmax < 0) {
1241+
ctx->set_error(ctx, 400, "failed to parse max_connections %s "
1242+
"(expecting a positive integer)", cp_param_node->txt);
1243+
return;
1244+
}
1245+
}
1246+
if ((cp_param_node = ezxml_child(node,"time_to_live_us")) != NULL) {
1247+
config->cp_ttl = (int)strtol(cp_param_node->txt,&endptr,10);
1248+
if (*endptr != 0 || config->cp_ttl < 0) {
1249+
ctx->set_error(ctx, 400, "failed to parse time_to_live_us %s "
1250+
"(expecting a positive integer)", cp_param_node->txt);
1251+
return;
1252+
}
1253+
}
1254+
}
12331255

12341256
cleanup:
12351257
ezxml_free(doc);

lib/connection_pool.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ static apr_status_t mapcache_connection_container_destructor(void *conn_, void *
7474
}
7575

7676

77-
apr_status_t mapcache_connection_pool_create(mapcache_connection_pool **cp, apr_pool_t *server_pool) {
77+
apr_status_t mapcache_connection_pool_create(mapcache_cfg *cfg, mapcache_connection_pool **cp, apr_pool_t *server_pool) {
7878
apr_status_t rv;
7979
*cp = apr_pcalloc(server_pool, sizeof(mapcache_connection_pool));
8080
(*cp)->server_pool = server_pool;
81-
rv = apr_reslist_create(&((*cp)->connexions), 1, 5, 1024, 60*1000000,
81+
rv = apr_reslist_create(&((*cp)->connexions), 1, 5, cfg->cp_hmax, cfg->cp_ttl,
8282
mapcache_connection_container_creator,
8383
mapcache_connection_container_destructor,
8484
NULL,

nginx/ngx_http_mapcache_module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ ngx_http_mapcache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
300300
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "no mapcache <service>s configured/enabled, no point in continuing.");
301301
return NGX_CONF_ERROR;
302302
}
303-
mapcache_connection_pool_create(&ctx->connection_pool,ctx->pool);
303+
mapcache_connection_pool_create(ctx->config, &ctx->connection_pool,ctx->pool);
304304
ctx->config->non_blocking = 1;
305305

306306
ngx_http_core_loc_conf_t *clcf;

util/mapcache_seed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ int main(int argc, const char **argv)
11201120
mapcache_configuration_post_config(&ctx,cfg);
11211121
if(ctx.get_error(&ctx))
11221122
return usage(argv[0],ctx.get_error_message(&ctx));
1123-
mapcache_connection_pool_create(&ctx.connection_pool, ctx.pool);
1123+
mapcache_connection_pool_create(cfg, &ctx.connection_pool, ctx.pool);
11241124
}
11251125

11261126
#ifdef USE_CLIPPERS

0 commit comments

Comments
 (0)