]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] spread checks also when the server is OK.
authorWilly Tarreau <w@1wt.eu>
Sun, 14 Oct 2007 21:47:04 +0000 (23:47 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 15 Oct 2007 07:33:17 +0000 (09:33 +0200)
Initial patch only managed to spread the checks when the checks
failed. The randomization code needs to be added also in the path
where the server is going fine.

src/checks.c

index 57242f11e39078c74e41ec33bd0918487129acd2..cd6bd3007a38a5f1a02783f6c88b3f7613330a18 100644 (file)
@@ -491,8 +491,14 @@ void process_chk(struct task *t, struct timeval *next)
                        }
                        s->curfd = -1; /* no check running anymore */
                        fd_delete(fd);
-                       while (tv_isle(&t->expire, &now))
-                               tv_ms_add(&t->expire, &t->expire, s->inter);
+
+                       rv = 0;
+                       if (global.spread_checks > 0) {
+                               rv = s->inter * global.spread_checks / 100;
+                               rv -= (int) (2 * rv * (rand() / (RAND_MAX + 1.0)));
+                               //fprintf(stderr, "process_chk(%p): (%d+/-%d%%) random=%d\n", s, s->inter, global.spread_checks, rv);
+                       }
+                       tv_ms_add(&t->expire, &now, s->inter + rv);
                        goto new_chk;
                }
                else if (s->result < 0 || tv_isle(&t->expire, &now)) {
@@ -511,10 +517,9 @@ void process_chk(struct task *t, struct timeval *next)
                        if (global.spread_checks > 0) {
                                rv = s->inter * global.spread_checks / 100;
                                rv -= (int) (2 * rv * (rand() / (RAND_MAX + 1.0)));
-                               //fprintf(stderr, "process_chk: (%d+/-%d%%) random=%d\n", s->inter, global.spread_checks, rv);
+                               //fprintf(stderr, "process_chk(%p): (%d+/-%d%%) random=%d\n", s, s->inter, global.spread_checks, rv);
                        }
-                       while (tv_isle(&t->expire, &now))
-                               tv_ms_add(&t->expire, &t->expire, s->inter + rv);
+                       tv_ms_add(&t->expire, &now, s->inter + rv);
                        goto new_chk;
                }
                /* if result is 0 and there's no timeout, we have to wait again */