streaming rate limiting recalc
Costa Tsaousis (ktsaou) committed
Jul 6, 2018 at 20:28 UTC
ff3c0f509726048ee8f767da49957d2bcf9c4ca8
1 file changed
+5
-3
src/rrdpush.c
+5
-3
@@ -1122,15 +1122,17 @@ int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url
1122
{
1123
static netdata_mutex_t stream_rate_mutex = NETDATA_MUTEX_INITIALIZER;
1124
static volatile time_t last_stream_accepted_t = 0;
1125
- time_t now = now_realtime_sec();
1125
1126
netdata_mutex_lock(&stream_rate_mutex);
1127
+ time_t now = now_realtime_sec();
1128
+ time_t rate_t = 10;
1129
+
1130
if(unlikely(last_stream_accepted_t == 0))
1131
last_stream_accepted_t = now;
1132
1131
- if(last_stream_accepted_t + 30 < now) {
1133
+ if(now - last_stream_accepted_t < rate_t) {
1134
netdata_mutex_unlock(&stream_rate_mutex);
1133
- error("STREAM [receive from [%s]:%s]: too busy to accept new streaming request. Try again in %ld secs.", w->client_ip, w->client_port, (long)(last_stream_accepted_t + 30 - now));
1135
+ error("STREAM [receive from [%s]:%s]: too busy to accept new streaming request. Try again in %ld secs.", w->client_ip, w->client_port, (long)(rate_t - (now - last_stream_accepted_t)));
1136
return rrdpush_receiver_too_busy_now(w);
1137
}
1138