What do the return values of node.js process.memoryUsage() stand for?

后端 未结 4 1141
你的背包
你的背包 2020-12-07 09:51

From the official documentation (source):

process.memoryUsage()

Returns an object describing the memory usage of the Node

4条回答
  •  一个人的身影
    2020-12-07 10:06

    The Node.js doumentation describes it as follows:

    heapTotal and heapUsed refer to V8's memory usage. external refers to the memory usage of C++ objects bound to JavaScript objects managed by V8. rss, Resident Set Size, is the amount of space occupied in the main memory device (that is a subset of the total allocated memory) for the process, which includes the heap, code segment and stack.

    All mentioned values are expressed in bytes. So, if you just want to print them, you probably want to rescale them to MB:

    const used = process.memoryUsage();
    for (let key in used) {
      console.log(`Memory: ${key} ${Math.round(used[key] / 1024 / 1024 * 100) / 100} MB`);
    }
    

    That will give you an output like:

    Memory: rss 522.06 MB
    Memory: heapTotal 447.3 MB
    Memory: heapUsed 291.71 MB
    Memory: external 0.13 MB
    

提交回复
热议问题