O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Neoito — JavaScript memory leaks

When a computer program incorrectly manages memory allocations so that the memory that is no longer needed is not released.

  • Seja o primeiro a comentar

Neoito — JavaScript memory leaks

  1. 1. Memory Leaks Deepak.S
  2. 2. 😏The name says it all………………... When a computer program incorrectly manages memory allocations so that the memory that is no longer needed is not released Symptoms🚑 =>CPU usage, and the load average of the host machine increase over time without any so called reason =>When my Cool Project Manager is not satisfied with Production matrix 😢
  3. 3. 😰But i thought JS had a GC…….! =>Data types( Boolean,String,num,Object) =>Looks for the objects that are no longer part of the root node =>V8 assumes as garbage ,collects and releases the m/y (GC)
  4. 4. A Object’s retaining tree…….
  5. 5. 😍V8 memory schema =>Node process in RAM =>Stack num,variable =>Heap (m/y leak)
  6. 6. 💫Example 1 app.get(’/’,(req,res)=>{ const garbage = new Array(1000); //big array of size 1000 allocated res.status(200).send(’hello world’); //not holding on to this object }) ; //so it is GC by V8
  7. 7. 💫Example 2 app.get(’/’,(req,res)=>{ req. garbage = new Array(1000); res.status(200).send(’hello world’); }) ; =>attaching to the req object =>checks req and gives res - express =>req is done ,all references to it will be thrown =>req are short lived
  8. 8. 💫Example 3 const requests = new map(); app.get(’/’,(req,res)=>{ requests.set(req.id,req) res.status(200).send(’hello world’); }) ; =>Expected SL attached to LL =>Requests are expected to be short lived =>Top level map lives forever => if a req come it is attached to requests object =>15,000 req will be leaked from server if made
  9. 9. Let’s go find a leak…………..💀
  10. 10. So do i have to manually snapshot it🙍!
  11. 11. Things to consider……. 😳Snapshots are expensive on CPU and memory 😣Comment out all console.logs in server because it can increase memory 😺Consider other simpler ways of tracking memory like node --trace-gc index.js 😲Open Source app performance monitoring tools for server such as NewRelic, Elastic APM Click here 📷 Click here 📖
  12. 12. 😏 😏 😏 😏 😏 😏…………………………………………………………. Thanks

×