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 unit tests around WEB_CONCURRENCY #876

Merged

Conversation

michaelherold
Copy link
Contributor

This buildpack is inconsistent with the heroku/ruby buildpack's setting
of WEB_CONCURRENCY
. It tries to guess a reasonable value for
WEB_CONCURRENCY, even if one is set manually in the application's
configuration.

Since this value is used, by default, by the Puma web server, this
behavior is undesirable. Newer Rails applications use both the
heroku/nodejs buildpack and the heroku/ruby buildpack because Rails
manages assets through Webpack.

This change respects any value that the customer sets for
WEB_CONCURRENCY via heroku config:set instead of blindly overwriting
the value. With this behavior, the customer can better control the
process-level concurrency for their applications.

I verified that this behavior does, indeed, occur by doing the
following:

  1. heroku config:set WEB_CONCURRENCY=2 -a <myapp>
  2. heroku run -a <myapp> bash
  3. echo $WEB_CONCURRENCY

For step (3), the value was set to WEB_CONCURRENCY=1 instead of the
expected WEB_CONCURRENCY=2. I do not believe the buildpacks have an
order-dependence since the Ruby one does not override a set value.

@michaelherold michaelherold requested a review from a team as a code owner December 9, 2020 19:43
@michaelherold michaelherold force-pushed the prevent-clobber-of-web-concurrency branch 3 times, most recently from c98325e to 52ff595 Compare December 9, 2020 19:59
@michaelherold
Copy link
Contributor Author

It appears my understanding of what environment variables are set when you run a ps:exec was flawed. I see that none of the environment variables that you set in your application configuration are available. Thus, the unexpected behavior I was seeing wasn't correct.

I understand if this change isn't wanted, but it would be nice to see consistent behavior between different Heroku-created buildpacks. To me, the setting of the value unless it is already set leads to more understandability.

@dzuelke
Copy link
Contributor

dzuelke commented Dec 11, 2020

This is already the behavior:

concurrency=${WEB_CONCURRENCY-$(($available/$web_memory))}
sets the variable to the user-supplied value, then performs some sanity checks (too large or too small) on it.

Maybe keep the unit tests, they can't hurt, and remove the other two changes? ;)

@danielleadams
Copy link
Contributor

@michaelherold Thanks for the PR! As @dzuelke said, the extra coverage would be great if you could fix the tests. Otherwise, do you mind if we close this?

@michaelherold michaelherold force-pushed the prevent-clobber-of-web-concurrency branch from 52ff595 to d539e03 Compare December 22, 2020 21:25
@michaelherold michaelherold changed the title Do not override WEB_CONCURRENCY if set Add unit tests around WEB_CONCURRENCY Dec 22, 2020
@michaelherold
Copy link
Contributor Author

This is already the behavior:

🤦 So it is. It was very easy to miss that since it's hidden in the function. And since it does some checking against the value, my sentinel value was being ignored.

the extra coverage would be great if you could fix the tests.

I removed everything but the tests, but Hatchet is still failing to work correctly on CI. I don't know why that's happening.

@danielleadams
Copy link
Contributor

@michaelherold These are tests that we run internally to check integration with the Heroku platform. I recently moved the tests to Circle CI where I am not able to figure out how to run the test myself (they will continue to fail because you don't have access to the Heroku creds). If I can't figure this out, I'll open a pull request a run the tests on the next release. Thanks!

@danielleadams
Copy link
Contributor

@michaelherold Can you rebase this? I can merge it it once it matches the base branch. Thanks!

@danielleadams
Copy link
Contributor

@michaelherold can you rebase this?

WEB_CONCURRENCY should be allowed to be set prior to the `profile.d`
scripts running. This change adds tests to make sure we do not
accidentally clobber preset values.

These tests were extracted from a different change that duplicated
behavior for WEB_CONCURRENCY handling. See the [associated PR][1] for
more information around the discussion.

[1]: heroku#876
@michaelherold michaelherold force-pushed the prevent-clobber-of-web-concurrency branch from d539e03 to 2f28f2e Compare January 19, 2021 23:04
@michaelherold
Copy link
Contributor Author

michaelherold commented Jan 19, 2021 via email

@danielleadams danielleadams merged commit f18234d into heroku:main Jan 22, 2021
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.

3 participants