Node real time debugging log

108 Views Asked by At

Im experiencing high latency during when Im benchmarking my web app. Usual response time is around 700ms but under heavy load, it climb to 15s. I want to debug where is the bottleneck.

Most basic method I think will help is to have something like superverbose output and there I can see in which part it freezes or spend most of the time. For now Im connected with node inspect and Im looping pause and cont to catch where we are at the moment but this is not enough. Is there some way to make all debuging output visible and forward it for example to file?

I know this will be huge amount of output.

UPDATE: Attaching screenshot of my desired verbouse output, this is what Im doing now with pause / cont but I want uninterupted flow of this output: enter image description here

1

There are 1 best solutions below

0
rrob On

So finally I ended with automation of my first method. I created expect script sending n (next step) 100000 times so it walks entire page load. First I need to pause whole page in different debuger window (do not close it because it resume execution on exit) node inspect localhost:9229 > debug> pause. And then I can run expect script (in new window) piped to file ./nodebuger.exp 2>&1 | tee -a node.log

#!/usr/bin/expect

spawn node inspect localhost:9229
expect "debug>"

set times 0;
while { $times < 100000 } {
    send -- "n\r"
    expect "debug"
    set times [ expr $times+1];
}

And there (after some cleanup), when I see bunch of lines with n character, I know that the previous step is still in progres (so its slow):

log output


Good article about How to enable debugger fast on any (also live) env without interupting: https://medium.com/the-node-js-collection/live-debugging-node-js-apps-at-the-command-line-cd5b58f883e1

$ ps aux | grep node
user 23254  0.0  0.0    0     0 ?        I    08:53   0:00 node /script.js
$ kill -SIGUSR1 23254 #this is not killing the process, just enabling debugger
$ node inspect -p 23254
or 
$ node inspect localhost:9229