-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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. |
This commit sets a default thread name whenever the inspector thread is created (InspectorIo)
Set the worker thread name using worker.name value and changing the default to "WorkerThread"
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 88.53% 88.03% -0.50%
==========================================
Files 657 657
Lines 190719 190769 +50
Branches 36605 36311 -294
==========================================
- Hits 168848 167952 -896
- Misses 15040 15957 +917
- Partials 6831 6860 +29
|
doc/api/worker_threads.md
Outdated
* Maximum sizes: | ||
* Windows: 32,767 characters | ||
* macOS: 64 characters | ||
* Other systems: 16 characters | ||
**Default:** `'WorkerThread'`. |
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.
Here are the limits that libuv uses: libuv/libuv@61c966c#diff-633663e593ffc06d66dce99513aefc6db4b74ead8f760914d1e882e196bae225R431-R443
Note: This PR depends libuv/libuv#4599 to be released by libuv team.
TODO:
worker.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: