[PATCH] [CRITICAL] fix server state tracking: it was O(n!) instead of O(n)

From: Krzysztof Piotr Oledzki <ole#ans.pl>
Date: Fri, 30 Jan 2009 01:38:38 +0100


From 9bb0f6085163991924d99b7c7ff8000ade0ce0b6 Mon Sep 17 00:00:00 2001 From: Krzysztof Piotr Oledzki <ole#ans.pl> Date: Fri, 30 Jan 2009 00:52:49 +0100
Subject: [CRITICAL] fix server state tracking: it was O(n!) instead of O(n)

Using the wrong operator (&& instead of &) causes DOWN->UP transition to take longer than it should and to produce a lot of redundant logs. With typical "track" usage (1-6 tracking servers) it shouldn't make a big difference but for heavily tracked servers this bug leads to hang with 100% CPU usage and extremely big log spam.

---
 src/checks.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/checks.c b/src/checks.c
index d6ce335..ec21e42 100644
--- a/src/checks.c
+++ b/src/checks.c

@@ -161,7 +161,7 @@ static void set_server_down(struct server *s)
s->down_trans++; - if (s->state && SRV_CHECKED) + if (s->state & SRV_CHECKED) for(srv = s->tracknext; srv; srv = srv->tracknext) set_server_down(srv); }
@@ -226,7 +226,7 @@ static void set_server_up(struct server *s) {
Warning("%s", trash); send_log(s->proxy, LOG_NOTICE, "%s", trash); - if (s->state && SRV_CHECKED) + if (s->state & SRV_CHECKED) for(srv = s->tracknext; srv; srv = srv->tracknext) set_server_up(srv); }
@@ -277,7 +277,7 @@ static void set_server_disabled(struct server *s) {
if (!s->proxy->srv_bck && !s->proxy->srv_act) set_backend_down(s->proxy); - if (s->state && SRV_CHECKED) + if (s->state & SRV_CHECKED) for(srv = s->tracknext; srv; srv = srv->tracknext) set_server_disabled(srv); }
@@ -317,7 +317,7 @@ static void set_server_enabled(struct server *s) {
Warning("%s", trash); send_log(s->proxy, LOG_NOTICE, "%s", trash); - if (s->state && SRV_CHECKED) + if (s->state & SRV_CHECKED) for(srv = s->tracknext; srv; srv = srv->tracknext) set_server_enabled(srv); } -- 1.6.0.4
Received on 2009/01/30 01:38

This archive was generated by hypermail 2.2.0 : 2009/01/30 01:45 CET