This will allow lb_chash to determine the total active sessions for a
proxy without any computation.

Signed-off-by: Andrew Rodland <andr...@vimeo.com>
---
 include/types/proxy.h | 1 +
 src/queue.c           | 1 +
 src/stream.c          | 2 ++
 3 files changed, 4 insertions(+)

diff --git a/include/types/proxy.h b/include/types/proxy.h
index 2f4f9b9..028b3a7 100644
--- a/include/types/proxy.h
+++ b/include/types/proxy.h
@@ -277,6 +277,7 @@ struct proxy {
        } tcp_rep;
        struct server *srv, defsrv;             /* known servers; default 
server configuration */
        int srv_act, srv_bck;                   /* # of servers eligible for LB 
(UP|!checked) AND (enabled+weight!=0) */
+       int served;                             /* # of active sessions 
currently being served */
        struct lbprm lbprm;                     /* load-balancing parameters */
        char *cookie_domain;                    /* domain used to insert the 
cookie */
        char *cookie_name;                      /* name of the cookie to look 
for */
diff --git a/src/queue.c b/src/queue.c
index 1f27c49..08a6c3d 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -126,6 +126,7 @@ struct stream *pendconn_get_next_strm(struct server *srv, 
struct proxy *px)
        strm->target = &srv->obj_type;
        stream_add_srv_conn(strm, srv);
        srv->served++;
+       srv->proxy->served++;
        if (px->lbprm.server_take_conn)
                px->lbprm.server_take_conn(srv);
 
diff --git a/src/stream.c b/src/stream.c
index 151bcb0..738a23c 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -2515,6 +2515,7 @@ void sess_change_server(struct stream *sess, struct 
server *newsrv)
 
        if (sess->srv_conn) {
                sess->srv_conn->served--;
+               sess->srv_conn->proxy->served--;
                if (sess->srv_conn->proxy->lbprm.server_drop_conn)
                        
sess->srv_conn->proxy->lbprm.server_drop_conn(sess->srv_conn);
                stream_del_srv_conn(sess);
@@ -2522,6 +2523,7 @@ void sess_change_server(struct stream *sess, struct 
server *newsrv)
 
        if (newsrv) {
                newsrv->served++;
+               newsrv->proxy->served++;
                if (newsrv->proxy->lbprm.server_take_conn)
                        newsrv->proxy->lbprm.server_take_conn(newsrv);
                stream_add_srv_conn(sess, newsrv);
-- 
2.9.3


Reply via email to