What does Heap Usage mean in PM2
Asked Answered
G

1

17

What does Heap Usage mean in the "Custom Metrics" window when running pm2 monit?

The value for my server gets dangerously close to 100%.

enter image description here

Gollin answered 28/12, 2019 at 16:56 Comment(3)
It looks like used heap size / heap size (41/57 = 72%). Ideally in an efficiently written program it would be 100% or close to 100% because that would mean that all malloc'd memory is actually used rather than simply allocated but not usedKantar
Why is 100% better? Because malloc'd memory is not available to other programs. Consider a PC with 4GB of ram and your heap is 3GB - that leaves only 1GB free RAM. But if heap usage is only 10% that means your program is only using 300MB but allocates (makes unavailable to other programs) 3GB wasting 2.7GB of RAM unused and unusableKantar
@Kantar The way you phrased that confused me for a moment. I didn't realize you were posing a question for rhetorical purposes instead of asking!Farceur
P
2

The heap is a memory used by programming languages to store global variables. By default, all global variable are stored in heap memory space.

It`is maybe because of your programs variable.

you can reset it after it exceeded the limit or force pm2 do it for you automatically.

pm2 start api.js --max-memory-restart 300M

Protomartyr answered 5/2, 2021 at 3:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.