简体   繁体   中英

How to measure memory usage of a Rack or Sinatra app?

How do you measure memory usage of a Rack or Sinatra app?

I understand that probably depends a lot on how it is deployed. But how do you get a basic idea of how much memory it uses?

如果您正在使用乘客,您可以尝试乘客记忆统计数据,这可以让您按站点分割出一个很好的概览,否则您可以通过使用top,shift-M和寻找红宝石过程来了解内存使用情况。

Despite it's name, I've successfully used the derailed_benchmarks gem to dynamically benchmark memory usage in a Padrino (built on Sinatra) app. The docs describe how to do this for a non-Rails Rack app - you just need to define DERAILED_APP in a simple Rake task to tell it how to boot your app.

It can be run with a real server (I use Unicorn) on your localhost and potentially even with your production database (define DATABASE_URL ). It can also be used to test any endpoint and bypass authentication, if necessary. Use cases include memory use over time (to find leaks) and profiling gems/required library memory at boot for a given endpoint (lots of memory use at boot).

As an example, the command bundle exec derailed exec perf:mem gives the output below for my app's root at boot (here hiding < 3 MiB usage). Around 70 MiB tallies with what Heroku's stats are telling me on my production server. My app is called 'padfoot' btw.

TOP: 71.75 MiB mechanize: 19.0898 MiB (Also required by: /Users/me/dev/padfoot/lib/parsers/transaction_table_parser.rb, /Users/me/dev/padfoot/lib/scrapers/app_details_scraper.rb, and 4 others) mechanize/pluggable_parsers: 11.1055 MiB mime/types: 10.9766 MiB (Also required by: /Users/me/.rvm/gems/ruby-2.3.1/gems/rest-client-1.8.0/lib/restclient/request, /Users/me/.rvm/gems/ruby-2.3.1/gems/rest-client-1.8.0/lib/restclient/payload) padrino: 13.1016 MiB padrino-core: 8.0273 MiB (Also required by: padrino-cache, padrino-admin) padrino-core/application: 3.3555 MiB sinatra/base: 3.1406 MiB (Also required by: padrino-core/ext/sinatra, sinatra/main) padrino-helpers: 3.707 MiB (Also required by: padrino-cache, padrino-admin) padrino/rendering: 3.3203 MiB (Also required by: /Users/me/dev/padfoot/app/app.rb) /Users/me/dev/padfoot/config/apps.rb: 6.9805 MiB /Users/me/dev/padfoot/app/app.rb: 6.8906 MiB aws-sdk-core/s3: 6.3711 MiB /Users/me/dev/padfoot/lib/scrapers/gps/gps_scraper.rb: 4.25 MiB linguistics/en: 4.1523 MiB /Users/me/dev/padfoot/lib/scrapers/digimap/digimap_scraper.rb: 3.0547 MiB

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM