node.js process.memoryUsage()的返回值代表什么? [英] What do the return values of node.js process.memoryUsage() stand for?

查看:342
本文介绍了node.js process.memoryUsage()的返回值代表什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘自官方文档():

process.memoryUsage()

返回一个对象,该对象描述Node进程的内存使用情况 以字节为单位.

Returns an object describing the memory usage of the Node process measured in bytes.

var util = require('util');

console.log(util.inspect(process.memoryUsage()));

这将生成:

{ rss: 4935680, heapTotal: 1826816, heapUsed: 650472 }

heapTotal和heapUsed是指V8的内存使用情况.

heapTotal and heapUsed refer to V8's memory usage.

rss heapTotal heapUsed 到底代表什么?

Exactly what do rss, heapTotal, and heapUsed stand for?

这似乎是一个琐碎的问题,但是我一直在寻找,到目前为止我还没有找到明确的答案.

It might seem like a trivial question, but I've been looking and I could not find a clear answer so far.

推荐答案

要回答此问题,必须首先了解V8的内存方案.

In order to answer this question, one has to understand V8’s Memory Scheme first.

运行中的程序始终通过内存中分配的某些空间来表示.此空间称为居民集. V8使用类似于Java虚拟机的方案,并将内存分为以下部分:

A running program is always represented through some space allocated in memory. This space is called Resident Set. V8 uses a scheme similar to the Java Virtual Machine and divides the memory into segments:

  • 代码:正在执行的实际代码
  • 堆栈:包含所有值类型(诸如整数或布尔值之类的基元),其指针引用堆上的对象并定义程序控制流的指针
  • :专用于存储引用类型(如对象,字符串和闭包)的内存段.
  • Code: the actual code being executed
  • Stack: contains all value types (primitives like integer or Boolean) with pointers referencing objects on the heap and pointers defining the control flow of the program
  • Heap: a memory segment dedicated to storing reference types like objects, strings and closures.

现在很容易回答这个问题:

Now it is easy to answer the question:

  • rss :居民集大小
  • heapTotal :堆的总大小
  • heapUsed :实际使用的堆
  • rss: Resident Set Size
  • heapTotal: Total Size of the Heap
  • heapUsed: Heap actually Used

参考: 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆