简体   繁体   English

禁用node.js垃圾回收一段时间

[英]Disable node.js garbage collection for a while

Is there any way to explicitly disable GC runs (at least most time-consuming ones, like GC interrupts in old space) during the specified period of time, while executing some code sensitive to delays? 有没有办法在指定的时间段内显式禁用GC运行(至少大多数耗时的运行,如旧空间中的GC中断),同时执行一些对延迟敏感的代码? Something like this: 像这样的东西:

disableGc();
runCodeWithoutDelays();
enableGc();

Probably using some node options, or native modules? 可能使用某些节点选项或本机模块? Or can I write my own module, is there an API in V8 for that? 或者我可以编写自己的模块,V8中是否有API用于此?

据我所知,你无法手动停止v8的垃圾收集器,你唯一能做的就是手动运行global.gc()启动gc进程,但不要停止v8的进程。

Another person had the same question and published an issue on GitHub here: https://github.com/nodejs/help/issues/462 另一个人有同样的问题,并在GitHub上发布了一个问题: https//github.com/nodejs/help/issues/462

Answer is you can't disable the GC in Node, but you can at least tweak the memory options to use the max space available and delay GC, by using --max_old_space_size, --max-semi-space-size. 答案是您无法在节点中禁用GC,但您可以通过使用--max_old_space_size, - max-semi-space-size来至少调整内存选项以使用可用的最大空间并延迟GC。

An example is provided there in context. 在上下文中提供了一个示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM