1

I'm observing the memory usage of my website. Every requests that I have sent to the express server, the memory usage adds up 0.5 MB and it does not lower down after use.

Is it normal?
Does it mean there is a memory leak needed to fixed?
Is the problem is in Express or in Node.js?

enter image description here

markcalendario
  • 218
  • 2
  • 9
  • Over how long an interval of time do you observe this happening? Does it continue to rise for 1000 requests? Some servers will steadily increase their memory usage up to some highwater mark and from then on will not go higher as they reach their maximum working set of memory and then live within that. As for what could be causing it, there's no way for us to know at all without seeing code and probably examining heap snapshots (the usual way of diagnosing memory use issues) – jfriend00 Jun 18 '22 at 03:43
  • FYI, this is not a generic problem with either nodejs or Express. If it is indeed a leak that continues to rise forever, it would be a problem with your code and what it does, not specifically with nodejs or Express by themselves. – jfriend00 Jun 18 '22 at 03:44
  • 1
    FYI, the image you show does not show continually increasing memory usage. – jfriend00 Jun 18 '22 at 03:46
  • 1
    See [Memory usage doesn't decrease in nodejs](https://stackoverflow.com/questions/29885939/memory-usage-doesnt-decrease-in-node-js-whats-going-on/29885992#29885992) for some discussion of a similar issue. – jfriend00 Jun 18 '22 at 03:53
  • I am not sure if this issue will still be observable for thousands of requests. But, I have noticed that every requests there is an .5 MB increase in the memory and do not decrease afterwards. – markcalendario Jun 18 '22 at 05:25
  • 1
    It's only a leak if it keeps going up on every request as you do many, many requests. Heaps don't immediately return all memory back to the OS that isn't in use and they can get a big fragmented - all of which means they may go up a little bit and eventually reach a high water mark and stop going up. To know whether you have a leak, you have to see it continually going up over time over many requests. Only that type of observation is an actual leak. – jfriend00 Jun 18 '22 at 05:30

1 Answers1

0

After use, a memory should degrade.

After multiple tests that I ran, I found out that I had left a database connection open that caused memory to go up and not go down. 

Here is the memory usage before the stress test. Idle State

Express' memory usage at the 5,000th open concurrent connection mark. 5000th mark

10,000th thread mark 10000th mark

After a test, the memory usage went down and the server's status back to normal and in idle state. back to normal state

markcalendario
  • 218
  • 2
  • 9