MEDIUM: stream-int: do not allocate a connection in parallel to applets

When we know we're not going to use a connection on a stream interface
because we're using an applet instead, do not allocate a connection, or
release the preallocated one. We do that for peers and CLI only at the
moment, and not for HTTP stats which in the future might be adapted to
support keep-alive.

The connection pointer is simply set to NULL, which pool_free2() already
supports.
This commit is contained in:
Willy Tarreau 2013-10-01 17:12:05 +02:00
parent b363a1f469
commit ce9dbcd9ea
2 changed files with 13 additions and 14 deletions

View File

@ -156,7 +156,12 @@ extern const char *stat_status_codes[];
*/ */
static int stats_accept(struct session *s) static int stats_accept(struct session *s)
{ {
/* we have a dedicated I/O handler for the stats */ /* we have a dedicated I/O handler for the CLI/stats, so we can safely
* release the pre-allocated connection that we will never use.
*/
pool_free2(pool2_connection, s->si[1].conn);
s->si[1].conn = NULL;
stream_int_register_handler(&s->si[1], &cli_applet); stream_int_register_handler(&s->si[1], &cli_applet);
s->target = &cli_applet.obj_type; // for logging only s->target = &cli_applet.obj_type; // for logging only
s->si[1].appctx.st1 = 0; s->si[1].appctx.st1 = 0;

View File

@ -1083,7 +1083,12 @@ static void peer_session_forceshutdown(struct session * session)
*/ */
int peer_accept(struct session *s) int peer_accept(struct session *s)
{ {
/* we have a dedicated I/O handler for the stats */ /* we have a dedicated I/O handler for the peers, so we can safely
* release the pre-allocated connection that we will never use.
*/
pool_free2(pool2_connection, s->si[1].conn);
s->si[1].conn = NULL;
stream_int_register_handler(&s->si[1], &peer_applet); stream_int_register_handler(&s->si[1], &peer_applet);
s->target = &peer_applet.obj_type; // for logging only s->target = &peer_applet.obj_type; // for logging only
s->si[1].appctx.ctx.peers.ptr = s; s->si[1].appctx.ctx.peers.ptr = s;
@ -1123,9 +1128,6 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
goto out_close; goto out_close;
} }
if (unlikely((s->si[0].conn = pool_alloc2(pool2_connection)) == NULL))
goto out_fail_conn0;
if (unlikely((s->si[1].conn = pool_alloc2(pool2_connection)) == NULL)) if (unlikely((s->si[1].conn = pool_alloc2(pool2_connection)) == NULL))
goto out_fail_conn1; goto out_fail_conn1;
@ -1161,13 +1163,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
s->req = s->rep = NULL; /* will be allocated later */ s->req = s->rep = NULL; /* will be allocated later */
/* si[0] is the applet, we should not need s->si[0].conn anymore soon */ s->si[0].conn = NULL;
s->si[0].conn->obj_type = OBJ_TYPE_CONN;
s->si[0].conn->t.sock.fd = -1;
s->si[0].conn->flags = CO_FL_NONE;
s->si[0].conn->err_code = CO_ER_NONE;
s->si[0].conn->target = &l->obj_type;
s->si[0].owner = t; s->si[0].owner = t;
s->si[0].state = s->si[0].prev_state = SI_ST_EST; s->si[0].state = s->si[0].prev_state = SI_ST_EST;
s->si[0].err_type = SI_ET_NONE; s->si[0].err_type = SI_ET_NONE;
@ -1319,8 +1315,6 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
LIST_DEL(&s->list); LIST_DEL(&s->list);
pool_free2(pool2_connection, s->si[1].conn); pool_free2(pool2_connection, s->si[1].conn);
out_fail_conn1: out_fail_conn1:
pool_free2(pool2_connection, s->si[0].conn);
out_fail_conn0:
pool_free2(pool2_session, s); pool_free2(pool2_session, s);
out_close: out_close:
return s; return s;