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
Fix memory leak in components #191
Merged
Merged
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
Most of our frontend apps leak memory, which causes regular Icinga alerts for 2nd line. We currently mitigate this by restarting the apps manually. This dashboard shows the problem: https://grafana.publishing.service.gov.uk/dashboard/db/memory-dashboard The primary cause of this seems to be the `GovukComponent` class. This currently instantiates a `ComponentResolver` class per request, which in turn instantiates lots of ActionView related objects. By caching the resolver for 15 minutes, we save a lot of memory. To test I've used the [derailed_benchmarks gem][derailed]. I've tested this with the following command on `government-frontend`: [derailed]: https://github.com/schneems/derailed_benchmarks ``` GOVUK_APP_DOMAIN=www.gov.uk GOVUK_ASSET_ROOT=https://www.gov.uk GOVUK_WEBSITE_ROOT=https://www.gov.uk PLEK_SERVICE_CONTENT_STORE_URI=https://www.gov.uk/api PLEK_SERVICE_STATIC_URI=assets.publishing.service.gov.uk DERAILED_SKIP_ACTIVE_RECORD=true TEST_COUNT=100 PATH_TO_HIT=/government/case-studies/nda-archive SLIMMER_DEV=1 bundle exec derailed exec perf:objects ``` This makes a 100 requests to the app and outputs stats on memory usage. Before this change (master): ``` Total allocated: 159341340 bytes (1415052 objects) Total retained: 680097 bytes (5510 objects) ``` After this change: ``` Total allocated: 106879912 bytes (931658 objects) Total retained: 141145 bytes (551 objects) ```
These graphs look pretty promising so this get's a big 👍 from me. I helped @tijmenb on slack as he was investigating this, so this probably wants someone else to give it a once (or twice) over. |
carvil
approved these changes
Feb 27, 2017
tijmenb
added a commit
to alphagov/collections
that referenced
this pull request
Feb 27, 2017
tijmenb
added a commit
to alphagov/frontend
that referenced
this pull request
Feb 27, 2017
tijmenb
added a commit
to alphagov/multipage-frontend
that referenced
this pull request
Feb 27, 2017
tijmenb
added a commit
to alphagov/business-support-finder
that referenced
this pull request
Feb 27, 2017
This was referenced Feb 27, 2017
Belated 👏 |
fofr
added a commit
to alphagov/manuals-frontend
that referenced
this pull request
Apr 6, 2017
* Fix memory leak with components: alphagov/slimmer#191 * Stub locale requests: alphagov/slimmer#159
fofr
added a commit
to alphagov/manuals-frontend
that referenced
this pull request
Apr 6, 2017
* Fix memory leak with components: alphagov/slimmer#191 * Stub locale requests: alphagov/slimmer#159
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Most of our frontend apps leak memory, which causes regular Icinga alerts for 2nd line. We currently mitigate this by restarting the apps manually.
This dashboard shows the problem: https://grafana.publishing.service.gov.uk/dashboard/db/memory-dashboard
The primary cause of this seems to be the
GovukComponent
class. This currently instantiates aComponentResolver
class per request, which in turn instantiates lots of ActionView related objects.By caching the resolver for 15 minutes, we save a lot of memory.
To test I've used the derailed_benchmarks gem. I've tested this with the following command on
government-frontend
:This makes a 100 requests to the app and outputs stats on memory usage.
Before this change (master):
After this change:
This change has run for on staging in
specialist-frontend
andmultipage-frontend
(see #189). It shows a nice improvement over the weekend:The last hours show a little increase in memory usage, but it's probably still better than the current situation.
https://trello.com/c/MPcAEGbL/851-frontend-apps-memory-leak
https://trello.com/c/TYpcs2W1