@cryptotaxi247 / netdata / commits / 5b2628d1d

Mqtt adjust buffer size (#20834)

* reduce MQTT buffer size to default value * Use different initialize buffer size based on the agent profile

Stelios Fragkakis committed Aug 18, 2025 at 15:50 UTC 5b2628d1dd9d79aac5b9bb9d9c1f5e6e541040a0
2 files changed +9 -4
src/aclk/aclk.c
+1 -2
@@ -22,7 +22,6 @@
22 #endif
23
24 #define MQTT_DEFAULT_MAX_BUF_SIZE (25 * 1024 * 1024)
25 -#define MQTT_PARENT_MAX_BUF_SIZE (128 * 1024 * 1024)
25
26 int aclk_pubacks_per_conn = 0; // How many PubAcks we got since MQTT conn est.
27 int aclk_rcvd_cloud_msgs = 0;
@@ -875,7 +874,7 @@ void aclk_main(void *ptr)
874 #endif
875
876 // Enable MQTT buffer growth if necessary
878 - size_t max_buf_size = netdata_conf_is_parent() ? MQTT_PARENT_MAX_BUF_SIZE : MQTT_DEFAULT_MAX_BUF_SIZE;
877 + size_t max_buf_size = MQTT_DEFAULT_MAX_BUF_SIZE;
878 mqtt_wss_set_max_buf_size(mqttwss_client, max_buf_size);
879
880 // Keep reconnecting and talking until our time has come
src/aclk/mqtt_websockets/mqtt_ng.c
+8 -2
@@ -11,7 +11,7 @@ void pulse_aclk_sent_message_acked(usec_t publish_latency, size_t len);
11 #include "mqtt_constants.h"
12 #include "mqtt_ng.h"
13 #include "aclk_mqtt_workers.h"
14 -
14 +#include "daemon/config/netdata-conf-profile.h"
15
16 #define PACKET_ACK_TIMEOUT_SECS (60)
17 #define SMALL_STRING_DONT_FRAGMENT_LIMIT 128
@@ -430,6 +430,9 @@ static void buffer_frag_free_data(struct buffer_fragment *frag)
430 }
431
432 #define HEADER_BUFFER_SIZE (1024*1024)
433 +#define HEADER_BUFFER_SIZE_IOT (128*1024)
434 +#define HEADER_BUFFER_SIZE_STANDALONE (512*1024)
435 +
436 #define GROWTH_FACTOR 1.25
437
438 #define BUFFER_BYTES_USED(buf) ((size_t)((buf)->tail - (buf)->data))
@@ -616,7 +619,10 @@ struct mqtt_ng_client *mqtt_ng_init(struct mqtt_ng_init *settings)
619 {
620 struct mqtt_ng_client *client = callocz(1, sizeof(struct mqtt_ng_client));
621
619 - transaction_buffer_init(&client->main_buffer, HEADER_BUFFER_SIZE);
622 + size_t buffer_size = netdata_conf_is_iot() ?
623 + HEADER_BUFFER_SIZE_IOT :
624 + (netdata_conf_is_standalone() ? HEADER_BUFFER_SIZE_STANDALONE : HEADER_BUFFER_SIZE);
625 + transaction_buffer_init(&client->main_buffer, buffer_size);
626
627 client->rx_aliases = RX_ALIASES_INITIALIZE();
628