diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-11-03 11:41:07 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-11-03 11:41:07 +0000 |
commit | f8971ca2d4dc37d518cba76fc31e5473d41a1754 (patch) | |
tree | c041b90991e0ee95560b9369f4c7e19d01fd26df /src/libutil/upstream.c | |
parent | c23a4b69e84bd77c4d589e8d7500c28b21e37fce (diff) | |
download | rspamd-f8971ca2d4dc37d518cba76fc31e5473d41a1754.tar.gz rspamd-f8971ca2d4dc37d518cba76fc31e5473d41a1754.zip |
Improve upstream tests.
Diffstat (limited to 'src/libutil/upstream.c')
-rw-r--r-- | src/libutil/upstream.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c index 010b2d0ff..7bec3729a 100644 --- a/src/libutil/upstream.c +++ b/src/libutil/upstream.c @@ -260,7 +260,6 @@ rspamd_upstream_fail (struct upstream *up) rspamd_mutex_lock (up->lock); if (g_atomic_int_compare_and_exchange (&up->errors, 0, 1)) { gettimeofday (&up->tv, NULL); - up->errors ++; } else { g_atomic_int_inc (&up->errors); @@ -270,9 +269,15 @@ rspamd_upstream_fail (struct upstream *up) msec_last = tv_to_msec (&up->tv) / 1000.; msec_cur = tv_to_msec (&tv) / 1000.; - if (msec_cur > msec_last) { - error_rate = ((gdouble)up->errors) / (msec_cur - msec_last); - max_error_rate = (gdouble)default_max_errors / (gdouble)default_error_time; + if (msec_cur >= msec_last) { + if (msec_cur > msec_last) { + error_rate = ((gdouble)up->errors) / (msec_cur - msec_last); + max_error_rate = (gdouble)default_max_errors / default_error_time; + } + else { + error_rate = 1; + max_error_rate = 0; + } if (error_rate > max_error_rate) { /* Remove upstream from the active list */ |