Skip to content

Instantly share code, notes, and snippets.

@vNNi
Last active June 30, 2023 16:57
Show Gist options
  • Select an option

  • Save vNNi/3c4f50067d0b4532decc63fdc44c2337 to your computer and use it in GitHub Desktop.

Select an option

Save vNNi/3c4f50067d0b4532decc63fdc44c2337 to your computer and use it in GitHub Desktop.
NodeJs - Memory leak research

Memory Leak related links

For a further back and remember.

Stack overflow response of GC pause time

https://stackoverflow.com/questions/55985405/gc-taking-32-of-runtime-expected

Example of a leak and Heap explanation

https://www.dynatrace.com/news/blog/understanding-garbage-collection-and-hunting-memory-leaks-in-node-js/

Scavenge Algorithm pause time resolution

https://www.alibabacloud.com/blog/better-node-application-performance-through-gc-optimization_595119

How to debug NodeJS internals (backend) like a pro

  1. https://marmelab.com/blog/2018/04/03/how-to-track-and-fix-memory-leak-with-nodejs.html
  2. https://developer.chrome.com/docs/devtools/memory-problems/memory-101/

NodeJs internals and V8 garbage collect (with algorithm distinction)

https://medium.com/voodoo-engineering/nodejs-internals-v8-garbage-collector-a6eca82540ec

Memoize functions problems

https://community.risingstack.com/the-worlds-fastest-javascript-memoization-library/

How to test?

I have used a basic http.batch test from k6. After the basic setup, run the test like this (assuming you ares running in k6 docker):

docker run --add-host=host.docker.internal:host-gateway -i loadimpact/k6 run --vus 3 --duration 400s --user-agent="Mozilla/5.0 (Linux; U; Android 4.4.2; en-us; SCH-I535 Build/KOT49H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30" - <{{script-name}}.js

obs: the user-agent is to run like a mobile site.

So, afeter running one time, take one snapshot, repare the amount of memory(MB) used from the Heap, and run again. If the second Heap snapshot uses more memory (relevant one, not just 0.1MB), probably we have a leak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment