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
Improve ActiveStorage asset linking performance #12576
Open
ahukkanen
wants to merge
42
commits into
develop
Choose a base branch
from
fix/storage-service-uris
base: develop
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use direct links to the assets living at storage services in order to push most of the application load to the storage service instead of the website itself.
ahukkanen
added
module: core
module: admin
team: performance
module: system
status: WIP
module: assemblies
module: blogs
module: participatory processes
module: conferences
module: initiatives
type: fix
PRs that implement a fix for a bug
labels
Mar 7, 2024
The image variants need to be processed through the local representation URLs when they are served the first time because this is when these assets are processed for the first time. These changes detect if the variant needs processing and serves it through the local representation URL before the image has been processed. If the image is already processed it is served directly through the storage service itself.
- Fix the storage asset specs to match the current implementation - Add more tests to test the router under different configurations and options - Add an RSpec support utility to define the storage host when the storage URLs are tested outside of a request context
In order to avoid adding the asset support hooks to too many specs.
(Asterisks are mine) |
- Add more logic for the disk service to determine the availability of the current host before generating the URL - Define the current host based on the record if the record has details about its organization, only if the current host hasn't been set already
alecslupu
requested changes
Apr 15, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 small improvements to be done.
Co-authored-by: Alexandru Emil Lupu <contact@alecslupu.ro>
The `image_tag` helper requires the image source to be present. Otherwise an error will be thrown.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
module: admin
module: assemblies
module: blogs
module: conferences
module: core
module: initiatives
module: participatory processes
module: system
team: performance
type: fix
PRs that implement a fix for a bug
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🎩 What? Why?
Use direct links to the assets living at storage services in order to push most of the application load to the storage service instead of the website itself.
Currently all uploaded assets in Decidim are served either through the ActiveStorage redirect URLs or representation URLs. This would make sense in some situations (e.g. if the files are protected) but currently all assets served by Decidim should be considered public.
Therefore, we can serve these images directly through the storage service because otherwise there will be an extra request to the service for each and every image to be served. If the page has a lot of different images, such as typical front page or listing of proposals, this adds excessive load on the servers because in worst case situations they are doing hundreds of requests to the Rails service just to serve one page. Under heavy load this becomes a real problem, e.g. if you have 100 users loading the front page at the same time containing 100 images, you would generate 10 000 requests for the Rails app in a very short timespan (note that 100 people is not that many).
To solve this issue, we can serve the images directly through the storage service bypassing all these requests coming to the Rails app. Note that some requests still need to be loaded through the app, such as the variant representation URLs during their first load (when the variant is created). But after the processing of the image variant, they can be served directly through the storage service.
📌 Related Issues
Testing
top
at the machine running Decidim