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

Commits on Feb 27, 2017

  1. Fix memory leak in components

    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)
    ```
    tijmenb committed Feb 27, 2017
    Configuration menu
    Copy the full SHA
    4e0a7f4 View commit details
    Browse the repository at this point in the history