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

Memory issues with the openactive gem #37

Open
nickevansuk opened this issue Jun 29, 2021 · 0 comments
Open

Memory issues with the openactive gem #37

nickevansuk opened this issue Jun 29, 2021 · 0 comments

Comments

@nickevansuk
Copy link
Contributor

With thanks to @rsslldnphy for this report:

The openactive gem allocates a large amount of objects on require. Roughly 3MB, which might not sound like a lot, but we were routinely being pushed only a few MB over our heroku dyno's limit.

These are the gems that allocate the most memory in our app, found using the derailed_benchmarks gem:

Total allocated: 87758372 bytes (814782 objects)
Total retained:  16486839 bytes (149308 objects)
 
allocated memory by gem
-----------------------------------
  60706044  dead_end-1.1.7
   5138712  mime-types-3.3.1
   3250825  openactive-0.1.2
   2066262  forwardable
   1706469  hashie-4.1.0
   1575432  aws-sdk-core-3.114.0
   1524992  set
   1349008  graphql-1.12.12
   1239154  aws-sdk-s3-1.94.1
   1142172  iso-639-0.3.5
   1005249  addressable-2.7.0
    766970  activesupport-6.0.3.5
    466576  aws-sdk-kms-1.43.0

As you can see the openactive gem allocates an outsized amount of memory compared to other gems (the dead_end gem is a dependency of the profiler, so isn't in the production app).

From what I can see this memory is mostly strings, the strings used in the define_property calls, exacerbated by the fact that the JsonLdSerializable concern appears to clone all the properties so will double the allocations. You can see this from the memory allocations by file here:

allocated memory by file
-----------------------------------
  60706044  /Users/rosoll/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/dead_end-1.1.7/lib/dead_end/auto.rb
   3966971  /Users/rosoll/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/mime-types-3.3.1/lib/mime/type.rb
   1623351  /Users/rosoll/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/hashie-4.1.0/lib/hashie/dash.rb
   1524992  /Users/rosoll/.rbenv/versions/2.7.2/lib/ruby/2.7.0/set.rb
   1237593  /Users/rosoll/.rbenv/versions/2.7.2/lib/ruby/2.7.0/forwardable.rb
   1142172  /Users/rosoll/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/iso-639-0.3.5/lib/iso-639.rb
    979195  /Users/rosoll/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/addressable-2.7.0/lib/addressable/idna/pure.rb
    975960  /Users/rosoll/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/aws-sdk-core-3.114.0/lib/seahorse/model/shapes.rb
    954258  /Users/rosoll/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/openactive-0.1.2/lib/openactive/concerns/json_ld_serializable.rb

This is only the first few lines of the output, there's a lot more files from openactive further down, but each one contributes only a small amount to the total memory allocations.

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

No branches or pull requests

1 participant