What is going on with this dump when I am running Puma for my Rails server in development. I find my app starts being really slow in development and I have to restart the server every once and a while. So I'm curious about what is going on with this dump and how can I make my Puma server act better in development?
This is my Procfile
web: bundle exec puma -C config/puma.rb
This is my Puma.rb file
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['MAX_THREADS'] || 8)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
ActiveRecord::Base.establish_connection
end
Related
I have a docker container: (called Dockerfile.web, relevant parts)
ARG PORT=3000
ENV PORT=$PORT
EXPOSE $PORT
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["rails", "server"]
Puma: config/puma.rb
before_fork do
ActiveRecord::Base.connection_pool.disconnect! if defined? ActiveRecord
end
on_worker_boot do
ActiveRecord::Base.establish_connection if defined? ActiveRecord
end
preload_app!
So when I run heroku container:push web followed by heroku container:release web, the app deploys, but the puma server doesn't come up b/c the port cannot be connected to:
Booting Puma
Rails 5.2.2 application starting in development
Run `rails server -h` for more startup options
Puma starting in cluster mode...
* Version 3.12.0 (ruby 2.6.0-p0), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Process workers: 1
* Preloading application
* Listening on tcp://localhost:41626
Use Ctrl-C to stop
- Worker 0 (pid: 28) booted, phase: 0
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Stopping process with SIGKILL
I'm following the official guide but I haven't added the sections:
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
Where could my error be? Any ideas?
I'm not sure why you left this part out:
port ENV['PORT'] || 3000
You can't pick your own port. Use the $PORT that Heroku gives you.
For people arriving here, the solution was to invoke the puma server directly from the docker CMD so that all the settings in the config file are applied. The reason is that on heroku, stuff like port is added dynamically, so container images (which are built out earlier) will not have those images. Somehow using the $PORT values inside Dockerfile also did not help. The solution was to do
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]
# or if you prefer the bash style
CMD bundle exec puma -C config/puma.rb
I can not understand what the problem is. The app works perfectly after I start it. After a while of inactivity (around 5 min with no requests) the app stops responding when I send requests to it.
puma.rb:
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" }
plugin :tmp_restart
This is what I get when I do this: ps aux | grep puma
user+ 4201 7.8 2.5 1197292 100560 ? Sl 15:41 0:04 puma 3.11.4 (tcp://0.0.0.0:3000) [backend]
user+ 4277 0.0 0.0 15476 1020 pts/20 S+ 15:42 0:00 grep --color=auto puma
ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
rails -v
Rails 5.1.6
OS Ubuntu 16.04 LTS
this is what your puma.rb should look like
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
ActiveRecord::Base.establish_connection
end
My puma configuration:
#!/usr/bin/env puma
workers ENV.fetch("WEB_CONCURRENCY") { 2 }
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count
worker_timeout 30
preload_app!
port ENV['PORT'] || 80
environment ENV['RAILS_ENV'] || 'development'
rackup DefaultRackup
before_fork do
ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
end
on_worker_boot do
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end
The htop:
The number of threads should be 5, but the htop shows that there are 12 threads in each worker(process). BTW, I run the workers and htop in a docker container.
That confused me a lot, could somebody explain it?
I'm configuring Jenkins to deploy in production my rails application.
At the end of jenkings, i can see:
+ bin/bundle exec puma -C config/puma.rb
Puma starting in single mode...
* Version 3.4.0 (ruby 2.2.2-p95), codename: Owl Bowl Brawl
* Min threads: 0, max threads: 16
* Environment: production
* Daemonizing...
Finished: SUCCESS
After the script, puma is not running ...
config/puma.rb
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads threads_count, threads_count
railsenv = 'production'
directory '/var/lib/jenkins/workspace/MyRailsApp'
environment railsenv
daemonize true
pidfile "/tmp/pids/puma-#{railsenv}.pid"
state_path "/tmp/pids/puma-#{railsenv}.state"
threads 0, 16
bind "unix:///tmp/my-rails-app.sock"
port ENV.fetch("PORT") { 3000 }
preload_app!
on_worker_boot do
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end
plugin :tmp_restart
What's the best way to start/restart puma with Jenkins ?
I am using the Puma webserver and ActiveAdmin. When trying to load an active admin page of users in production I get a 502 error about 1/4 times. How can I correct this bug?
The screen shows this:
502 Bad Gateway
nginx/1.8.0
The logs show this:
2016-02-17T20:05:47.175Z - app I, [2016-02-17T20:05:47.194213 #15715] INFO -- : Started GET "/admin/users" for 127.0.0.1 at 2016-02-17 20:05:47 +0000
2016-02-17T20:05:47.178Z - app I, [2016-02-17T20:05:47.196358 #15715] INFO -- : Processing by Admin::UsersController#index as HTML
2016-02-17T20:05:54.579Z - app [69] - Worker 0 (pid: 15959) booted, phase: 0
config/puma.rb
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
ActiveRecord::Base.establish_connection
end