Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs v8.getHeapStatistics method

Tags:

In nodejs v8 module, there's a function called getHeapStatistics which return an object that contains information about memory usage:

{    total_heap_size: 221540352,   total_heap_size_executable: 5242880,   total_physical_size: 221540352,   total_available_size: 1286110104,   used_heap_size: 189179192,   heap_size_limit: 1501560832,   malloced_memory: 16384,   peak_malloced_memory: 1325112,   does_zap_garbage: 0  } 

What's the meaning of each field?

like image 570
王如锵 Avatar asked Jan 09 '17 06:01

王如锵


People also ask

Does node still use v8?

V8 is Google's open source high-performance JavaScript and WebAssembly engine, written in C++. It is used in Chrome and in Node.

What does v8 do in node JS?

The V8 engine is what powers Node. js and it is an open-source engine on which even Chrome works. It parses and runs your JavaScript inside a Node environment.

What is Libuv in Nodejs?

libuv is a multi-platform C library that provides support for asynchronous I/O based on event loops. It supports epoll(4) , kqueue(2) , Windows IOCP, and Solaris event ports. It is primarily designed for use in Node. js but it is also used by other software projects.


2 Answers

Some good explanation from gc-heap-stats package:

  • total_heap_size: Number of bytes V8 has allocated for the heap. This can grow if usedHeap needs more.
  • used_heap_size: Number of bytes in used by application data
  • total_heap_size_executable: Number of bytes for compiled bytecode and JITed code
  • heap_size_limit: The absolute limit the heap cannot exceed (default limit or --max_old_space_size)
  • total_physical_size: Committed size

From Node.JS docs:

  • does_zap_garbage is a 0/1 boolean, which signifies whether the --zap_code_space option is enabled or not. This makes V8 overwrite heap garbage with a bit pattern. The RSS footprint (resident memory set) gets bigger because it continuously touches all heap pages and that makes them less likely to get swapped out by the operating system.

Self descriptive:

  • total_available_size: Available heap size
  • malloced_memory: current amount of memory, obtained via malloc
  • peak_malloced_memory: peak amount of memory, obtained via malloc
like image 108
Jehy Avatar answered Sep 18 '22 13:09

Jehy


There's V8 API documentation directly generated from the sources, but the details of HeapStatistics are not explained.

like image 25
user835611 Avatar answered Sep 18 '22 13:09

user835611