I wrote a small Rails 5 API-only application that I am hosting on Heroku. All the application has to do is to retrieve some Data from a DB (currently less than 5K records) and output it as JSON. After deploying the application and running a couple of test queries from the browser (with different parameters to filter the result), I noticed the following on Heroku:
The gem that handles the JSON conversion is
gem 'jsonapi-utils', '~> 0.6.0.beta'
but I've also tried it without, and as far as the RAM consumption goes it makes no difference at all.
Besides that everything in my application is the default from generating a Rails 5 API-only application. The Puma config looks like this:
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
which is the one recommended by Heroku here: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server
As you can see from the releases, the idle application consumes very little RAM. How can it be that a couple of requests (< 20) can increase the RAM usage that heavily, and what can I do about that?
P.S. I am using Rails 5.0.2 and Ruby 2.4.1