Skip to content

Conversation

@dygabo
Copy link
Member

@dygabodygabo commented Apr 26, 2024

This implements reusing the single esm loader hooks thread for all the subsequent workers.
It started as a trial to solve the test contributed by @GeoffreyBooth from #50752. The test content is taken over from that branch and only slightly modified to also support transitive worker threads (that are started by some worker and not by the main thread). This is probably a not very common use case but the interface supports it so I put in the test as well.

With this initial commit all tests are passing.

[==========] 157 tests from 28 test suites ran. (2328 ms total) [ PASSED ] 157 tests. make -s jstest ninja: Entering directory `out/Release' ninja: no work to do. [04:49|% 100|+ 4095|- 0]: Done All tests passed. 

Let's start a discussion and if there are additional usages that are missed by the implementation or if something needs improvements, let me know. If the implementation matches the expectations, we could close the test-only PR and continue the discussion here. Let me know your thoughts.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-botnodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Apr 26, 2024
@FlarnaFlarna added module Issues and PRs related to the module subsystem. loaders Issues and PRs related to ES module loaders labels Apr 26, 2024
@dygabodygaboforce-pushed the spawn-only-one-loader-thread branch from 1025b03 to fa24d02CompareApril 26, 2024 14:03
@dygabodygabo marked this pull request as draft April 26, 2024 14:08
@dygabodygaboforce-pushed the spawn-only-one-loader-thread branch from fa24d02 to ee16c17CompareApril 26, 2024 14:21
@targos
Copy link
Member

@nodejs/loaders

Copy link
Member

@GeoffreyBoothGeoffreyBooth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@GeoffreyBoothGeoffreyBooth marked this pull request as ready for review April 26, 2024 15:50
@dygabodygaboforce-pushed the spawn-only-one-loader-thread branch from 03f69a8 to 2fdf7b3CompareApril 27, 2024 04:57
Copy link
Member

@JakobJingleheimerJakobJingleheimer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yahoo! 🙌 great work @dygabo. thank you for this!

a few nits, and a couple small tweaks requested.

dygabo

This comment was marked as resolved.

Copy link
Member

@JakobJingleheimerJakobJingleheimer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

@dygabo
Copy link
MemberAuthor

I added a testcase for a scenario where a worker thread import operation would call process.exit. I.e.

  • the main thread imports some module that creates a Worker thread
  • the Worker thread script imports a module => this gets delegated to the single hook thread
  • on the hooks thread this causes a process.exit
  • this process.exit now gets propagated to main thread and all workers.

I think this is a change in behavior compared to the previous version. Is this scenario covered correctly now? Is this an acceptable change in behavior?
If not, can this be covered with a follow-up or should it be covered here?

@dygabodygaboforce-pushed the spawn-only-one-loader-thread branch from bb59bc8 to 7f86cdeCompareApril 29, 2024 11:22
@dygabodygabo changed the title esm: have a single hooks thread for all workersmodule: have a single hooks thread for all workersApr 29, 2024
port2: toHooksThread,
}=newMessageChannel();
if(!isInternal){
// This is not an internal hooks thread => it needs a channel to the hooks thread:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the isInternal flag only used by hooks thread?
if yes, the name should be likely changed (maybe in a followup).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently but not inherently limited to

Copy link
Member

@bmeckbmeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a great improvement! cheers

@FlarnaFlarna added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 30, 2024
@FlarnaFlarna added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 30, 2024
@GeoffreyBoothGeoffreyBooth added the commit-queue Add this label to land a pull request using GitHub Actions. label May 8, 2024
@nodejs-github-botnodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels May 8, 2024
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/52706 ✔ Done loading data for nodejs/node/pull/52706 ----------------------------------- PR info ------------------------------------ Title module: have a single hooks thread for all workers (#52706) ⚠ Could not retrieve the email or name of the PR author's from user's GitHub profile! Branch dygabo:spawn-only-one-loader-thread -> nodejs:main Labels module, lib / src, needs-ci, loaders, commit-queue-squash Commits 13 - module: have a single hooks thread for all workers - Update lib/internal/modules/esm/loader.js - Apply suggestions from code review - Apply suggestions from code review - code review suggestions addressed - cache response message on exit - add test for process.exit for import running for worker thread - implement unregistration of workers from the hooks thread upon exit - address review finding - fix comment - fix or skip tests that are not fit for running on worker threads - fix flaky test with debug build - fixup! fix flaky test with debug build Committers 1 - Gabriel Bota PR-URL: https://github.com/nodejs/node/pull/52706 Reviewed-By: Geoffrey Booth Reviewed-By: Jacob Smith Reviewed-By: Antoine du Hamel Reviewed-By: Gerhard Stöbich ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/52706 Reviewed-By: Geoffrey Booth Reviewed-By: Jacob Smith Reviewed-By: Antoine du Hamel Reviewed-By: Gerhard Stöbich -------------------------------------------------------------------------------- ⚠ Commits were pushed since the last approving review: ⚠ - module: have a single hooks thread for all workers ⚠ - Update lib/internal/modules/esm/loader.js ⚠ - Apply suggestions from code review ⚠ - Apply suggestions from code review ⚠ - code review suggestions addressed ⚠ - cache response message on exit ⚠ - add test for process.exit for import running for worker thread ⚠ - implement unregistration of workers from the hooks thread upon exit ⚠ - address review finding ⚠ - fix comment ⚠ - fix or skip tests that are not fit for running on worker threads ⚠ - fix flaky test with debug build ⚠ - fixup! fix flaky test with debug build ℹ This PR was created on Fri, 26 Apr 2024 13:22:51 GMT ✔ Approvals: 4 ✔ - Geoffrey Booth (@GeoffreyBooth) (TSC): https://github.com/nodejs/node/pull/52706#pullrequestreview-2025361284 ✔ - Jacob Smith (@JakobJingleheimer): https://github.com/nodejs/node/pull/52706#pullrequestreview-2026747841 ✔ - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/52706#pullrequestreview-2026755507 ✔ - Gerhard Stöbich (@Flarna): https://github.com/nodejs/node/pull/52706#pullrequestreview-2040506445 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2024-05-08T00:05:42Z: https://ci.nodejs.org/job/node-test-pull-request/59022/ - Querying data for job/node-test-pull-request/59022/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/8995057971

@GeoffreyBoothGeoffreyBooth added commit-queue Add this label to land a pull request using GitHub Actions. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels May 8, 2024
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label May 8, 2024
@nodejs-github-botnodejs-github-bot merged commit 22cb99d into nodejs:mainMay 8, 2024
@nodejs-github-bot
Copy link
Collaborator

Landed in 22cb99d

@dygabodygabo deleted the spawn-only-one-loader-thread branch May 8, 2024 04:13
targos pushed a commit that referenced this pull request May 8, 2024
PR-URL: #52706 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]>
@targostargos mentioned this pull request May 13, 2024
@mcollinamcollina added dont-land-on-v18.x dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. labels May 28, 2024
@mcollina
Copy link
Member

I've added dont-land-on-v18.x and dontt-land-on-v20.x given how breaking this is.

@dygabodygabo restored the spawn-only-one-loader-thread branch June 3, 2024 16:40
sophoniie pushed a commit to sophoniie/node that referenced this pull request Jun 20, 2024
PR-URL: nodejs#52706 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]>
bmeck pushed a commit to bmeck/node that referenced this pull request Jun 22, 2024
PR-URL: nodejs#52706 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit-queue-squashAdd this label to instruct the Commit Queue to squash all the PR commits into the first one.dont-land-on-v20.xPRs that should not land on the v20.x-staging branch and should not be released in v20.x.lib / srcIssues and PRs related to general changes in the lib or src directory.loadersIssues and PRs related to ES module loadersmoduleIssues and PRs related to the module subsystem.needs-ciPRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@dygabo@nodejs-github-bot@targos@Flarna@aduh95@mcollina@bmeck@GeoffreyBooth@benjamingr@JakobJingleheimer