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

Fix memory leak in components #191

Merged
merged 1 commit into from Feb 27, 2017
Merged

Fix memory leak in components #191

merged 1 commit into from Feb 27, 2017

Conversation

tijmenb
Copy link
Contributor

@tijmenb tijmenb commented Feb 27, 2017

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

screen shot 2017-02-27 at 12 13 15

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. I've tested this with the following command on government-frontend:

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)

This change has run for on staging in specialist-frontend and multipage-frontend (see #189). It shows a nice improvement over the weekend:

screen shot 2017-02-27 at 12 15 06

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

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)
```
@h-lame
Copy link

h-lame commented Feb 27, 2017

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.

@dsingleton
Copy link
Contributor

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants