13
votes

I was using decryption to decrypt "MySql" data. I got the below issue:

<--- Last few GCs --->
31681 ms: Mark-sweep 654.1 (666.5) -> 492.5 (509.8) MB, 267.5 / 0.0 ms [allocation failure] [GC in old space requested].
31839 ms: Mark-sweep 492.5 (509.8) -> 492.2 (506.8) MB, 157.5 / 0.0 ms [allocation failure] [GC in old space requested].
31985 ms: Mark-sweep 492.2 (506.8) -> 492.2 (497.8) MB, 146.2 / 0.0 ms [last resort gc]. 32122 ms: Mark-sweep 492.2 (497.8) -> 492.2 (497.8) MB, 136.8 / 0.0 ms [last resort gc]. <--- JS stacktrace --->

What is it regarding and how to fix it,

Thanks in advance

3
How big is the data you're trying to decrypt? You need to figure out what is using too much memory in your node.js app and/or, you need to increase the amount of memory you node.js app has available to it. FYI heap snapshots will help you figure out what your memory is being consumed by. - jfriend00

3 Answers

14
votes

Alllocate more memory to your script by using the following argument to node: --max_old_space_size=x

Example:

node --max_old_space_size=8000 yourscript.js

This will allocate about 8GB to your script. Eventually this is still not sufficient and you should decrypt your SQL in smaller chunks and make use of your physical drive instead of RAM memory.

Hope this helps!

3
votes

Proper solution

Something is using too much memory in your node.js app. This is usually bad sign and requires investigation in long term. To find out the exact piece of code, which does this - you may want to check out node.js profiling techniques. Some article about this https://nodejs.org/en/docs/guides/simple-profiling/

Fast solution

In some cases fast workaround is what we want. For such cases, as correctly pointed out by Cryptic Pug - we can increase JS memory allocation limit. There are few options how to do so (based on your needs)

  1. pass argument to node directly
    node --max_old_space_size=4096 app.js
    
  2. use environment variable
    NODE_OPTIONS=--max_old_space_size=4096
    node app.js
    
  3. use .npmrc file. Put following in .npmrc local or global file
    node-options=--max_old_space_size=4096
    
    and run your script
    node app.js
    
-1
votes

I had this problem but by removing globally installed electron and installing electron locally for my project this error disappears.