Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: No such label 'RESPONSE TIME' for console.timeEnd()

Situation:

I have a Node.js api that is called many times a second on a website. I am using console.time('RESPONSE TIME') and console.timeEnd('RESPONSE TIME') to measure how long the api is taking to respond to the client on to each request. Inside of the api, I am using a Promise.all() to aggregate responses from 4 different api's and then return a final response based on what the 4 apis returned.

Issue:

Everything works as expected except for an occasional warning logged Warning: No such label 'RESPONSE TIME' for console.timeEnd(). Why is this and how do I properly avoid this?

I speculate that it's because Node is asynchronous and while one request may still be waiting for it's 4 api's to respond, another request will have finished and hit the console.timeEnd() ending both timers since they share the same name. But I can't find an answer anywhere.

like image 207
Ryan Walker Avatar asked May 21 '19 19:05

Ryan Walker


1 Answers

Your speculation is correct, you should have a unique label name for every api call. Assuming every request has a unique identifier stored in req.id you can use the following:

console.time(`RESPONSE TIME request ${req.id}`)
// await api call
console.timeEnd(`RESPONSE TIME request ${req.id}`)
like image 199
Rayee Roded Avatar answered Oct 16 '22 20:10

Rayee Roded