-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
src,lib: use uv_thread_setname to a better multi-thread debugging #56416
base: main
Are you sure you want to change the base?
Conversation
Review requested:
|
The code generally looks fine to me.
The API to execute code in the the threadpool is uv_queue_work() but I don't think we want that. |
18c23f5
to
ad00536
Compare
@@ -1165,6 +1165,7 @@ InitializeOncePerProcessInternal(const std::vector<std::string>& args, | |||
} | |||
|
|||
if (!(flags & ProcessInitializationFlags::kNoInitializeNodeV8Platform)) { | |||
uv_thread_setname("MainThread"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if that's the best place to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, this looks great. I needed this for a while, but never took the time for the libuv PR.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #56416 +/- ##
==========================================
+ Coverage 89.20% 89.21% +0.01%
==========================================
Files 662 662
Lines 191899 191907 +8
Branches 36940 36944 +4
==========================================
+ Hits 171184 171217 +33
+ Misses 13546 13545 -1
+ Partials 7169 7145 -24
|
Waiting for libuv/libuv#4664 to land & release |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a couple of comments
and to the worker title for debugging/identification purposes, | ||
making the final title as `[worker ${id}] ${name}`. | ||
This parameter has a maximum allowed size, depending on the operating | ||
system. If the provided name exceeds the limit, it will be truncated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
system. If the provided name exceeds the limit, it will be truncated | |
system. If the provided name exceeds the limit, it will be truncated. |
This commit sets a default thread name whenever the inspector thread is created (InspectorIo)
a22bc75
to
4d6293c
Compare
Set the worker thread name using worker.name value and changing the default to "WorkerThread"
4d6293c
to
0e1e38e
Compare
This is now ready to go. PTAL @mcollina @santigimeno @jasnell |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still LGTM
Note: This PR depends libuv/libuv#4599 to be released by libuv team.
TODO:
I'm also patching uv to set the default thread name, but it's up to them to accept it, I don't know if there's a way from Node.js to access their thread or call an API to change their default thread nameDone in src: set a default thread name for workers libuv/libuv#4664worker.name
to set the thread name when a worker thread gets created (it defaults toWorkerThread
).cc: @santigimeno
With this PR users will be able to get a more meaningful diagnostic when looking at Node.js threads, for instance, they will be able to see on which thread their app is spending more time (libuv, workers, main thread...). See the image:
Consider the following server (please do not run it in production):
On Node.js startup if you monitor using
htop
you should be able to see:Then once it gets a request: