MEDIUM: session: count the frontend's connections at a single place
authorWilly Tarreau <w@1wt.eu>
Fri, 15 Sep 2017 08:25:14 +0000 (10:25 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 15 Sep 2017 09:49:52 +0000 (11:49 +0200)
There are several places where we see feconn++, feconn--, totalconn++ and
an increment on the frontend's number of connections and connection rate.
This is done exactly once per session in each direction, so better take
care of this counter in the session and simplify the callers. At least it
ensures a better symmetry. It also ensures consistency as till now the
lua/spoe/peers frontend didn't have these counters properly set, which can
be useful at least for troubleshooting.

src/flt_spoe.c
src/hlua.c
src/listener.c
src/peers.c
src/session.c
src/stream.c

index f278809..2d62e5a 100644 (file)
@@ -1948,9 +1948,6 @@ spoe_create_appctx(struct spoe_config *conf)
        strm->do_log = NULL;
        strm->res.flags |= CF_READ_DONTWAIT;
 
-       conf->agent_fe.feconn++;
-       totalconn++;
-
        task_wakeup(SPOE_APPCTX(appctx)->task, TASK_WOKEN_INIT);
        LIST_ADDQ(&conf->agent->applets, &SPOE_APPCTX(appctx)->list);
        conf->agent->applets_act++;
index e1b7264..c68495b 100644 (file)
@@ -2413,10 +2413,6 @@ __LJMP static int hlua_socket_new(lua_State *L)
        strm->flags |= SF_DIRECT | SF_ASSIGNED | SF_ADDR_SET | SF_BE_ASSIGNED;
        strm->target = &socket_tcp.obj_type;
 
-       /* Update statistics counters. */
-       socket_proxy.feconn++; /* beconn will be increased later */
-       totalconn++;
-
        task_wakeup(strm->task, TASK_WOKEN_INIT);
        /* Return yield waiting for connection. */
        return 1;
index e6f89f9..a7e2b0d 100644 (file)
@@ -527,7 +527,6 @@ void listener_accept(int fd)
                        actconn++;
                }
 
-               totalconn++;
                l->nbconn++;
 
                if (l->counters) {
index 17f1867..f63589d 100644 (file)
@@ -1835,9 +1835,6 @@ static struct appctx *peer_session_create(struct peers *peers, struct peer *peer
 
        s->res.flags |= CF_READ_DONTWAIT;
 
-       p->feconn++;/* beconn will be increased later */
-       totalconn++;
-
        peer->appctx = appctx;
        task_wakeup(s->task, TASK_WOKEN_INIT);
        return appctx;
index 98d7e2c..08c3c62 100644 (file)
@@ -36,7 +36,7 @@ static struct task *session_expire_embryonic(struct task *t);
 /* Create a a new session and assign it to frontend <fe>, listener <li>,
  * origin <origin>, set the current date and clear the stick counters pointers.
  * Returns the session upon success or NULL. The session may be released using
- * session_free().
+ * session_free(). Note: <li> may be NULL.
  */
 struct session *session_new(struct proxy *fe, struct listener *li, enum obj_type *origin)
 {
@@ -53,6 +53,12 @@ struct session *session_new(struct proxy *fe, struct listener *li, enum obj_type
                memset(sess->stkctr, 0, sizeof(sess->stkctr));
                vars_init(&sess->vars, SCOPE_SESS);
                sess->task = NULL;
+               fe->feconn++;
+               if (fe->feconn > fe->fe_counters.conn_max)
+                       fe->fe_counters.conn_max = fe->feconn;
+               if (li)
+                       proxy_inc_fe_conn_ctr(li, fe);
+               totalconn++;
                jobs++;
        }
        return sess;
@@ -62,6 +68,7 @@ void session_free(struct session *sess)
 {
        if (!LIST_ISEMPTY(&sess->streams))
                return;
+       sess->fe->feconn--;
        session_store_counters(sess);
        vars_prune_per_sess(&sess->vars);
        pool_free2(pool2_session, sess);
@@ -153,13 +160,6 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr
 
        conn_set_owner(cli_conn, sess);
 
-       p->feconn++;
-       /* This session was accepted, count it now */
-       if (p->feconn > p->fe_counters.conn_max)
-               p->fe_counters.conn_max = p->feconn;
-
-       proxy_inc_fe_conn_ctr(l, p);
-
        /* now evaluate the tcp-request layer4 rules. We only need a session
         * and no stream for these rules.
         */
@@ -265,7 +265,6 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr
 
        /* error unrolling */
  out_free_sess:
-       p->feconn--;
        session_free(sess);
  out_free_conn:
        cli_conn->flags &= ~CO_FL_XPRT_TRACKED;
@@ -365,7 +364,6 @@ static void session_kill_embryonic(struct session *sess)
        conn_force_close(conn);
        conn_free(conn);
 
-       sess->fe->feconn--;
        listener_release(sess->listener);
 
        task_delete(task);
index 5489f11..355f8d8 100644 (file)
@@ -2417,7 +2417,6 @@ struct task *process_stream(struct task *t)
                return t; /* nothing more to do */
        }
 
-       sess->fe->feconn--;
        if (s->flags & SF_BE_ASSIGNED)
                s->be->beconn--;