8

I made a little app and deployed it into a Ubuntu server using Meteor Up. There are very few users each day (<10), but after few days a lot of the memory of the server is used. So I think that there is a memory leak somewhere in my code.

How to find it ?

Thanks a lot !

Jerome Martin
  • 229
  • 1
  • 9
  • 2
    Strange, I have the very same problem at the moment. I am running Meteor on an AWS Ubuntu instance and installed it using mupx. I was just searching the web to find an answer. Don't know why you got downvoted, I am also asking myself how I could trace memory leaks in Meteor. Kadira shows the memory usage goes up, but it won't tell you why. – waldgeist Mar 04 '16 at 20:41
  • can you share your code? so that we can find the actual cause – Chetan Oct 19 '16 at 12:50

2 Answers2

0

We actually had a memory leak the last days and it was relatively easy to find using a package called heapdump, you can find it here: https://www.npmjs.com/package/heapdump

It is not made for meteor in specific, but for nodejs. Just read through the README carefully to install it. Afterwards find a good moment to get the first heapdump by running kill -USR2 <pid_of_meteor_app> on the server. A good moment is when there is not much going on on the server but enough so that the memory is leaking.

Afer a while, when you recognized a good amount of memory growth without a logical explanation: go make another heapdump and download both. Hit F12 to open up you webdev console on your browser (Chrome, Firefox, Edge,...) and got to Memory there. Import both heapdumps after.

Now you need to find what changed between those two heapdumps, what actually helped me there was this article to understand how to do that: https://www.useanvil.com/blog/engineering/isolating-memory-leak-in-node/

Remember that you are most probably looking for memory reservations of the same size, sometimes just tiny amounts of kb as in our case, but hundreds of thousands of them. So sorting by space is a good idea.

In our case it was an outdated package called tslib which reserverd all the memory after a day or so. We were on 2.3.1, so we went to https://github.com/microsoft/tslib/releases/tag/2.4.0 and read there:

This release includes the __classPrivateFieldIn helper as well as an update to __createBinding to reduce indirection between multiple re-exports.

We updated the package, which was a dependency of another package and that fixed it.

Kadira, Monti APM and whatever is often absolutely useless in such cases, you cannot really track down the source more often than not.

ataraxis
  • 1,257
  • 1
  • 15
  • 30
-2

There is a kadira package to check your app. have a look https://kadira.io/

Ramesh Murugesan
  • 4,727
  • 7
  • 42
  • 67