]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: session: maintain the session count stats in the session, not the stream
authorWilly Tarreau <w@1wt.eu>
Wed, 8 Apr 2015 16:10:49 +0000 (18:10 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 8 Apr 2015 16:10:49 +0000 (18:10 +0200)
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.

src/session.c
src/stream.c

index 6ae2592fe1b049127da978f12abbeb3436a3ea73..604bfa97c5651c6b0a0fe413d73fd9916fe2ffe6 100644 (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)
index 863075b0ba4c9a722cf4b3742aed05bd1d69c1de..9663747e1f08ec59828b5e0661e254a0f01de06e 100644 (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);