@cryptotaxi247 / netdata-1 / commits / ff14353bc

streaming rate limiting config option

Costa Tsaousis (ktsaou) committed Jul 6, 2018 at 20:42 UTC ff14353bc7d9490cf17f6d8d0e7e21e1a29acd70
4 files changed +6 -4
src/main.c
+1
@@ -102,6 +102,7 @@ void web_server_threading_selection(void) {
102 void web_server_config_options(void) {
103 web_client_timeout = (int) config_get_number(CONFIG_SECTION_WEB, "disconnect idle clients after seconds", web_client_timeout);
104 web_client_first_request_timeout = (int) config_get_number(CONFIG_SECTION_WEB, "timeout for first request", web_client_first_request_timeout);
105 + web_client_streaming_rate_t = config_get_number(CONFIG_SECTION_WEB, "accept a streaming request every seconds", web_client_streaming_rate_t);
106
107 respect_web_browser_do_not_track_policy = config_get_boolean(CONFIG_SECTION_WEB, "respect do not track policy", respect_web_browser_do_not_track_policy);
108 web_x_frame_options = config_get(CONFIG_SECTION_WEB, "x-frame-options response header", "");
src/rrdpush.c
+3 -4
@@ -1119,20 +1119,19 @@ int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url
1119 }
1120 }
1121
1122 - {
1122 + if(unlikely(web_client_streaming_rate_t > 0)) {
1123 static netdata_mutex_t stream_rate_mutex = NETDATA_MUTEX_INITIALIZER;
1124 static volatile time_t last_stream_accepted_t = 0;
1125
1126 netdata_mutex_lock(&stream_rate_mutex);
1127 time_t now = now_realtime_sec();
1128 - time_t rate_t = 10;
1128
1129 if(unlikely(last_stream_accepted_t == 0))
1130 last_stream_accepted_t = now;
1131
1133 - if(now - last_stream_accepted_t < rate_t) {
1132 + if(now - last_stream_accepted_t < web_client_streaming_rate_t) {
1133 netdata_mutex_unlock(&stream_rate_mutex);
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)));
1134 + error("STREAM [receive from [%s]:%s]: too busy to accept new streaming request. Will be allowed in %ld secs.", w->client_ip, w->client_port, (long)(web_client_streaming_rate_t - (now - last_stream_accepted_t)));
1135 return rrdpush_receiver_too_busy_now(w);
1136 }
1137
src/web_server.c
+1
@@ -409,6 +409,7 @@ static struct web_client *web_client_create_on_listenfd(int listener) {
409
410 int web_client_timeout = DEFAULT_DISCONNECT_IDLE_WEB_CLIENTS_AFTER_SECONDS;
411 int web_client_first_request_timeout = DEFAULT_TIMEOUT_TO_RECEIVE_FIRST_WEB_REQUEST;
412 +long web_client_streaming_rate_t = 0L;
413
414 static void multi_threaded_web_client_worker_main_cleanup(void *ptr) {
415 struct web_client *w = ptr;
src/web_server.h
+1
@@ -43,5 +43,6 @@ extern int api_listen_sockets_setup(void);
43 #define DEFAULT_DISCONNECT_IDLE_WEB_CLIENTS_AFTER_SECONDS 60
44 extern int web_client_timeout;
45 extern int web_client_first_request_timeout;
46 +extern long web_client_streaming_rate_t;
47
48 #endif /* NETDATA_WEB_SERVER_H */