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

add RAILS_MIN_THREADS, RAILS_MAX_THREADS, set default worker, preload… #2143

Merged
merged 17 commits into from Apr 21, 2020

Conversation

@jalevin
Copy link
Contributor

jalevin commented Mar 2, 2020

… if using workers

Description

closes #1949

Please describe your pull request. Thank you for contributing! You're the best.

Your checklist for this pull request

  • [ x] I have reviewed the guidelines for contributing to this repository.
  • I have added an entry to History.md if this PR fixes a bug or adds a feature. If it doesn't need an entry to HISTORY.md, I have added [changelog skip] the pull request title.
  • [ x] I have added appropriate tests if this PR fixes a bug or adds a feature.
  • [ x] My pull request is 100 lines added/removed or less so that it can be easily reviewed.
  • If this PR doesn't need tests (docs change), I added [ci skip] to the title of the PR.
  • If this closes any issues, I have added "Closes #issue" to the PR description or my commit messages.
  • I have updated the documentation accordingly.
  • All new and existing tests passed, including Rubocop.
jalevin added 2 commits Mar 2, 2020
History.md Outdated Show resolved Hide resolved
History.md Outdated Show resolved Hide resolved
lib/puma/configuration.rb Outdated Show resolved Hide resolved
lib/puma/configuration.rb Outdated Show resolved Hide resolved
@nateberkopec
Copy link
Member

nateberkopec commented Mar 2, 2020

My guess on test failures would be that they're related to the change of changing the default from single mode to cluster mode, which I'm not even sure is a good idea.

Copy link
Contributor Author

jalevin left a comment

Is cluster mode enabled changing the number of workers from 0 to 1 ?

lib/puma/configuration.rb Outdated Show resolved Hide resolved
History.md Outdated Show resolved Hide resolved
@olleolleolle
Copy link
Contributor

olleolleolle commented Mar 2, 2020

I liked the PUMA_MIN_THREADS naming.

Would it be easier to create this PR if it was only about the ENV vars, and left out the other stuff? Could make this change smaller and easier to review.

PS: this is awesome, thanks for taking the time to work on it!

@nateberkopec
Copy link
Member

nateberkopec commented Mar 2, 2020

I'm fine with the size-factor of this PR. Need to think about the Single vs Cluster for MRI thing.

@dentarg
Copy link
Contributor

dentarg commented Mar 2, 2020

Regarding "changing the default from single mode to cluster mode", I assume it would be a change for Puma 5, but nonetheless I guess the before_fork stuff (e.g. you should do DB.disconnect) could be a surprise for people running the default and not knowing about cluster mode.

@nateberkopec
Copy link
Member

nateberkopec commented Mar 5, 2020

OK. Let's keep Puma in singlemode by default. No need to force cluster by changing workers to 1. With that plus the other changes outlined above, LGTM.

jalevin added 4 commits Mar 2, 2020
@jalevin
Copy link
Contributor Author

jalevin commented Mar 9, 2020

FYI: test/test_config.rg:43 is a flaky test. I need to research this more, but randomly config returns 2 instead of 0. I'm not sure if that is coming from a test helper or something

@jalevin
Copy link
Contributor Author

jalevin commented Mar 9, 2020

Builds failing with TimeoutEveryTestCase::TestTookTooLong: execution expired...

History.md Outdated Show resolved Hide resolved
lib/puma/configuration.rb Outdated Show resolved Hide resolved
jalevin added 4 commits Apr 13, 2020
… fix_up_config_defaults
@@ -137,6 +137,12 @@ def initialize(user_options={}, default_options = {}, &block)
@file_dsl = DSL.new(@options.file_options, self)
@default_dsl = DSL.new(@options.default_options, self)

workers_supported = !(Puma.jruby? || Puma.windows?)

This comment has been minimized.

Copy link
@nateberkopec

nateberkopec Apr 20, 2020

Member

Check ::Process.respond_to? :fork instead.

This comment has been minimized.

Copy link
@nateberkopec

nateberkopec Apr 20, 2020

Member

Also no need to assign to a variable, just put it on line 143

@@ -167,14 +173,20 @@ def flatten!
self
end

def default_max_threads
return 5 if Puma.mri?

This comment has been minimized.

Copy link
@nateberkopec

nateberkopec Apr 20, 2020

Member

I would prefer a ternary here instead of return.

lib/puma/configuration.rb Outdated Show resolved Hide resolved
conf = Puma::Configuration.new
assert_equal 0, conf.options.default_options[:min_threads]

ENV['MIN_THREADS'] = '7'

This comment has been minimized.

Copy link
@nateberkopec

nateberkopec Apr 20, 2020

Member

Setting a global and running tests in parallel threads, you're gonna have a Bad Time (as you've seen on your tests).

Maybe just removing parallelize_me will fix everything here. Put these tests into a separate test class which is not paralellized.

This comment has been minimized.

Copy link
@jalevin

jalevin Apr 20, 2020

Author Contributor

Doesn't look like removing parallelize_me! works here. Any other ideas?

This comment has been minimized.

Copy link
@jalevin

jalevin Apr 20, 2020

Author Contributor

Scratch that- extrapolated into it's own class and used the with_env helper. All seems fine.

Copy link
Member

nateberkopec left a comment

A few suggestions

@ukolovda

This comment has been minimized.

Copy link

ukolovda commented on test/test_config.rb in e552e6c Apr 20, 2020

Should we use PUMA_PAX_THREADS instead MAX_THREADS on line 311?

This comment has been minimized.

Copy link
Contributor Author

jalevin replied Apr 20, 2020

Yep, thanks.

@jalevin
Copy link
Contributor Author

jalevin commented Apr 20, 2020

@nateberkopec @ukolovda It looks like truffleruby does not support forking. Does this mean that truffle also does not support workers?

@@ -109,7 +109,7 @@ def in_background(&blk)
end

def workers_supported?

This comment has been minimized.

Copy link
@jalevin

jalevin Apr 20, 2020

Author Contributor

This method feels like it should be in the lib/puma/detect.rb

This comment has been minimized.

Copy link
@jalevin
@@ -109,7 +109,7 @@ def in_background(&blk)
end

def workers_supported?
return false if Puma.jruby? || Puma.windows?
return false if Puma.jruby? || Puma.windows? || Puma.truffle?

This comment has been minimized.

Copy link
@jalevin

jalevin Apr 20, 2020

Author Contributor

should we check ::Process.respond_to?(:fork) as well?
Does that single check eliminate the need to check for jruby/windows/truffle?

This comment has been minimized.

Copy link
@jalevin

This comment has been minimized.

Copy link
@nateberkopec

nateberkopec Apr 22, 2020

Member

Fixed in my nitpick commit. Thanks for the work on this PR!

This comment has been minimized.

Copy link
@jalevin

jalevin Apr 22, 2020

Author Contributor

Sweet!

@nateberkopec nateberkopec merged commit dc3b9b8 into puma:master Apr 21, 2020
26 of 27 checks passed
26 of 27 checks passed
ubuntu 2.2
Details
build
Details
ubuntu 2.3
Details
ubuntu 2.4
Details
ubuntu 2.5
Details
ubuntu 2.6
Details
ubuntu 2.7
Details
ubuntu head
Details
ubuntu jruby
Details
ubuntu truffleruby-head
Details
macos 2.2
Details
macos 2.3
Details
macos 2.4
Details
macos 2.5
Details
macos 2.6
Details
macos 2.7
Details
macos head
Details
macos jruby macos jruby
Details
macos truffleruby-head
Details
windows 2.2
Details
windows 2.3
Details
windows 2.4
Details
windows 2.5
Details
windows 2.6
Details
windows 2.7
Details
windows mingw
Details
ubuntu jruby-head ubuntu jruby-head
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants
You can’t perform that action at this time.