home PYTHONJAVA
 

Node.js V8

What is V8

V8 is an open source JavaScript engine created by the Chromium venture for the Google Chrome internet browser. It is written in C++. Presently a days, it is utilized in numerous tasks, for example, Couchbase, MongoDB and Node.js.


V8 in Node.js

The Node.js V8 module represents to interfaces and event explicit to the rendition of V8. It gives techniques to get data about heap memory through v8.getHeapStatistics() and v8.getHeapSpaceStatistics() methods.

To utilize this module, you have to utilize require('v8').

  1. const v8 = require('v8');  

Node.js v8.getHeapStatistics() Example

The v8.getHeapStatistics() technique returns statistics about heap , for example, complete store measure, utilized stack estimate, heap estimate limit, total accessible size etc.

File: v8-example1.js

  1. const v8 = require('v8');  
  2. console.log(v8.getHeapStatistics());  

Node.js v8.getHeapSpaceStatistics() Example

The v8.getHeapSpaceStatistics() returns statistics about heap space. It returns an array of 5 objects: new space, old space, code space, map space and large object space. Each object contains information about space name, space size, space used size, space available size and physical space size.

File: v8-example2.js

  1. const v8 = require('v8');  
  2. console.log(v8.getHeapSpaceStatistics());  

Memory limit of V8 in Node.js

Currently, by default v8 has a memory limit of 512mb on 32-bit and 1gb on 64-bit systems. You can raise the limit by setting --max-old-space-size to a maximum of ~1gb for 32-bit and ~1.7gb for 64-bit systems. But it is recommended to split your single process into several workers if you are hitting memory limits.





welookups is optimized for learning.© welookups. 2018 - 2019 All Right Reserved and you agree to have read and accepted our term and condition.