Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

yvasiyarov
Copy link
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
Collaborator

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
Collaborator

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
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
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
Contributor Author

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

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.

2 participants