-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
multi-thread support proposal #20239
Comments
Yes, that would be a neat thing for Node to support anyway – we should definitely allow embedders and addons to use Node.js in multiple threads, whether that’s for Workers or not 👍
Yes, and I’m not happy about that either – But the current main obstacle is pretty well-defined: Edge cases in old Windows code in libuv. So, if we were to say that not supporting Windows to begin with is an option, we could actually move forward now. I mean, I’m glad about concrete suggestions or help. But it probably is worth pointing out that working Worker code for Node does exist at this point. |
Also, I’ve been mentioning it in the TSC meetings, and I know @mhdawson was trying to reach out to MS people – if you know somebody who is somewhat familiar with debugging Node.js and in particular libuv on Windows, and is familiar with async I/O using the Windows C API, that might be all we need to bring #19377 over the line. (Even without the PR, those seem to be real bugs on Windows to begin with – they just don’t manifest themselves yet.) |
@aruneshchandra ,@digitalinfinity any help on the windows side for #19377 would be greatly appreciated. |
I've picked up #19377, I'm investigating it right now. |
@addaleax I would like to contribute to the part "Enable multi-thread capability for addon". There are 2 changes need to be done:
For the first one I believe I can find some implementation from Ayo.js. hope this can help |
@fs-eire Yes, I agree with 100 % of what you just said. :) The patch is probably outdated compared to nodejs/node@master, but you could find relevant pieces in ayojs/ayo#118 for the dynamic library stuff. Also, PRs you might want to be aware of:
|
@fs-eire I'd suggest you attend the next N-API meeting (Thursday at 1:30 EST, Description:https://hangouts.google.com/hangouts/_/event/c0eevtrlajniu7h8cjrdk0f56c8) to kick off the discussion with the N-API team. (I'm hoping that time works for you) |
Allow loading add-ons from multiple Node.js instances if they are declared context-aware; in particular, this applies to N-API addons. Also, plug a memory leak that occurred when registering N-API addons. Refs: #23319 PR-URL: #26175 Fixes: #21481 Fixes: #21783 Fixes: #25662 Fixes: #20239 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Allow loading add-ons from multiple Node.js instances if they are declared context-aware; in particular, this applies to N-API addons. Also, plug a memory leak that occurred when registering N-API addons. Refs: #23319 PR-URL: #26175 Fixes: #21481 Fixes: #21783 Fixes: #25662 Fixes: #20239 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Multi-thread support in Node.js is not a new requirement. There was a previous proposal #13143 trying to bring multi-threading capability to node, and there are several projects outside node doing this effort as listed here as well.
The worker proposal, however, seems not go smoothly. I consider one of the reasons is because the change turns out to be too huge. I would like to share another approach of bringing multi-thread capability into node.
The basic idea is to break the work into several stages -
1. Enable multi-thread capability for addon.
2. Enable node API in multi-thread incrementally.
3. Add multi-thread node API when we think it's ready.
The first step is to enable multi-thread capability for addon, that is to say, to make it possible in addon to create another javascript thread which applies node's context. To achieve this, node's initialization and module loader need to be updated multi-thread readiness. Native API/napi should also be updated to expose necessary information.
The next step is to tune node API so that they can be helpful in multi-thread. There can be a lot of discussions and decision making, like -
ArrayBuffer
bySharedArrayBuffer
We are not going to do all those on once. They can be separated to small and independent problems.
The final step is like a natural result, when dependencies and blocking issues are resolved.
The advantage of this approach is, we will not break any feature, or add incomplete feature in every step, while we can keep every changes small and clean. Enabling multi-thread for addon also enables addon developers explore and discover use cases and problems that may happen. JS users should not be affected since no new APIs are exposed before stage (3).
/cc @addaleax @Trott @bnoordhuis @jasnell
The text was updated successfully, but these errors were encountered: