-
Problem report
-
Resolution: Fixed
-
Trivial
-
None
-
None
-
Sprint 70 (Nov 2020), Sprint 71 (Dec 2020)
-
0.25
After ZBXNEXT-782 it should be easier to create up to 1000 Pollers, however there is large memory consumption due to redundant stack allocations.
In poller.c:848:12: there are 126 items allocated on stack each second, even at idle, this results in 4.42 megabytes of memory consumption per one poller, and this memory will never be used in ordinary poller.
DC_ITEM items[MAX_POLLER_ITEMS];
Even if it is to be used then maximum 1 item is used in ordinary non Java poller.
switch (poller_type) { case ZBX_POLLER_TYPE_JAVA: max_items = MAX_JAVA_ITEMS; break; case ZBX_POLLER_TYPE_PINGER: max_items = MAX_PINGER_ITEMS; break; default: max_items = 1; }
If still wish to keep on stack then could wrap into a function, or in if scope example:
diff --git a/src/zabbix_server/poller/poller.c b/src/zabbix_server/poller/poller.c index f9ce917840..33407f7d44 100644 --- a/src/zabbix_server/poller/poller.c +++ b/src/zabbix_server/poller/poller.c @@ -843,11 +843,9 @@ void zbx_clean_items(DC_ITEM *items, int num, AGENT_RESULT *results) * see DCconfig_get_poller_items() * * * ******************************************************************************/ -static int get_values(unsigned char poller_type, int *nextcheck) +static int get_values(unsigned char poller_type, DC_ITEM *items, AGENT_RESULT *results, int *errcodes, + int *nextcheck) { - DC_ITEM items[MAX_POLLER_ITEMS]; - AGENT_RESULT results[MAX_POLLER_ITEMS]; - int errcodes[MAX_POLLER_ITEMS]; zbx_timespec_t timespec; int i, num, last_available = HOST_AVAILABLE_UNKNOWN; zbx_vector_ptr_t add_results; @@ -971,6 +969,24 @@ exit: return num; } +static int get_values_single(unsigned char poller_type, int *nextcheck) +{ + DC_ITEM items; + AGENT_RESULT results; + int errcodes; + + return get_values(poller_type, &items, &results, &errcodes, nextcheck); +} + +static int get_values_bulk(unsigned char poller_type, int *nextcheck) +{ + DC_ITEM items[MAX_JAVA_ITEMS]; + AGENT_RESULT results[MAX_JAVA_ITEMS]; + int errcodes[MAX_JAVA_ITEMS]; + + return get_values(poller_type, items, results, errcodes, nextcheck); +} + static void zbx_poller_sigusr_handler(int flags) { #ifdef HAVE_NETSNMP @@ -1042,7 +1058,16 @@ ZBX_THREAD_ENTRY(poller_thread, args) old_total_sec); } - processed += get_values(poller_type, &nextcheck); + switch (poller_type) + { + case ZBX_POLLER_TYPE_JAVA: + processed += get_values_bulk(poller_type, &nextcheck); + break; + default: + processed += get_values_single(poller_type, &nextcheck); + break; + } + total_sec += zbx_time() - sec; sleeptime = calculate_sleeptime(nextcheck, POLLER_DELAY);
Memory drops to 800 KB per poller with PostgreSQL after fix