[ZBX-23722] Drastically higher memory usage for Script items on 6.4 Created: 2023 Nov 17 Updated: 2024 Jul 31 Resolved: 2024 Jan 23 |
|
Status: | Closed |
Project: | ZABBIX BUGS AND ISSUES |
Component/s: | Proxy (P), Server (S) |
Affects Version/s: | None |
Fix Version/s: | 6.0.26rc1, 6.4.11rc1, 7.0.0beta1, 7.0 (plan) |
Type: | Problem report | Priority: | Major |
Reporter: | Tomass Janis Bross | Assignee: | Andrejs Sitals (Inactive) |
Resolution: | Fixed | Votes: | 1 |
Labels: | None | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | Not Specified | ||
Original Estimate: | Not Specified |
Attachments: |
![]() ![]() ![]() |
||||||||||||||||
Issue Links: |
|
||||||||||||||||
Team: | |||||||||||||||||
Sprint: | S2401-1 | ||||||||||||||||
Story Points: | 3 |
Description |
Comments |
Comment by Andrejs Sitals (Inactive) [ 2024 Jan 03 ] |
ZBX_ES_MEMORY_LIMIT controls the amount of memory that can be allocated by scripts on each poller. It looks like it used to be 10MB, but was increased to 64MB in To test how this affects memory consumption, only one poller process was started, 110 memory-intensive script items were created, then "Execute now" was used for all items. Here's the script that was used: function randInt(min, max) { return min + Math.floor(Math.random() * (max - min + 1)); } var len = randInt(1000000, 2000000); var sum = 0; var arr = new Array(len); for (var i = 0; i < len; i++) { arr[i] = i; } for (var i = 0; i < len; i++) { sum += arr[i] & 0xFFFFFFFF; } return sum & 0x0FFFFFFF; Lowering memory limit to 64MB and adding some logging in es_malloc() reveals that it often returns NULL (i.e., script engine has already used all "available" memory) - almost every call to get_value_script() results in "out of memory". Though script items are executed successfully. Memory consumption of dev virtual machine variesĀ between 2.21GB and 2.28GB during the test. Rising memory limit back to 512MB gives considerably larger memory consumption and much smaller number of "failed" calls to es_malloc() which seem to be "periodic" - once per ~20 calls to get_value_script(). Memory consumption of dev vm is between 2.31GB and 2.72GB during the test. When memory limit is increased to 2048MB, calls to es_malloc() don't result in "out of memory" anymore with the mentioned test items, though the memory consumption gets very high until all "Execute now" tasks are finished. When they're done, most of the memory gets released, though memory consumption during idle periods still remains higher than with lower ZBX_ES_MEMORY_LIMIT values. From the tests it looks like script engine is optimizing memory management either by reusing allocated memory or by delaying releasing the memory. When ZBX_ES_MEMORY_LIMIT is high, this can result in high memory usage. To fix the issue, either ZBX_ES_MEMORY_LIMIT has to be lowered (we might want to make it configurable), or script engine has to release memory more agressively. This might apply to JavaScript preprocessing and other places where script engine is used. |
Comment by Andrejs Sitals (Inactive) [ 2024 Jan 04 ] |
It looks like calling duk_gc(ctx, flags) after executing the script solves the issue - memory consumption remains low and stable, and there are no "failed" calls to es_malloc() after adding duk_gc(). Documentation states that it's worth calling duk_gc() twice. |
Comment by Andrejs Sitals (Inactive) [ 2024 Jan 04 ] |
In 6.0, affected processes are:
|
Comment by Andrejs Sitals (Inactive) [ 2024 Jan 12 ] |
Available in versions:
|
Comment by Shane Arnold [ 2024 Jul 31 ] |
Hi Team, checking to see if this made it into 7.0 LTS release and minors .1 and .2? I have seen this behaviour since 7.0.0, currently on 7.0.1, with the preprocessing manager using large amounts of memory (including virtual). |