Limit Node.js memory usage to less than 300MB per process

前端 未结 1 1572
猫巷女王i
猫巷女王i 2021-02-04 14:37

We run tests in separate processes and a few of our test suites contain more than 20 files. How can we limit (instead of increase) the amount of memory a Node.js process uses to

1条回答
  •  名媛妹妹
    2021-02-04 15:17

    Useful links:

    nodejs decrease v8 garbage collector memory usage

    https://groups.google.com/forum/#!topic/nodejs/IYsQ_bXlzcg

    https://www.quora.com/How-does-Node-js-do-memory-allocation

    Options to be considered:

    –nouse-idle-notification

    –expose-gc + gc() function from your code.

    –max-old-space-size

    –max-new-space-size

    --max-semi-space-size

    Also to decrease memory, less memory consuming algorithms can be used, the code can be more GC friendly. Also native C++ modules can help, but check them thoroughly for memory leaks and errors with some valgrind.

    Also quotes from OS can be applied to kill processes which exceed some memory limits.

    I know, without some concious option descriptions this answer is not so usefull, but I not very good learned them for now, so this "answer" is just a direction.

    0 讨论(0)
提交回复
热议问题