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 BOOTSNAP_READONLY to Dockerfile template for production #50065

Conversation

technicalpickles
Copy link
Contributor

Motivation / Background

This was added in back in bootsnap 1.15.0 (Shopify/bootsnap#428). This can save extra work and IO when the cache won't be changed, like is the case for docker containers

Detail

This Pull Request changes the Dockerfile template used when creating a new application to add BOOTSNAP_READONLY=1

Additional information

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@rails-bot rails-bot bot added the railties label Nov 15, 2023
@byroot
Copy link
Member

byroot commented Nov 16, 2023

This shouldn't make much of a difference in this context, Docker preserve mtime so bootsnap shouldn't have anything to update.

But actually, would need to measure, but I suspect this is actually harmful because you set it before rake assets:precompile, so I suspect Bootsnap won't be able to persist its load path cache, marking the final image boot slower.

@technicalpickles
Copy link
Contributor Author

technicalpickles commented Nov 16, 2023

Someone pointed out that the ENV would need to go into final image 😅 I think that would mitigate the concern about precompile since it wouldn't be read-only until the image is run.

@byroot do you have any thoughts on how to measure the impact on this? Time to first request when running the docker image?

@byroot
Copy link
Member

byroot commented Nov 16, 2023

do you have any thoughts on how to measure the impact on this?

Yeah, just need time bin/rails runner 1 in production mode.

You can also set BOOTSNAP_LOG=1 to see if there is cache misses.

This was added in back in bootsnap 1.15.0 (Shopify/bootsnap#428).
This can save extra work and IO when the cache won't be changed, like is the case for docker containers
@byroot
Copy link
Member

byroot commented Jan 23, 2024

I've tested it and it drastically changes application boot time: down from near 2mn to 30s 😃

Edit: the app runs in Docker, on HDD drives

That's in "too good to be true" territory. Can you try just disabling Bootsnap to compare?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants