Skip to content

Commit

Permalink
Switch from Thin to Puma
Browse files Browse the repository at this point in the history
* Commit database.yml to git to setup pool size
* Set `PORT` var, make sure to update your local `.env`

https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server

Closes: #286
  • Loading branch information
antonfefilov authored and timurvafin committed Aug 27, 2015
1 parent b92c296 commit 92c4eb8
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Specify assets server host name, eg.: d2oek0c5zwe48d.cloudfront.net
# ASSET_HOST=d2oek0c5zwe48d.cloudfront.net

# Port to serve application
PORT=5000

# current environment:
RACK_ENV=development

Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ log/*.log
tmp/*
coverage/*
rerun.txt
config/database.yml
doc/**/*
vendor/bundle
vendor/cache
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Switch web server from [Thin](https://github.com/macournoyer/thin) to [Puma](https://github.com/puma/puma)
- Update [Uglifier](https://github.com/lautis/uglifier) version up to 2.7.2
- Add [Rubocop-Rspec](https://github.com/nevir/rubocop-rspec) for reporting violations of Ruby style guide in specs
- Add [Slim-Lint](https://github.com/sds/slim-lint) for reporting violations of Ruby style guide in `.slim` templates
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ gem "kaminari"
gem "responders"
gem "rollbar", "~> 0.10.3"
gem "seedbank"
gem "thin"
gem "puma"
gem "pundit"
gem "rack-canonical-host"

Expand Down
9 changes: 2 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ GEM
columnize (0.8.9)
crack (0.4.2)
safe_yaml (~> 1.0.0)
daemons (1.1.9)
database_cleaner (1.3.0)
debug_inspector (0.0.2)
debugger-linecache (1.2.0)
Expand All @@ -131,7 +130,6 @@ GEM
launchy (~> 2.1)
mail (~> 2.2)
erubis (2.7.0)
eventmachine (1.0.7)
execjs (2.6.0)
factory_girl (4.5.0)
activesupport (>= 3.0.0)
Expand Down Expand Up @@ -210,6 +208,7 @@ GEM
slop (~> 3.4)
pry-rails (0.3.2)
pry (>= 0.9.10)
puma (2.13.4)
pundit (1.0.0)
activesupport (>= 3.0.0)
quiet_assets (1.0.2)
Expand Down Expand Up @@ -353,10 +352,6 @@ GEM
therubyracer (0.12.1)
libv8 (~> 3.16.14.0)
ref
thin (1.6.1)
daemons (>= 1.0.9)
eventmachine (>= 1.0.0)
rack (>= 1.0.0)
thor (0.19.1)
thread_safe (0.3.5)
tilt (1.4.1)
Expand Down Expand Up @@ -418,6 +413,7 @@ DEPENDENCIES
metamagic
pg
pry-rails
puma
pundit
quiet_assets
rack-canonical-host
Expand All @@ -442,7 +438,6 @@ DEPENDENCIES
spring
spring-commands-rspec
therubyracer
thin
uglifier (>= 2.7.2)
web-console (~> 2.0)
webmock
Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: bundle exec rails server thin -p $PORT -e $RACK_ENV
web: bundle exec puma -C config/puma.rb
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ It's based on Rails 4 and Ruby 2.2.3.

## Development Gems

* [Thin](https://github.com/macournoyer/thin) as Rails web server
* [Puma](https://github.com/puma/puma) as Rails web server
* [Foreman](https://github.com/ddollar/foreman) for managing development stack with Procfile
* [Letter Opener](https://github.com/ryanb/letter_opener) for opening mail in the browser instead of sending it
* [Bullet](https://github.com/flyerhzm/bullet) for detecting N+1 queries and unused eager loading
Expand Down
19 changes: 19 additions & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
defaults: &defaults
adapter: postgresql
encoding: unicode
min_messages: warning
timeout: 5000
pool: <%= [ENV.fetch("MAX_THREADS", 5), ENV.fetch("DB_POOL", 5)].max %>

development:
database: application_dev
<<: *defaults

test:
database: application_test
<<: *defaults

production: &deploy
<<: *defaults

staging: *deploy
32 changes: 0 additions & 32 deletions config/database.yml.example

This file was deleted.

13 changes: 13 additions & 0 deletions config/puma.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
workers ENV.fetch("WEB_CONCURRENCY", 2).to_i
threads_count = ENV.fetch("MAX_THREADS", 5).to_i
threads threads_count, threads_count

rackup DefaultRackup
port ENV.fetch("PORT", 5000)
environment ENV.fetch("RACK_ENV", "development")

preload_app!

on_worker_boot do
ActiveRecord::Base.establish_connection
end

0 comments on commit 92c4eb8

Please sign in to comment.