diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 11:19:16 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-07-24 09:53:24 +0000 |
commit | b5f8ee61a7f7e9bd291dd26b0585d03eb686c941 (patch) | |
tree | d4d31289c39fc00da064a825df13a0b98ce95b10 /web/server/static | |
parent | Adding upstream version 1.44.3. (diff) | |
download | netdata-upstream.tar.xz netdata-upstream.zip |
Adding upstream version 1.46.3.upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/web/server/static/static-threaded.c (renamed from web/server/static/static-threaded.c) | 78 | ||||
-rw-r--r-- | src/web/server/static/static-threaded.h (renamed from web/server/static/static-threaded.h) | 0 | ||||
-rw-r--r-- | web/server/static/Makefile.am | 11 | ||||
-rw-r--r-- | web/server/static/README.md | 21 |
4 files changed, 40 insertions, 70 deletions
diff --git a/web/server/static/static-threaded.c b/src/web/server/static/static-threaded.c index 773d49f15..a4b24c9ac 100644 --- a/web/server/static/static-threaded.c +++ b/src/web/server/static/static-threaded.c @@ -40,7 +40,8 @@ static struct web_client *web_client_create_on_fd(POLLINFO *pi) { w->port_acl = pi->port_acl; int flag = 1; - if(unlikely(web_client_check_tcp(w) && setsockopt(w->ifd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)) != 0)) + if(unlikely( + web_client_check_conn_tcp(w) && setsockopt(w->ifd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)) != 0)) netdata_log_debug(D_WEB_CLIENT, "%llu: failed to enable TCP_NODELAY on socket fd %d.", w->id, w->ifd); flag = 1; @@ -60,7 +61,7 @@ static struct web_client *web_client_create_on_fd(POLLINFO *pi) { // the main socket listener - STATIC-THREADED struct web_server_static_threaded_worker { - netdata_thread_t thread; + ND_THREAD *thread; int id; int running; @@ -142,7 +143,7 @@ static int web_server_file_read_callback(POLLINFO *pi, short int *events) { goto cleanup; } - if(unlikely(w->mode != WEB_CLIENT_MODE_FILECOPY || w->ifd == w->ofd)) { + if(unlikely(w->mode != HTTP_REQUEST_MODE_FILECOPY || w->ifd == w->ofd)) { netdata_log_debug(D_WEB_CLIENT, "%llu: PREVENTED ATTEMPT TO READ FILE ON FD %d, ON NON-FILECOPY WEB CLIENT", w->id, pi->fd); retval = -1; goto cleanup; @@ -205,13 +206,13 @@ static void *web_server_add_callback(POLLINFO *pi, short int *events, void *data struct web_client *w = web_client_create_on_fd(pi); if (!strncmp(pi->client_port, "UNIX", 4)) { - web_client_set_unix(w); + web_client_set_conn_unix(w); } else { - web_client_set_tcp(w); + web_client_set_conn_tcp(w); } #ifdef ENABLE_HTTPS - if ((!web_client_check_unix(w)) && (netdata_ssl_web_server_ctx)) { + if ((web_client_check_conn_tcp(w)) && (netdata_ssl_web_server_ctx)) { sock_delnonblock(w->ifd); //Read the first 7 bytes from the message, but the message @@ -296,11 +297,11 @@ static int web_server_rcv_callback(POLLINFO *pi, short int *events) { worker_is_busy(WORKER_JOB_PROCESS); web_client_process_request_from_web_server(w); - if (unlikely(w->mode == WEB_CLIENT_MODE_STREAM)) { + if (unlikely(w->mode == HTTP_REQUEST_MODE_STREAM)) { web_client_send(w); } - else if(unlikely(w->mode == WEB_CLIENT_MODE_FILECOPY)) { + else if(unlikely(w->mode == HTTP_REQUEST_MODE_FILECOPY)) { if(w->pollinfo_filecopy_slot == 0) { netdata_log_debug(D_WEB_CLIENT, "%llu: FILECOPY DETECTED ON FD %d", w->id, pi->fd); @@ -393,8 +394,9 @@ cleanup: // ---------------------------------------------------------------------------- // web server worker thread -static void socket_listen_main_static_threaded_worker_cleanup(void *ptr) { - worker_private = (struct web_server_static_threaded_worker *)ptr; +static void socket_listen_main_static_threaded_worker_cleanup(void *pptr) { + worker_private = CLEANUP_FUNCTION_GET_PTR(pptr); + if(!worker_private) return; netdata_log_info("stopped after %zu connects, %zu disconnects (max concurrent %zu), %zu receptions and %zu sends", worker_private->connected, @@ -413,7 +415,7 @@ static bool web_server_should_stop(void) { } void *socket_listen_main_static_threaded_worker(void *ptr) { - worker_private = (struct web_server_static_threaded_worker *)ptr; + worker_private = ptr; worker_private->running = 1; worker_register("WEB"); worker_register_job_name(WORKER_JOB_ADD_CONNECTION, "connect"); @@ -426,26 +428,24 @@ void *socket_listen_main_static_threaded_worker(void *ptr) { worker_register_job_name(WORKER_JOB_SND_DATA, "send"); worker_register_job_name(WORKER_JOB_PROCESS, "process"); - netdata_thread_cleanup_push(socket_listen_main_static_threaded_worker_cleanup, ptr); - - poll_events(&api_sockets - , web_server_add_callback - , web_server_del_callback - , web_server_rcv_callback - , web_server_snd_callback - , NULL - , web_server_should_stop - , web_allow_connections_from - , web_allow_connections_dns - , NULL - , web_client_first_request_timeout - , web_client_timeout - , default_rrd_update_every * 1000 // timer_milliseconds - , ptr // timer_data - , worker_private->max_sockets - ); - - netdata_thread_cleanup_pop(1); + CLEANUP_FUNCTION_REGISTER(socket_listen_main_static_threaded_worker_cleanup) cleanup_ptr = worker_private; + poll_events(&api_sockets + , web_server_add_callback + , web_server_del_callback + , web_server_rcv_callback + , web_server_snd_callback + , NULL + , web_server_should_stop + , web_allow_connections_from + , web_allow_connections_dns + , NULL + , web_client_first_request_timeout + , web_client_timeout + , default_rrd_update_every * 1000 // timer_milliseconds + , ptr // timer_data + , worker_private->max_sockets + ); + return NULL; } @@ -453,8 +453,10 @@ void *socket_listen_main_static_threaded_worker(void *ptr) { // ---------------------------------------------------------------------------- // web server main thread - also becomes a worker -static void socket_listen_main_static_threaded_cleanup(void *ptr) { - struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr; +static void socket_listen_main_static_threaded_cleanup(void *pptr) { + struct netdata_static_thread *static_thread = CLEANUP_FUNCTION_GET_PTR(pptr); + if(!static_thread) return; + static_thread->enabled = NETDATA_MAIN_THREAD_EXITING; // int i, found = 0; @@ -465,7 +467,7 @@ static void socket_listen_main_static_threaded_cleanup(void *ptr) { // if(static_workers_private_data[i].running) { // found++; // netdata_log_info("stopping worker %d", i + 1); -// netdata_thread_cancel(static_workers_private_data[i].thread); +// nd_thread_signal_cancel(static_workers_private_data[i].thread); // } // else // netdata_log_info("found stopped worker %d", i + 1); @@ -495,7 +497,7 @@ static void socket_listen_main_static_threaded_cleanup(void *ptr) { } void *socket_listen_main_static_threaded(void *ptr) { - netdata_thread_cleanup_push(socket_listen_main_static_threaded_cleanup, ptr); + CLEANUP_FUNCTION_REGISTER(socket_listen_main_static_threaded_cleanup) cleanup_ptr = ptr; web_server_mode = WEB_SERVER_MODE_STATIC_THREADED; if(!api_sockets.opened) @@ -547,14 +549,14 @@ void *socket_listen_main_static_threaded(void *ptr) { snprintfz(tag, sizeof(tag) - 1, "WEB[%d]", i+1); netdata_log_info("starting worker %d", i+1); - netdata_thread_create(&static_workers_private_data[i].thread, tag, NETDATA_THREAD_OPTION_DEFAULT, - socket_listen_main_static_threaded_worker, (void *)&static_workers_private_data[i]); + static_workers_private_data[i].thread = nd_thread_create(tag, NETDATA_THREAD_OPTION_DEFAULT, + socket_listen_main_static_threaded_worker, + (void *)&static_workers_private_data[i]); } // and the main one static_workers_private_data[0].max_sockets = max_sockets / static_threaded_workers_count; socket_listen_main_static_threaded_worker((void *)&static_workers_private_data[0]); - netdata_thread_cleanup_pop(1); return NULL; } diff --git a/web/server/static/static-threaded.h b/src/web/server/static/static-threaded.h index a8c5335ef..a8c5335ef 100644 --- a/web/server/static/static-threaded.h +++ b/src/web/server/static/static-threaded.h diff --git a/web/server/static/Makefile.am b/web/server/static/Makefile.am deleted file mode 100644 index 59250a997..000000000 --- a/web/server/static/Makefile.am +++ /dev/null @@ -1,11 +0,0 @@ -# SPDX-License-Identifier: GPL-3.0-or-later - -AUTOMAKE_OPTIONS = subdir-objects -MAINTAINERCLEANFILES = $(srcdir)/Makefile.in - -SUBDIRS = \ - $(NULL) - -dist_noinst_DATA = \ - README.md \ - $(NULL) diff --git a/web/server/static/README.md b/web/server/static/README.md deleted file mode 100644 index c4e5c4c18..000000000 --- a/web/server/static/README.md +++ /dev/null @@ -1,21 +0,0 @@ -<!-- -title: "`static-threaded` web server" -description: "The Netdata Agent's static-threaded web server spawns a fixed number of threads that listen to web requests and uses non-blocking I/O." -custom_edit_url: https://github.com/netdata/netdata/edit/master/web/server/static/README.md -sidebar_label: "`static-threaded` web server" -learn_status: "Published" -learn_topic_type: "Tasks" -learn_rel_path: "Developers/Web" ---> - -# `static-threaded` web server - -The `static-threaded` web server spawns a fixed number of threads. -All the threads are concurrently listening for web requests on the same sockets. -The kernel distributes the incoming requests to them. - -Each thread uses non-blocking I/O so it can serve any number of web requests in parallel. - -This web server respects the `keep-alive` HTTP header to serve multiple HTTP requests via the same connection. - - |