0

My nodejs script fails with following error,

<--- Last few GCs --->

[78:0x29f56b0]    31470 ms: Scavenge 2041.7 (2050.3) -> 2041.9 (2051.5) MB, 9.3 / 0.0 ms  (average mu = 0.231, current mu = 0.213) allocation failure 
[78:0x29f56b0]    31547 ms: Scavenge 2042.8 (2051.5) -> 2042.5 (2047.8) MB, 14.9 / 0.0 ms  (average mu = 0.231, current mu = 0.213) allocation failure 


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x134e879]
Security context: 0x01e8352c0919 <JSObject>
...

Now, I want to know the memory consumption by nodejs's V8 engine in runtime while my script is being executed. How can I do that ?

2

2 Answers 2

1

If you want to go with native nodejs solution you can use process.memoryUsage() function.

You can read more about it here.

I have written a small helper script for myself that returns formatted memory consumption that is easy to read (values are calculated to MBs):

function getMemory() {
    return Object.entries(process.memoryUsage()).reduce((carry, [key, value]) => {
        return `${carry}${key}:${Math.round(value / 1024 / 1024 * 100) / 100}MB;`;
    }, "");
};

The output of this function looks like this:

rss:282.61MB;heapTotal:239.46MB;heapUsed:129.36MB;external:22.13MB;
Sign up to request clarification or add additional context in comments.

Comments

0

if you want to check for global memeory go for

var os = require('os');

os.freemem();
os.totalmem();

or you want node specific then go for

memwatch-next

for tutorial click

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.