我编写了一个小型 Rails 5 API-only 应用程序,我在 Heroku 上托管。应用程序所要做的就是从数据库中检索一些数据(当前少于 5K 记录)并将其输出为 JSON。在部署应用程序并从浏览器运行几个测试查询(使用不同的参数来过滤结果)后,我在 Heroku 上注意到以下内容:
处理 JSON 转换的 gem 是
gem 'jsonapi-utils', '~> 0.6.0.beta'
但我也试过没有,就RAM消耗而言,它根本没有区别。
除此之外,我的应用程序中的所有内容都是默认生成的 Rails 5 API-only 应用程序。Puma 配置如下所示:
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads threads_count, threads_count
port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
workers ENV.fetch("WEB_CONCURRENCY") { 2 }
preload_app!
on_worker_boot do
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end
plugin :tmp_restart
这是 Heroku 在这里推荐的:https ://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server
从发布中可以看出,空闲应用程序消耗的 RAM 非常少。几个请求(< 20)怎么可能会大量增加 RAM 使用量,我该怎么办?
PS 我正在使用 Rails 5.0.2 和 Ruby 2.4.1