MINOR: session: maintain the session count stats in the session, not the stream

This has nothing to do in the stream, as we'll face absurdities when chaining
multiple streams. The session is where it must be accounted for.
This commit is contained in:
Willy Tarreau 2015-04-08 18:10:49 +02:00
parent 1b90511eeb
commit 042cd75bc2
2 changed files with 28 additions and 22 deletions

View File

@ -76,6 +76,31 @@ int init_session()
return pool2_session != NULL;
}
/* count a new session to keep frontend, listener and track stats up to date */
static void session_count_new(struct session *sess)
{
struct stkctr *stkctr;
void *ptr;
int i;
proxy_inc_fe_sess_ctr(sess->listener, sess->fe);
for (i = 0; i < MAX_SESS_STKCTR; i++) {
stkctr = &sess->stkctr[i];
if (!stkctr_entry(stkctr))
continue;
ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_CNT);
if (ptr)
stktable_data_cast(ptr, sess_cnt)++;
ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_RATE);
if (ptr)
update_freq_ctr_period(&stktable_data_cast(ptr, sess_rate),
stkctr->table->data_arg[STKTABLE_DT_SESS_RATE].u, 1);
}
}
/* This function is called from the protocol layer accept() in order to
* instanciate a new session on behalf of a given listener and frontend. It
* returns a positive value upon success, 0 if the connection can be ignored,
@ -225,6 +250,8 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr
/* OK let's complete stream initialization since there is no handshake */
cli_conn->flags |= CO_FL_CONNECTED;
session_count_new(sess);
strm = stream_new(sess, t);
if (!strm)
goto out_free_task;
@ -381,6 +408,7 @@ static int conn_complete_session(struct connection *conn)
if (conn->flags & CO_FL_ERROR)
goto fail;
session_count_new(sess);
task->process = sess->listener->handler;
strm = stream_new(sess, task);
if (!strm)

View File

@ -69,7 +69,6 @@ struct stream *stream_new(struct session *sess, struct task *t)
struct stream *s;
struct connection *conn = objt_conn(sess->origin);
struct appctx *appctx = objt_appctx(sess->origin);
int i;
if (unlikely((s = pool_alloc2(pool2_stream)) == NULL))
return s;
@ -136,27 +135,6 @@ struct stream *stream_new(struct session *sess, struct task *t)
s->req_cap = NULL;
s->res_cap = NULL;
/* Let's count a stream now */
if (conn)
proxy_inc_fe_sess_ctr(sess->listener, sess->fe);
for (i = 0; i < MAX_SESS_STKCTR; i++) {
void *ptr;
struct stkctr *stkctr = &sess->stkctr[i];
if (!stkctr_entry(stkctr))
continue;
ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_CNT);
if (ptr)
stktable_data_cast(ptr, sess_cnt)++;
ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_RATE);
if (ptr)
update_freq_ctr_period(&stktable_data_cast(ptr, sess_rate),
stkctr->table->data_arg[STKTABLE_DT_SESS_RATE].u, 1);
}
/* this part should be common with other protocols */
si_reset(&s->si[0]);
si_set_state(&s->si[0], SI_ST_EST);