Configuring v8's memory management to be smart for a node.js process

前端 未结 1 1893
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 15:59

We run an XMPP server on node.js, on a machine with around 3.8 GB RAM. Here are the command line parameters we pass while invoking node : /opt/node/bin/node --max-old-spa

相关标签:
1条回答
  • 2020-12-07 16:21

    I think it is a limitation of V8. It does not use more than 1.7 GB of RAM on 64 bit machines. Quote from FAQ:

    Currently, by default v8 has a memory limit of 512mb on 32-bit systems, and 1gb on 64-bit systems. The limit can be raised by setting --max-old-space-size to a maximum of ~1gb (32-bit) and ~1.7gb (64-bit), but it is recommended that you split your single process into several workers if you are hitting memory limits.

    So following this you are hitting the maximum memory limits and the 10 second pause due to garbage collection is a big worry. You should consider running garbage collector periodically/when idle to avoid hitting the limit and facing long delays.

    Parameters which you can pass to help the situation are : (Check this blog)

    • --nouse-idle-notification which prevents running GC constantly and
    • --expose-gc which will allow you to run GC from your code.

    Most importantly debug your code to remove memory leaks. Use these package to find them in your code:

    • nodetime
    • node-inspector
    0 讨论(0)
提交回复
热议问题