--max-semi-space-size=SIZE(以兆字节为单位)


为 V8 的清除垃圾收集器设置最大的半空间大小,以 MiB(兆字节)为单位。 增加半空间的最大尺寸可能会提高 Node.js 的吞吐量,但会消耗更多内存。

由于 V8 堆的年轻代大小是半空间大小的三倍(参见 V8 中的 YoungGenerationSizeFromSemiSpaceSize),因此半空间增加 1 MiB 适用于三个单独的半空间中的每一个,并导致堆大小增加 3 MiB。 吞吐量的提高取决于您的工作负荷(参见 #42511)。

64 位系统的默认值为 16 MiB,32 位系统的默认值为 8 MiB。 要为您的应用程序获得最佳配置,您应该在为您的应用程序运行基准测试时尝试不同的 max-semi-space-size 值。

例如,在 64 位系统上进行基准测试:

for MiB in 16 32 64 128; do
    node --max-semi-space-size=$MiB index.js
done

Sets the maximum semi-space size for V8's scavenge garbage collector in MiB (megabytes). Increasing the max size of a semi-space may improve throughput for Node.js at the cost of more memory consumption.

Since the young generation size of the V8 heap is three times (see YoungGenerationSizeFromSemiSpaceSize in V8) the size of the semi-space, an increase of 1 MiB to semi-space applies to each of the three individual semi-spaces and causes the heap size to increase by 3 MiB. The throughput improvement depends on your workload (see #42511).

The default value is 16 MiB for 64-bit systems and 8 MiB for 32-bit systems. To get the best configuration for your application, you should try different max-semi-space-size values when running benchmarks for your application.

For example, benchmark on a 64-bit systems:

for MiB in 16 32 64 128; do
    node --max-semi-space-size=$MiB index.js
done