2

I am trying to analyse the Google CLoud Stackdriver's Profiling, now can anyone please tell me how can I Optimize my code by using this.

Also, I cannot see any of my function name and all, i don't know what is this _tickCallback and which part of the code it is executing ??

Please help me, anyone.

Profiling

Alexey Alexandrov
  • 2,951
  • 1
  • 24
  • 24
Sudhanshu Gaur
  • 7,486
  • 9
  • 47
  • 94

2 Answers2

6

When looking at node.js heap profiles, I find that it's really helpful to know if the code is busy and allocating memory (i.e. does a web server have a load?).

This is because the heap profiler takes a snap shot of everything that is in the heap at a the time of profile collection, including allocations which are not in use anymore, but have not been garbage collected.

Garbage collection doesn't happen very often if the code isn't allocating memory. So, when the code isn't very busy, the heap profile will show a lot of memory allocations which are in the heap but no longer really in use.

Looking at your flame graph, I would guess that your code isn't very busy (or isn't allocating very much memory), so memory allocations from the profiler dominate the heap profiles. If you're code is a web server and you profiled it when it didn't have a load, it may help if you generate a load for it while profiling.

nolanmar511
  • 116
  • 4
  • 1
    Additionally, it will help to ignore (using the filter: option in the control bar) profile, as that's the profiler agent itself running. This expands on mn573's answer, as the agent shouldn't be using much in terms of resources, so with low load it dominates the profile. – David Souther May 11 '18 at 15:46
  • 1
    Another possible challenge if you're using typescript -- the profiling agent does not have source map support, so function names will be the name of functions in the javascript that is compiled from the typescript, rather than the typescript functions. – nolanmar511 May 11 '18 at 16:40
4

To answer the secondary question: _tickCallback is a Node.js internal function that is used for running things on timers. For example, if anything is using a setTimeout. Anything that is scheduled on a timer would have _tickCallback on the bottom of the stack.

Elsewhere on the picture, you can see some green and cyan 'end' functions on the stack. I suspect those are the places where you are calling response.end in your express request handlers.