]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: server: publish UP/DOWN events from STATE change
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 19 Apr 2023 20:34:01 +0000 (22:34 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 5 May 2023 14:28:32 +0000 (16:28 +0200)
Reuse cb_data from STATE event to publish UP and DOWN events.
This saves some CPU time since the event is only constructed
once to publish STATE, STATE+UP or STATE+DOWN depending on the
state change.

src/server.c

index 5bc73ccd57f5490dd917ea7704ebd765ca32f5c4..83faf6b3014762b0854e971a15c069f511d24ccd 100644 (file)
@@ -5349,9 +5349,6 @@ static int _srv_update_status_op(struct server *s, enum srv_op_st_chg_cause caus
                 */
                xferred = pendconn_redistribute(s);
 
-               /* no maintenance + server DOWN: publish event SERVER DOWN */
-               srv_event_hdl_publish(EVENT_HDL_SUB_SERVER_DOWN, s, 0);
-
                tmptrash = alloc_trash_chunk();
                if (tmptrash) {
                        chunk_printf(tmptrash,
@@ -5420,9 +5417,6 @@ static int _srv_update_status_op(struct server *s, enum srv_op_st_chg_cause caus
                 */
                xferred = pendconn_grab_from_px(s);
 
-               /* no maintenance + server going UP: publish event SERVER UP */
-               srv_event_hdl_publish(EVENT_HDL_SUB_SERVER_UP, s, 0);
-
                tmptrash = alloc_trash_chunk();
                if (tmptrash) {
                        chunk_printf(tmptrash,
@@ -5504,9 +5498,6 @@ static int _srv_update_status_adm(struct server *s, enum srv_adm_st_chg_cause ca
                         */
                        xferred = pendconn_redistribute(s);
 
-                       /* maintenance on previously running server: publish event SERVER DOWN */
-                       srv_event_hdl_publish(EVENT_HDL_SUB_SERVER_DOWN, s, 0);
-
                        tmptrash = alloc_trash_chunk();
                        if (tmptrash) {
                                chunk_printf(tmptrash,
@@ -5565,12 +5556,6 @@ static int _srv_update_status_adm(struct server *s, enum srv_adm_st_chg_cause ca
 
                }
 
-               /* ignore if server stays down when leaving maintenance mode */
-               if (s->next_state != SRV_ST_STOPPED) {
-                       /* leaving maintenance + server UP: publish event SERVER UP */
-                       srv_event_hdl_publish(EVENT_HDL_SUB_SERVER_UP, s, 0);
-               }
-
                tmptrash = alloc_trash_chunk();
                if (tmptrash) {
                        if (!(s->next_admin & SRV_ADMF_FMAINT) && (s->cur_admin & SRV_ADMF_FMAINT)) {
@@ -5814,10 +5799,12 @@ static void srv_update_status(struct server *s, int type, int cause)
                        /* server was down and no longer is */
                        if (s->last_change < ns_to_sec(now_ns))                        // ignore negative times
                                s->down_time += ns_to_sec(now_ns) - s->last_change;
+                       _srv_event_hdl_publish(EVENT_HDL_SUB_SERVER_UP, cb_data.common, s);
                }
                else if (s->cur_state == SRV_ST_STOPPED) {
                        /* server was up and is currently down */
                        s->counters.down_trans++;
+                       _srv_event_hdl_publish(EVENT_HDL_SUB_SERVER_DOWN, cb_data.common, s);
                }
                s->last_change = ns_to_sec(now_ns);