diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-06-23 14:15:20 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-06-23 14:15:20 +0100 |
commit | 641e14aa8ff46fc0448f69d409266bba2053ddf4 (patch) | |
tree | 047f3d9d68fb126f1073ba26e65005f1958ea099 | |
parent | 39c042ebd020639cc3a00434bbad97697d900e95 (diff) | |
download | rspamd-641e14aa8ff46fc0448f69d409266bba2053ddf4.tar.gz rspamd-641e14aa8ff46fc0448f69d409266bba2053ddf4.zip |
[Fix] Fix errors counting in upstreams
-rw-r--r-- | src/libutil/upstream.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c index 2aa27d929..e8bf1a19c 100644 --- a/src/libutil/upstream.c +++ b/src/libutil/upstream.c @@ -372,7 +372,7 @@ rspamd_upstream_fail (struct upstream *up) { struct timeval tv; gdouble error_rate, max_error_rate; - gint msec_last, msec_cur; + gdouble sec_last, sec_cur; struct upstream_addr_elt *addr_elt; gettimeofday (&tv, NULL); @@ -384,11 +384,14 @@ rspamd_upstream_fail (struct upstream *up) up->errors = 1; } else if (up->active_idx != -1) { - msec_last = tv_to_msec (&up->tv) / 1000.; - msec_cur = tv_to_msec (&tv) / 1000.; - if (msec_cur >= msec_last) { - if (msec_cur > msec_last) { - error_rate = ((gdouble)up->errors) / (msec_cur - msec_last); + sec_last = tv_to_double (&up->tv); + sec_cur = tv_to_double (&tv); + + if (sec_cur >= sec_last) { + up->errors ++; + + if (sec_cur > sec_last) { + error_rate = ((gdouble)up->errors) / (sec_cur - sec_last); max_error_rate = ((gdouble)up->ctx->max_errors) / up->ctx->error_time; } else { |