From f5277e5c30eb83f274ff97217b48f543822e660f Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 3 Jul 2025 07:51:31 -0400 Subject: [PATCH] MT#55283 add http-buf-size option closes #1950 Change-Id: I12047e7e6af8e0d927744a0dc70c5b4668420878 --- daemon/main.c | 8 ++++++++ daemon/websocket.c | 3 +++ docs/rtpengine.md | 8 ++++++++ etc/rtpengine.conf | 1 + include/main.h | 1 + 5 files changed, 21 insertions(+) diff --git a/daemon/main.c b/daemon/main.c index b0a616275..c3658eb7b 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -22,6 +22,7 @@ #ifndef WITHOUT_NFTABLES #include #endif +#include #include "poller.h" #include "control_tcp.h" @@ -807,6 +808,7 @@ static void options(int *argc, char ***argv, charp_ht templates) { { "https-cert", 0,0, G_OPTION_ARG_FILENAME, &rtpe_config.https_cert,"Certificate for HTTPS and WSS","FILE"}, { "https-key", 0,0, G_OPTION_ARG_FILENAME, &rtpe_config.https_key, "Private key for HTTPS and WSS","FILE"}, { "http-threads", 0,0, G_OPTION_ARG_INT, &rtpe_config.http_threads,"Number of worker threads for HTTP and WS","INT"}, + { "http-buf-size", 0,0, G_OPTION_ARG_INT, &rtpe_config.http_buf_size,"Send buffer size for HTTP and WS in kB","INT"}, { "software-id", 0,0, G_OPTION_ARG_STRING, &rtpe_config.software_id,"Identification string of this software presented to external systems","STRING"}, { "poller-per-thread", 0,0, G_OPTION_ARG_NONE, &rtpe_config.poller_per_thread, "Use poller per thread", NULL }, { "timer-accuracy", 0,0,G_OPTION_ARG_INT, &rtpe_config.timer_accuracy,"Minimum number of microseconds to sleep","INT"}, @@ -1050,6 +1052,12 @@ static void options(int *argc, char ***argv, charp_ht templates) { die("Missing option --listen-tcp, --listen-udp, --listen-ng, --listen-tcp-ng, " "--listen-http, or --listen-https"); + const static size_t max_buf_size = + ((1LL << (sizeof(((struct lws_context_creation_info) {}).pt_serv_buf_size) * 8 - 1)) + - 1) / 1024; + if (rtpe_config.http_buf_size >= max_buf_size) + die("Option 'http-buf-size' too large (must be <%zu)", max_buf_size); + if (graphitep) { if (!endpoint_parse_any_getaddrinfo_full(&rtpe_config.graphite_ep, graphitep)) die("Invalid IP or port '%s' (--graphite)", graphitep); diff --git a/daemon/websocket.c b/daemon/websocket.c index c27a0dfc7..94ea9011d 100644 --- a/daemon/websocket.c +++ b/daemon/websocket.c @@ -1160,6 +1160,7 @@ int websocket_init(void) { LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND | #endif 0, + .pt_serv_buf_size = rtpe_config.http_buf_size > 0 ? rtpe_config.http_buf_size * 1024LL : 0, }; websocket_context = lws_create_context(&wci); err = "Failed to create LWS context"; @@ -1192,6 +1193,7 @@ int websocket_init(void) { .port = ep->port, .iface = g_strdup(sockaddr_print_buf(&ep->address)), .protocols = websocket_protocols, + .pt_serv_buf_size = wci.pt_serv_buf_size, }; vhost->vhost_name = vhost->iface; if (ep->address.family->af == AF_INET) @@ -1242,6 +1244,7 @@ int websocket_init(void) { .ssl_cert_filepath = rtpe_config.https_cert, .ssl_private_key_filepath = rtpe_config.https_key ? : rtpe_config.https_cert, .options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT, + .pt_serv_buf_size = wci.pt_serv_buf_size, // XXX cipher list, key password }; vhost->vhost_name = vhost->iface; diff --git a/docs/rtpengine.md b/docs/rtpengine.md index e5e935679..0c0741a75 100644 --- a/docs/rtpengine.md +++ b/docs/rtpengine.md @@ -989,6 +989,14 @@ call to inject-DTMF won't be sent to __\-\-dtmf-log-dest=__ or __\-\-listen-tcp- number as given under __num-threads__ will be used. If no HTTP listeners are enabled, then no threads are created. +- __\-\-http-buf-size=__*INT* + + Set the internal buffer size used by the HTTP/HTTPS/WS/WSS library, in + kilobytes. If unset or less than or equal to zero, then the + implementation-defined default will be used. Set this to 1024 (one + megabyte) or larger if you experience high WS activity, to improve + performance and prevent possible protocol hiccups. + - __\-\-software-id=__*STRING* Sets a free-form string that is used to identify this software towards external diff --git a/etc/rtpengine.conf b/etc/rtpengine.conf index 17b426a8f..4add413be 100644 --- a/etc/rtpengine.conf +++ b/etc/rtpengine.conf @@ -49,6 +49,7 @@ tos = 184 # num-threads = 16 # media-num-threads = 8 # http-threads = 4 +# http-buf-size = 1024 port-min = 30000 port-max = 39999 diff --git a/include/main.h b/include/main.h index cb72ab0b0..ac4a825b3 100644 --- a/include/main.h +++ b/include/main.h @@ -89,6 +89,7 @@ enum endpoint_learning { X(timer_accuracy) \ X(ng_client_timeout) \ X(ng_client_retries) \ + X(http_buf_size) \ #define RTPE_CONFIG_INT64_PARAMS \ X(bw_limit) \