Add pgsql_conn_max configuration parameter.

Allows you to tune how many pgsql connections kore
will make at one time.
This commit is contained in:
Joris Vink 2014-07-04 09:14:05 +02:00
parent 8b20dec081
commit 1ad9f039ab
4 changed files with 45 additions and 2 deletions

View File

@ -26,7 +26,8 @@ struct kore_pgsql {
void *conn;
};
extern char *pgsql_conn_string;
extern u_int16_t pgsql_conn_max;
extern char *pgsql_conn_string;
void kore_pgsql_init(void);
void kore_pgsql_handle(void *, int);

View File

@ -24,6 +24,10 @@
#include "kore.h"
#include "http.h"
#if defined(KORE_USE_PGSQL)
#include "pgsql.h"
#endif
/* XXX - This is becoming a clusterfuck. Fix it. */
static int configure_include(char **);
@ -60,6 +64,10 @@ static int configure_authentication_type(char **);
static int configure_authentication_value(char **);
static int configure_authentication_validator(char **);
#if defined(KORE_USE_PGSQL)
static int configure_pgsql_conn_max(char **);
#endif
static void domain_sslstart(void);
static void kore_parse_config_file(char *);
@ -101,6 +109,9 @@ static struct {
{ "authentication_type", configure_authentication_type },
{ "authentication_value", configure_authentication_value },
{ "authentication_validator", configure_authentication_validator },
#if defined(KORE_USE_PGSQL)
{ "pgsql_conn_max", configure_pgsql_conn_max },
#endif
{ NULL, NULL },
};
@ -907,3 +918,26 @@ domain_sslstart(void)
kore_domain_sslstart(current_domain);
current_domain = NULL;
}
#if defined(KORE_USE_PGSQL)
static int
configure_pgsql_conn_max(char **argv)
{
int err;
if (argv[1] == NULL) {
printf("missing parameter for pgsql_conn_max\n");
return (KORE_RESULT_ERROR);
}
pgsql_conn_max = kore_strtonum(argv[1], 10, 0, USHRT_MAX, &err);
if (err != KORE_RESULT_OK) {
printf("bad value for pgsql_conn_max: %s\n", argv[1]);
return (KORE_RESULT_ERROR);
}
return (KORE_RESULT_OK);
}
#endif

View File

@ -246,6 +246,13 @@ kore_server_start(void)
kore_write_kore_pid();
kore_log(LOG_NOTICE, "kore is starting up");
#if defined(KORE_USE_PGSQL)
kore_log(LOG_NOTICE, "pgsql built-in enabled");
#endif
#if defined(KORE_USE_TASKS)
kore_log(LOG_NOTICE, "tasks built-in enabled");
#endif
kore_platform_proctitle("kore [parent]");
kore_worker_init();

View File

@ -53,6 +53,7 @@ static void pgsql_read_result(struct http_request *, int,
static TAILQ_HEAD(, pgsql_conn) pgsql_conn_free;
static u_int16_t pgsql_conn_count;
char *pgsql_conn_string = NULL;
u_int16_t pgsql_conn_max = PGSQL_CONN_MAX;
void
kore_pgsql_init(void)
@ -73,7 +74,7 @@ kore_pgsql_query(struct http_request *req, char *query, int idx)
fatal("kore_pgsql_query: %d already exists", idx);
if (TAILQ_EMPTY(&pgsql_conn_free)) {
if (pgsql_conn_count >= PGSQL_CONN_MAX)
if (pgsql_conn_count >= pgsql_conn_max)
return (KORE_RESULT_ERROR);
}