Node.js and V8 garbage collection

2019-02-01 01:48发布

问题:

Here's what's I've read so far, and correct me if I'm wrong:

  1. Node.js is based on V8 JavaScript engine.
  2. V8 JavaScript engine implements stop-the-world garbage collection

Which..causes Node.js to sometimes completely shutdown for a few seconds to a few minutes to handle garbage collection.

If this is running for production code, that's a few seconds for 10,000 users.

Is this really acceptable in production environment?

回答1:

Whether it is acceptable depends on your application and your heap size. Big Gc is around 1.3ms per Mbyte. YMMV. About half that for a compacting GC. Around 1 GC in 10 is big. Around 1 big GC in 3 is compacting. Use V8 flag --trace-gc to log GCs. We have done some work on reducing pauses. No promises, no timetables. See branches/experimental/gc in V8 repo.