`
sillycat
  • 浏览: 2542990 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Memory Leak in NodeJS

 
阅读更多
Memory Leak in NodeJS

I have done a lot of memory leak investigation for JAVA, this is the first time for NodeJS.

Compare the version of TSC
> sudo npm install -g typescript@2.1.4
> tsc --version
Version 2.1.4

My current one is
> tsc --version
Version 3.2.2

> node --version
v10.14.2

In my package.json file, it start the nodeJS application like this
"start": "node build/src/index.js",
So I follow the docs and add - - inspect to that
"start": "node --inspect build/src/index.js",

Once it start, it will open a debug port
> npm run start
> sillycat-microservice@0.0.3 start /Users/hluo/company/code/sillycat.contactManager
> node --inspect build/src/index.js
Debugger listening on ws://127.0.0.1:9229/50c12fb6-488b-4456-b96a-a2f4e1f92582
For help, see: https://nodejs.org/en/docs/inspector

In the chrome browser, we can open a tab and put
chrome://inspect

We can open the monitor of that nodeJS process and we can take snapshot of the nodeJS memory to see what methods use most of the memory.
In my case, process.nextTick() happen a lot and use most of the memory
https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/
https://www.oschina.net/translate/understanding-process-next-tick

So after I read a lot of related documents. I guess maybe here is the reason.
I am using nodeJS to consume the messages from RabbitMQ, this fetch message operations are quick and powerful, but for each message, we need to do CRUD on DB and ElasticSearch. It seems heavier.
https://www.rabbitmq.com/tutorials/tutorial-two-javascript.html
https://mariuszwojcik.wordpress.com/2014/05/19/how-to-choose-prefetch-count-value-for-rabbitmq/

So there is time window NodeJS app received a lot of messages, but the callback did not happen yet to ACK the message. We generate a lot of nextTick and host all these messages in our memory. These objects can not be GC.

Then I open the UI console in RabbitMQ, and I saw the messages on the fly are large. Every time the messages on the fly grows to a large number, I get OUT OF MEMORY in nodeJS console. And the last few GC logging showing nodeJS can not get any free memory after GC.
And sometimes the ‘deliver/get’ is reaching 2000 m/s but the ‘ack’ is still 15 m/s.

I think that means Consumer just try to fetch too many messages and can not handle them in time.

After I came to change my NodeJS codes
await channel.prefetch(10000); //limit 10000 message on the fly

Limit 10000 messages on the fly, it will not slow down the consuming of the rabbitMQ. But it will make the 'deliver/get' and ‘ack’ more stable and the same number


References:
https://sillycat.iteye.com/blog/772289
https://unix.stackexchange.com/questions/10106/orphaned-connections-in-close-wait-state
https://www.shellhacks.com/kill-tcp-connections-close-wait-state/
https://marmelab.com/blog/2018/04/03/how-to-track-and-fix-memory-leak-with-nodejs.html
https://mariuszwojcik.wordpress.com/2014/05/19/how-to-choose-prefetch-count-value-for-rabbitmq/
分享到:
评论

相关推荐

    memory leak

    内存泄漏是程序在申请内存后,无法释放已申请的内存空间,一次小的内存泄漏可能看似无足轻重,但随着时间推移,大量的内存泄漏会消耗掉系统可用内存,导致性能下降甚至系统崩溃。在C++编程中,由于手动管理内存的...

    BREW Memory Leak Checker 20120219

    This program is a tool that help you positioning memory leak locations of an QUALCOMM BREW application on simulator. It can give the call stack of memory leaks (including the locations that MALLOC/...

    BREW Memory Leak Checker

    **BREW Memory Leak Checker** 是一个专为BREW(Binary Runtime Environment for Wireless)平台设计的工具,用于检测和定位BREW应用程序中的内存泄漏问题。在移动设备开发中,内存管理是至关重要的,因为有限的资源...

    C++ Memory Leak Detect

    本文将深入探讨C++中的内存泄漏问题及其解决策略,并介绍两种常用的内存泄漏检测工具——Visual Leak Detector (VLD) 和 CodeSnitch。 内存泄漏的发生通常是由于以下原因: 1. 动态分配的内存未被释放:当使用`new`...

    技術分享_Glassfish 3.1.2.2 Web Service Memory Leak Workaround1

    Glassfish 3.1.2.2 Web Service Memory Leak Workaround Glassfish 3.1.2.2 中的 Memory Leak 问题可能会导致服务器变慢或无响应。这种问题可能是由于 Web Service 的 Memory Leak 导致的。在此文中,我们将讨论...

    Angularjs memory leak in ie8 test

    使用内存分析工具,如Chrome DevTools或Firefox的Memory Profiler,可以帮助识别内存泄漏的模式和具体对象。这些工具可以显示内存分配和引用关系,帮助开发者找到难以察觉的内存泄漏点。 总的来说,AngularJS在IE8...

    BREW Memory Leak Checker 20111030

    BREW Memory Leak Checker是一款专为BREW(Binary Runtime Environment for Wireless)平台设计的内存泄漏检测工具,版本号为20111030。该工具的主要功能是在BREW模拟器上帮助开发者定位并解决应用程序中的内存泄漏...

    BREW Memory Leak Checker 20111109

    BREW Memory Leak Checker是一款专为BREW(Binary Runtime Environment for Wireless)平台设计的内存泄漏检测工具,版本号为20111109。该工具的主要功能是在BREW模拟器上帮助开发者定位并解决应用程序中的内存泄漏...

    c++ memory leak 检测代码

    在C++编程中,内存泄漏是一个常见的问题,它发生在程序员分配了内存但未能正确地释放。这可能导致程序占用越来越多的内存,最终导致性能下降甚至崩溃。为了帮助开发者检测和修复内存泄漏,本压缩包提供了一个内存...

    Memory Leak.zip

    JavaScript是一种广泛应用于Web开发的脚本语言,它在执行时占据内存资源,如果代码编写不当,可能会出现“内存泄漏”(Memory Leak)的问题。内存泄漏是程序运行时未释放不再使用的内存,导致系统资源浪费,严重时...

    How to createavoid memory leak in Java and.NET.doc

    java

    BREW Memory Leak Checker 20120219 (with src)

    This program is a tool that help you positioning memory leak locations of an QUALCOMM BREW application on simulator. It can give the call stack of memory leaks (including the locations that MALLOC/...

    Memory Leak(解决方案).md

    Memory Leak(解决方案).md

    Android中Memory Leak原因分析及解决办法

    "Android中Memory Leak原因分析及解决办法" Android中Memory Leak原因分析及解决办法是Android开发过程中的重要问题之一。Memory Leak是指在Android应用程序中,一些对象不能被正确释放,导致这些对象继续占用内存...

    Memory Leak Detected(亲测可用).md

    Memory Leak Detected(亲测可用).md

    编译器设计之代码分析工具:Memory Leak Detectors.zip

    编译器设计之代码分析工具:Memory Leak Detectors

    memory-leak-detector

    内存泄漏检测器 MemoryLeakDetector是由Xigua视频android团队开发的本地内存泄漏监视工具。 它具有访问简单,监视范围广,性能...leak-detector:0.0.7 '} 步骤3:添加代码以方便使用(使用广播控件不需要此步骤) //

    Visual C ++ memory Leak Detector.rar

    "Visual C++ Memory Leak Detector"就是针对这类问题的工具,它可以帮助开发者检测和定位C++程序中的内存泄漏。 该压缩包文件包含了一个名为"vld-1.9d-setup.exe"的安装程序,这很可能是Visual Leak Detector (VLD)...

Global site tag (gtag.js) - Google Analytics