diff options
author | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2018-07-06 20:42:07 +0300 |
---|---|---|
committer | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2018-07-06 20:42:07 +0300 |
commit | ff14353bc7d9490cf17f6d8d0e7e21e1a29acd70 (patch) | |
tree | 82fd6b43d1d6623458dc788a6950a6ca545f4ff2 /src | |
parent | ff3c0f509726048ee8f767da49957d2bcf9c4ca8 (diff) |
streaming rate limiting config option
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 1 | ||||
-rw-r--r-- | src/rrdpush.c | 7 | ||||
-rw-r--r-- | src/web_server.c | 1 | ||||
-rw-r--r-- | src/web_server.h | 1 |
4 files changed, 6 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c index 277ffcdae2..9443095561 100644 --- a/src/main.c +++ b/src/main.c @@ -102,6 +102,7 @@ void web_server_threading_selection(void) { void web_server_config_options(void) { web_client_timeout = (int) config_get_number(CONFIG_SECTION_WEB, "disconnect idle clients after seconds", web_client_timeout); web_client_first_request_timeout = (int) config_get_number(CONFIG_SECTION_WEB, "timeout for first request", web_client_first_request_timeout); + web_client_streaming_rate_t = config_get_number(CONFIG_SECTION_WEB, "accept a streaming request every seconds", web_client_streaming_rate_t); 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); web_x_frame_options = config_get(CONFIG_SECTION_WEB, "x-frame-options response header", ""); diff --git a/src/rrdpush.c b/src/rrdpush.c index f99d12e658..c28512ee05 100644 --- a/src/rrdpush.c +++ b/src/rrdpush.c @@ -1119,20 +1119,19 @@ int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url } } - { + if(unlikely(web_client_streaming_rate_t > 0)) { static netdata_mutex_t stream_rate_mutex = NETDATA_MUTEX_INITIALIZER; static volatile time_t last_stream_accepted_t = 0; netdata_mutex_lock(&stream_rate_mutex); time_t now = now_realtime_sec(); - time_t rate_t = 10; if(unlikely(last_stream_accepted_t == 0)) last_stream_accepted_t = now; - if(now - last_stream_accepted_t < rate_t) { + if(now - last_stream_accepted_t < web_client_streaming_rate_t) { netdata_mutex_unlock(&stream_rate_mutex); - 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))); + 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))); return rrdpush_receiver_too_busy_now(w); } diff --git a/src/web_server.c b/src/web_server.c index 8c0aae46b5..ee8dddf7b9 100644 --- a/src/web_server.c +++ b/src/web_server.c @@ -409,6 +409,7 @@ static struct web_client *web_client_create_on_listenfd(int listener) { int web_client_timeout = DEFAULT_DISCONNECT_IDLE_WEB_CLIENTS_AFTER_SECONDS; int web_client_first_request_timeout = DEFAULT_TIMEOUT_TO_RECEIVE_FIRST_WEB_REQUEST; +long web_client_streaming_rate_t = 0L; static void multi_threaded_web_client_worker_main_cleanup(void *ptr) { struct web_client *w = ptr; diff --git a/src/web_server.h b/src/web_server.h index 3542f30b26..3b7db2214a 100644 --- a/src/web_server.h +++ b/src/web_server.h @@ -43,5 +43,6 @@ extern int api_listen_sockets_setup(void); #define DEFAULT_DISCONNECT_IDLE_WEB_CLIENTS_AFTER_SECONDS 60 extern int web_client_timeout; extern int web_client_first_request_timeout; +extern long web_client_streaming_rate_t; #endif /* NETDATA_WEB_SERVER_H */ |