]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] session: differenciate between accepted connections and received connections
authorWilly Tarreau <w@1wt.eu>
Fri, 4 Jun 2010 18:59:39 +0000 (20:59 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 14 Jun 2010 08:53:19 +0000 (10:53 +0200)
Now we're able to reject connections very early, so we need to use a
different counter for the connections that are received and the ones
that are accepted and converted into sessions, so that the rate limits
can still apply to the accepted ones. The session rate must still be
used to compute the rate limit, so that we can reject undesired traffic
without affecting the rate.

include/proto/proxy.h
include/types/counters.h
include/types/proxy.h
src/dumpstats.c
src/session.c

index 288ca226a71442fe7ba2c8df47d89832e5605d77..597c03bb011294190ca969bf5df30b95544fe99c 100644 (file)
@@ -68,13 +68,24 @@ static inline void proxy_reset_timeouts(struct proxy *proxy)
        proxy->timeout.check = TICK_ETERNITY;
 }
 
-/* increase the number of cumulated connections on the designated frontend */
-static void inline proxy_inc_fe_ctr(struct listener *l, struct proxy *fe)
+/* increase the number of cumulated connections received on the designated frontend */
+static void inline proxy_inc_fe_conn_ctr(struct listener *l, struct proxy *fe)
 {
        fe->counters.cum_feconn++;
        if (l->counters)
                l->counters->cum_conn++;
 
+       update_freq_ctr(&fe->fe_conn_per_sec, 1);
+       if (fe->fe_conn_per_sec.curr_ctr > fe->counters.fe_cps_max)
+               fe->counters.fe_cps_max = fe->fe_conn_per_sec.curr_ctr;
+}
+
+/* increase the number of cumulated connections accepted by the designated frontend */
+static void inline proxy_inc_fe_sess_ctr(struct listener *l, struct proxy *fe)
+{
+       fe->counters.cum_fesess++;
+       if (l->counters)
+               l->counters->cum_sess++;
        update_freq_ctr(&fe->fe_sess_per_sec, 1);
        if (fe->fe_sess_per_sec.curr_ctr > fe->counters.fe_sps_max)
                fe->counters.fe_sps_max = fe->fe_sess_per_sec.curr_ctr;
index 6e620e186428556259edbba53e13a479a639794e..7a0ff1d3424cee6d60a4d656ce6291853d491dd6 100644 (file)
@@ -26,11 +26,12 @@ struct pxcounters {
        unsigned int feconn_max, beconn_max;    /* max # of active frontend and backend sessions */
 
        long long cum_fe_req;                   /* cumulated number of processed HTTP requests */
-       long long cum_feconn, cum_beconn;       /* cumulated number of processed sessions */
-       long long cum_lbconn;                   /* cumulated number of sessions processed by load balancing */
+       long long cum_feconn, cum_fesess;       /* cumulated number of received/accepted connections */
+       long long cum_beconn, cum_lbconn;       /* cumulated number of sessions processed by load balancing */
 
        unsigned int fe_rps_max;                /* maximum of new sessions per second seen on the frontend */
-       unsigned int fe_sps_max;                /* maximum of new sessions per second seen on the frontend */
+       unsigned int fe_cps_max;                /* maximum of new connections per second received on the frontend */
+       unsigned int fe_sps_max;                /* maximum of new sessions per second accepted on the frontend */
        unsigned int be_sps_max;                /* maximum of new sessions per second seen on the backend */
        unsigned int nbpend_max;                /* max number of pending connections with no server assigned yet */
 
@@ -54,7 +55,8 @@ struct pxcounters {
 struct licounters {
        unsigned int conn_max;                  /* max # of active listener sessions */
 
-       long long cum_conn;                     /* cumulated number of processed sessions */
+       long long cum_conn;                     /* cumulated number of received connections */
+       long long cum_sess;                     /* cumulated number of accepted sessions */
 
        long long bytes_in;                     /* number of bytes transferred from the client to the server */
        long long bytes_out;                    /* number of bytes transferred from the server to the client */
index f7d4e8c33fb1f671f9c56debdfd4feb8997b40d4..aab7b762c57214e1fda8a76f8c88f37ab666dacf 100644 (file)
@@ -229,7 +229,8 @@ struct proxy {
        int totpend;                            /* total number of pending connections on this instance (for stats) */
        unsigned int feconn, beconn;            /* # of active frontend and backends sessions */
        struct freq_ctr fe_req_per_sec;         /* HTTP requests per second on the frontend */
-       struct freq_ctr fe_sess_per_sec;        /* sessions per second on the frontend */
+       struct freq_ctr fe_conn_per_sec;        /* received connections per second on the frontend */
+       struct freq_ctr fe_sess_per_sec;        /* accepted sessions per second on the frontend (after tcp rules) */
        struct freq_ctr be_sess_per_sec;        /* sessions per second on the backend */
        unsigned int maxconn;                   /* max # of active sessions on the frontend */
        unsigned int fe_sps_lim;                /* limit on new sessions per second on the frontend */
index 4f84298116517d34792f657a25b6e3359865eafe..1d1e0ff62245f05707044661eda07a556b3e3f86 100644 (file)
@@ -407,6 +407,7 @@ int stats_sock_parse_request(struct stream_interface *si, char *line)
                                        px->counters.beconn_max = 0;
                                        px->counters.fe_rps_max = 0;
                                        px->counters.fe_sps_max = 0;
+                                       px->counters.fe_cps_max = 0;
                                        px->counters.be_sps_max = 0;
                                        px->counters.nbpend_max = 0;
                                }
@@ -1514,7 +1515,7 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri)
                                     "<td>%s</td><td>%s</td>"
                                     "",
                                     (px->mode == PR_MODE_HTTP)?"<u>":"",
-                                    U2H6(px->counters.cum_feconn),
+                                    U2H6(px->counters.cum_fesess),
                                     (px->mode == PR_MODE_HTTP)?"</u>":"",
                                     U2H7(px->counters.bytes_in), U2H8(px->counters.bytes_out));
 
@@ -1559,7 +1560,7 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri)
                                     /* check_status, check_code, check_duration */
                                     ",,,",
                                     px->id,
-                                    px->feconn, px->counters.feconn_max, px->maxconn, px->counters.cum_feconn,
+                                    px->feconn, px->counters.feconn_max, px->maxconn, px->counters.cum_fesess,
                                     px->counters.bytes_in, px->counters.bytes_out,
                                     px->counters.denied_req, px->counters.denied_resp,
                                     px->counters.failed_req,
index 0ccd9959dfdeedf0a77f7a8adf99c885c01f4302..dcb3fdcdb6091eb7452018e49dccdc0feaa72b1a 100644 (file)
@@ -94,7 +94,7 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
        s->logs.accept_date = date; /* user-visible date for logging */
        s->logs.tv_accept = now;  /* corrected date for internal use */
        s->uniq_id = totalconn;
-       proxy_inc_fe_ctr(l, p); /* note: cum_beconn will be increased once assigned */
+       proxy_inc_fe_conn_ctr(l, p);    /* note: cum_beconn will be increased once assigned */
 
        t->process = l->handler;
        t->context = s;
@@ -124,6 +124,9 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
                return 0;
        }
 
+       /* This session was accepted, count it now */
+       proxy_inc_fe_sess_ctr(l, p);
+
        /* this part should be common with other protocols */
        s->si[0].fd        = cfd;
        s->si[0].owner     = t;