Inicio Facebook

Increasing serverless offline memory: prevent GC problems

serverless-offline can be an excellent complement to the development process when creating serverless applications without having to deploy them to test on AWS, for instance.

The big problem I've found is with it's memory leaks (not sure if it's with serverless or serverless-offline. If you have use it for rather intensive processes you may have found it tends to break while authorizing or responding multiple requests at the same time. For most of the times it is just a memory allocation problem. So if you, like me, are facing memory problems with serverless offline, this is how you can increase it's node process memory and enjoy a bit more resilience while developing.

node --max-old-space-size=4096 node_modules/serverless/bin/serverless offline start

Some messages you may have been getting:

<--- Last few GCs --->

[60975:0x102801e00]  1801853 ms: Mark-sweep 1393.3 (1468.7) -> 1393.3 (1469.2) MB, 792.2 / 0.0 ms  allocation failure GC in old space requested
[60975:0x102801e00]  1802586 ms: Mark-sweep 1393.3 (1469.2) -> 1393.3 (1438.2) MB, 732.7 / 0.0 ms  last resort GC in old space requested
[60975:0x102801e00]  1803468 ms: Mark-sweep 1393.3 (1438.2) -> 1393.3 (1438.2) MB, 882.2 / 0.0 ms  last resort GC in old space requested

<--- JS stacktrace --->

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

Security context: 0x3fdd9b625ee1 <JSObject>  
    2: _compile [module.js:~600] [pc=0x37e4c7895d70](this=0x3fdd161211c1 <Module map = 0x3fddafd402c1>,content=0x3fde03e02201 <Very long string[6933272]>,filename=0x3fdd74cf3839 <String[107]: /Users/walter/Development/<your project>/.webpack/service/src/handlers/environment.js>)
    4: .js [module.js:654] [bytecode=0x3fdd1b53c1b1 offset=50](this=0x3fddbf084569 <Object map =...

Walter Montes

Read more posts by this author.

San José, Costa Rica

Please Donate To Bitcoin Address: [[address]]

Donation of [[value]] BTC Received. Thank You.