Node.js app has periodic slowness and/or timeouts (does not accept incoming requests)

前端 未结 7 532
眼角桃花
眼角桃花 2021-01-30 02:08

This problem is killing the stability of my production servers.

To recap, the basic idea is that my node server(s) sometimes intermittently slow down, sometimes resultin

7条回答
  •  南方客
    南方客 (楼主)
    2021-01-30 02:56

    You are heavily leaking memory, try setting every object to null as soon as you don't need it anymore! Read this.

    More information about hunting down memory leaks can be found here.

    Give special attention to having multiple references to the same object and check if you have circular references, those are a pain to debug but will help you very much.

    Try invoking the garbage collector manually every minute or so (I don't know if you can do this in node.js cause I'm more of a c++ and php coder). From my years of experience working with c++ I can tell you the most likely cause of your application slowing down over time is memory leaks, find them and plug them, you'll be ok!

    Also assuming you're not caching and/or processing images, audio or video in memory or anything like that 150M heap is a lot! Those could be hundreds of thousands or even millions of small objects.

    You don't have to be running out of memory for your application to slow down... just searching for free memory with that many objects already allocated is a huge job for the memory allocator, it takes a lot of time to allocate each new object and as you leak more and more memory that time only increases.

提交回复
热议问题