后端应用程序会消耗所有RAM,但没有发现内存泄漏
我最近部署了Nestjs Backend应用程序来渲染,我提到所有可用的RAM在我的服务后一段时间都消失了。
它可以在相当长的一段时间内正常工作,消耗不超过500MB的RAM,这是我期望看到的,但是随后发生了一些事情,内存开始泄漏。 top
说我的节点过程使用1.4g内存:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
60 render 20 0 2883236 1.4g 56492 S 0.3 2.3 17:27.66 node
但是后来我使用 flag启动了 flag以制作堆快照,令人惊讶的是显示了堆尺寸只有65兆字节,而top表示
1.4G
:
我认为木偶可能是一个问题,所以我从顶部输出中杀死了每个铬的过程,它仅释放了大约80MB的RAM。这里有什么问题,为什么我的RAM使用率如此之高?
I recently deployed my NestJS backend application to Render and I mentioned that all available RAM is gone after some time for my service.
It can work fine for quite some time, consuming no more than 500mb of RAM which is what I expect to see, but then something happens and memory starts to leak. top
says my node process is using 1.4g of memory:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
60 render 20 0 2883236 1.4g 56492 S 0.3 2.3 17:27.66 node
But then I started my application with --inspect
flag to make a heap snapshot, and surprisingly it showed that heap size was only 65 megabytes while top says 1.4g
:
That I also see in VSCode debugger extension:
I thought that puppeteer might be an issue, so I killed every single chrome processes by PID from top output, and it only freed around 80mb of RAM. What could be the issue here and why my RAM usage is so high?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道您正在开发哪种类型的项目,但是最近我在上传文件的系统中也遇到了内存泄漏问题。
首先,要找出导致内存泄漏的原因,您将需要监视您的API中调用哪些请求,该请求引起了此问题,并调试并分析项目代码。
我注意到您正在使用nodejs
- Inspect
标志进行分析,尝试通过保留大小
列进行降序,然后开始分析每个数组中的内容,可能有些数组或对象可以指向您项目中安装的某些库,这可能会导致内存泄漏供您执行调试。我遇到的问题是在
mongoose
库中,在我的代码中的某个点上,有必要打开与数据库的连接,并且没有被关闭。也可能导致内存泄漏的是blob
和文件的
,在我的情况下,我必须删除buffer
还结束了使用blob
的流的读/写操作。我将无法告诉您您的项目中可能有什么问题,但是进行调试和代码分析确实是必要的。
I don't know what type of project you are developing, but recently I also had a memory leak problem in a system that uploads files.
First, to find out what is causing the memory leak, you will need to monitor which request is being called in your API that is causing this problem and debug and analyze your project's code.
I noticed that you are using the NodeJs
--inspect
flag to analyze, try to do a descending sort by theRetained Size
column and start analyzing what is inside each array, probably there are arrays or objects that could point to some library installed in your project that may be causing a memory leak for you to perform debugging.The problem I was having was with the
Mongoose
library, at one point in my code it was necessary to open the connection to the database and it was not being closed. What can also cause a memory leak is theBlob
andBuffer
of files, in my case I had to delete theBuffer
when finishing an upload and also ending the read/write operation of a stream that usedBlob
.I won't be able to tell you what your problem might be in your project, but it will really be necessary to carry out debugging and code analysis.