Browse Source

[core] allocate initial request pool w/ srv->conns

allocate reusable h2 request pool when initial srv->conns pool allocated
master
Glenn Strauss 6 months ago
parent
commit
4ccd86f981
  1. 31
      src/connections.c
  2. 10
      src/reqpool.c
  3. 2
      src/reqpool.h
  4. 2
      src/server.c

31
src/connections.c

@ -47,21 +47,30 @@ static connection *connection_init(server *srv);
static void connection_reset(connection *con);
__attribute_cold__
__attribute_noinline__
static void connections_extend(server * const srv, connections * const conns) {
const uint32_t n = (srv->max_conns >= 128 && conns->size >= 16)
? (0 != conns->size) ? 128 : 128 - 16
: (srv->max_conns > 16) ? 16 : srv->max_conns;
if (conns->size < 128 && srv->srvconf.h2proto)
request_pool_extend(srv, n * 8);
conns->size += n;
conns->ptr = realloc(conns->ptr, sizeof(*conns->ptr) * conns->size);
force_assert(NULL != conns->ptr);
for (uint32_t i = conns->used; i < conns->size; ++i) {
conns->ptr[i] = connection_init(srv);
connection_reset(conns->ptr[i]);
}
}
static connection *connections_get_new_connection(server *srv) {
connections * const conns = &srv->conns;
size_t i;
if (conns->size == conns->used) {
conns->size += srv->max_conns >= 128 ? 128 : srv->max_conns > 16 ? 16 : srv->max_conns;
conns->ptr = realloc(conns->ptr, sizeof(*conns->ptr) * conns->size);
force_assert(NULL != conns->ptr);
for (i = conns->used; i < conns->size; i++) {
conns->ptr[i] = connection_init(srv);
connection_reset(conns->ptr[i]);
}
}
if (conns->size == conns->used)
connections_extend(srv, conns);
conns->ptr[conns->used]->ndx = conns->used;
return conns->ptr[conns->used++];

10
src/reqpool.c

@ -235,9 +235,15 @@ static uint32_t reqspace;
void
request_pool_init (uint32_t sz)
request_pool_extend (server *srv, const uint32_t sz)
{
reqspace = sz;
for (uint32_t i = 0; i < sz; ++i) {
request_st * const x = calloc(1, sizeof(request_st));
force_assert(x);
request_init_data(x, NULL, srv);
x->con = (connection *)reqpool; /*(reuse r->con as next ptr)*/
reqpool = x;
}
}

2
src/reqpool.h

@ -23,7 +23,7 @@ __attribute_cold__
void request_free_data (request_st *r);
__attribute_cold__
void request_pool_init (uint32_t sz);
void request_pool_extend (server *srv, uint32_t sz);
__attribute_cold__
void request_pool_free (void);

2
src/server.c

@ -1731,8 +1731,6 @@ static int server_main_setup (server * const srv, int argc, char **argv) {
srv->max_conns = srv->max_fds/3;
}
request_pool_init(srv->max_conns);
/* libev backend overwrites our SIGCHLD handler and calls waitpid on SIGCHLD; we want our own SIGCHLD handling. */
#ifdef HAVE_SIGACTION
sigaction(SIGCHLD, &act, NULL);

Loading…
Cancel
Save