Skip to content

feat: implement monitoring of callbacks executed by process.nextTick()#277

Closed
yvasiyarov wants to merge 10 commits into
prometheus:mainfrom
yvasiyarov:tick
Closed

feat: implement monitoring of callbacks executed by process.nextTick()#277
yvasiyarov wants to merge 10 commits into
prometheus:mainfrom
yvasiyarov:tick

Conversation

@yvasiyarov

Copy link
Copy Markdown
Contributor

Nearly every talk about Node.js performance begins with event loop monitoring.
And one of most often recommendation is - do not run cpu intensive operations in nextTick().
So I thought it will be useful to measure how long does it takes to execute every single callback scheduled by nextTick() and how many ticks are being executed by nextTick().

To make this information actionable I also wanna implement some way to export top longest callbacks executed by nextTick() or somehow export callbacks which executes longer than some threshold. But it's not implemented yet. Any suggestions how this kind of information can be exported to prometheus are welcome :-)

@zbjornson

Copy link
Copy Markdown
Contributor

This is an interesting metric! Do you have any estimate of how much overhead it adds to the running process (performance impact)? Wondering if it should be opt-in/a separate custom metric.

@zbjornson

Copy link
Copy Markdown
Contributor

I also wanna implement some way to export top longest callbacks executed by nextTick() or somehow export callbacks which executes longer than some threshold

I don't think this is possible when there are multiple callbacks running (which is basically always for a real production server). Callback A will delay callback B and all subsequent callbacks that were scheduled in the current event loop iteration, so it wouldn't be an accurate measurement, I think. You'd probably have to track execution time of the callback handlers more likely, which would be hard.

@yvasiyarov

Copy link
Copy Markdown
Contributor Author

This is an interesting metric! Do you have any estimate of how much overhead it adds to the running process (performance impact)? Wondering if it should be opt-in/a separate custom metric.

I don't have numbers in my hands, but anyway I think its a good idea to make it opt-in. Will implement it today

@yvasiyarov

Copy link
Copy Markdown
Contributor Author

I also wanna implement some way to export top longest callbacks executed by nextTick() or somehow export callbacks which executes longer than some threshold

I don't think this is possible when there are multiple callbacks running (which is basically always for a real production server). Callback A will delay callback B and all subsequent callbacks that were scheduled in the current event loop iteration, so it wouldn't be an accurate measurement, I think. You'd probably have to track execution time of the callback handlers more likely, which would be hard.

I separately measure execution of every callback. So execution time of callback A measured separately from callback B.

@yvasiyarov

Copy link
Copy Markdown
Contributor Author

@zbjornson I've made monitoring of process.nextTick optional, disabled by default.

@jdmarshall

Copy link
Copy Markdown
Contributor

#518 is a better option here, now.

@jdmarshall jdmarshall closed this Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants