From f39c71c98174e0691c048ed4935b045ea64f93e4 Mon Sep 17 00:00:00 2001 From: Krzysztof Piotr Oledzki Date: Fri, 30 Jan 2009 00:52:49 +0100 Subject: [PATCH] [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 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/checks.c b/src/checks.c index eb316cbb6..1acff0d84 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); }