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

Spawn molds instead of promoting workers #42

Merged
merged 1 commit into from
Apr 6, 2023
Merged

Conversation

casperisfine
Copy link
Contributor

@casperisfine casperisfine commented Apr 5, 2023

The big benefit is we no longer reduce capacity when a promotion is happening.

The downside is that complexity is a bit increased.

Another important change is that since we fork, the various Process._fork callbacks will be invoked. For some it will be a positive (e.g. dropped connections), for others it may be somewhat negative (e.g. restarted background threads).

This was suggested by @matthewd.

@casperisfine casperisfine force-pushed the fork-on-promotion branch 3 times, most recently from f95b564 to 7ff0f0b Compare April 5, 2023 13:57
@casperisfine casperisfine marked this pull request as ready for review April 5, 2023 13:58
Copy link
Contributor

@paarthmadan paarthmadan left a comment

Choose a reason for hiding this comment

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

Cool, neat idea

```

When a reforking is triggered, one of the workers is selected to become a `mold`, and is taken out of rotation.
Once the `mold` is done loading, the `master` ask it to spawn the desired number of workers:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Once the `mold` is done loading, the `master` ask it to spawn the desired number of workers:
Once the `mold` is done loading, the `master` asks it to spawn the desired number of workers:

```

When a reforking is triggered, one of the workers is selected to become a `mold`, and is taken out of rotation.
Once the `mold` is done loading, the `master` ask it to spawn the desired number of workers:

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you're missing the ``` backticks to start the codeblock

refute_nil second_mold
assert_equal 42, second_mold.pid

assert_equal [first_mold, second_mold], @children.molds
Copy link
Contributor

Choose a reason for hiding this comment

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

It's possible I've misunderstood the intent, but this test doesn't explicitly reap any molds, it seems to assert that when a new mold is spawned, the @mold replaces the old with the new.

Should we change the name of the test or perhaps add something like:

diff --git a/test/unit/test_children.rb b/test/unit/test_children.rb
index b0313bc2..34808f67 100644
--- a/test/unit/test_children.rb
+++ b/test/unit/test_children.rb
@@ -78,6 +78,11 @@ def test_reap_old_molds
       assert_equal 42, second_mold.pid
 
       assert_equal [first_mold, second_mold], @children.molds
+
+      @children.reap(24)
+
+      assert_equal [second_mold], @children.molds
+      assert_equal second_mold, @children.mold
     end
 
     def test_reap_pending_mold

@casperisfine
Copy link
Contributor Author

Thanks @paarthmadan, all good points.

The big benefit is we no longer reduce capacity when a promotion is
happening.

The downside is that complexity is a bit increased.
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.

None yet

3 participants