关于nodejs内存泄漏问题的疑问?
发布于 7 年前 作者 binginto 2933 次浏览 来自 问答

通过 process.memoryUsage() 获取nodejs内存使用情况,且每隔45S就会进行一个强制gc() 。 经过一晚上测试,发现headUsed和heapTotal变化都不大,但rss增长幅度比较大。这是因为内存泄漏还是nodejs和linux自身回收内存的机制所致。希望有经验的朋友能予以解答。谢谢。

最初的内存占用情况

[2017-05-25 20:24:03.701] [WARN] log_file - wss.client5000 [2017-05-25 20:24:03.701] [WARN] log_file - client5000 [2017-05-25 20:24:03.701] [WARN] log_file - loginMap0 [2017-05-25 20:24:03.701] [WARN] log_file - timerMap5000 [2017-05-25 20:24:03.701] [WARN] log_file - { rss: 86278144, heapTotal: 65048576, heapUsed: 51594504, external: 919812 } [2017-05-25 20:24:48.809] [WARN] log_file - wss.client5000 [2017-05-25 20:24:48.809] [WARN] log_file - client5000 [2017-05-25 20:24:48.809] [WARN] log_file - loginMap0 [2017-05-25 20:24:48.809] [WARN] log_file - timerMap5000 [2017-05-25 20:24:48.809] [WARN] log_file - { rss: 86786048, heapTotal: 64000000, heapUsed: 51709264, external: 978224 } [2017-05-25 20:25:33.957] [WARN] log_file - wss.client5000 [2017-05-25 20:25:33.957] [WARN] log_file - client5000 [2017-05-25 20:25:33.957] [WARN] log_file - loginMap0 [2017-05-25 20:25:33.957] [WARN] log_file - timerMap5000 [2017-05-25 20:25:33.958] [WARN] log_file - { rss: 85770240, heapTotal: 64000000, heapUsed: 51306016, external: 898460 } [2017-05-25 20:26:19.054] [WARN] log_file - wss.client5000 [2017-05-25 20:26:19.054] [WARN] log_file - client5000 [2017-05-25 20:26:19.054] [WARN] log_file - loginMap0 [2017-05-25 20:26:19.054] [WARN] log_file - timerMap5000 [2017-05-25 20:26:19.054] [WARN] log_file - { rss: 84819968, heapTotal: 62951424, heapUsed: 51305040, external: 898460 }

经过一晚上的发送消息之后的情况。

[2017-05-26 09:07:26.252] [WARN] log_file - wss.client5000 [2017-05-26 09:07:26.253] [WARN] log_file - client5000 [2017-05-26 09:07:26.253] [WARN] log_file - loginMap0 [2017-05-26 09:07:26.253] [WARN] log_file - timerMap5000 [2017-05-26 09:07:26.253] [WARN] log_file - { rss: 101851136, heapTotal: 66097152, heapUsed: 51416176, external: 742988 } [2017-05-26 09:08:11.347] [WARN] log_file - wss.client5000 [2017-05-26 09:08:11.348] [WARN] log_file - client5000 [2017-05-26 09:08:11.348] [WARN] log_file - loginMap0 [2017-05-26 09:08:11.348] [WARN] log_file - timerMap5000 [2017-05-26 09:08:11.348] [WARN] log_file - { rss: 101851136, heapTotal: 66097152, heapUsed: 51416176, external: 742988 } [2017-05-26 09:08:56.490] [WARN] log_file - wss.client5000 [2017-05-26 09:08:56.490] [WARN] log_file - client5000 [2017-05-26 09:08:56.490] [WARN] log_file - loginMap0 [2017-05-26 09:08:56.490] [WARN] log_file - timerMap5000 [2017-05-26 09:08:56.490] [WARN] log_file - { rss: 101851136, heapTotal: 66097152, heapUsed: 51416176, external: 742988 } [2017-05-26 09:09:41.614] [WARN] log_file - wss.client5000 [2017-05-26 09:09:41.614] [WARN] log_file - client5000 [2017-05-26 09:09:41.614] [WARN] log_file - loginMap0 [2017-05-26 09:09:41.614] [WARN] log_file - timerMap5000 [2017-05-26 09:09:41.614] [WARN] log_file - { rss: 101851136, heapTotal: 66097152, heapUsed: 51416176, external: 742988 } [2017-05-26 09:10:26.762] [WARN] log_file - wss.client5000 [2017-05-26 09:10:26.763] [WARN] log_file - client5000 [2017-05-26 09:10:26.763] [WARN] log_file - loginMap0 [2017-05-26 09:10:26.763] [WARN] log_file - timerMap5000 [2017-05-26 09:10:26.763] [WARN] log_file - { rss: 101851136, heapTotal: 66097152, heapUsed: 51416176, external: 742988 }

1 回复
回到顶部