Why does htop show more threads than puma configuration? - ruby-on-rails

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?

Related

not able to access localhost:3000 outside vmware

i am running webrick default ROR server inside vmware in ubuntu. i have host window as Window 10.but in window 10 browser i am not able to access the 0.0.0.0:3000 . i have ruby on rails code, how can i host in my own machine server?
in window10 browser i get error like-
[error][1]
[VMware and real host ip snapshot][2]
puma.rb
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count
port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
plugin :tmp_restart
[1]: https://i.stack.imgur.com/N65uJ.png
[2]: https://i.stack.imgur.com/At2Rz.png

The puma server freezes

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

Puma starting in single mode but not really start

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 ?

Puma fails sometimes with ActiveAdmin

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

Puma prints huge unruly output in terminal and runs slowly in development

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

Resources