Skip to content

Commit 92c4eb8

Browse files
antonfefilovtimurvafin
authored andcommitted
Switch from Thin to Puma
* 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
1 parent b92c296 commit 92c4eb8

10 files changed

+41
-43
lines changed

.env.example

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Specify assets server host name, eg.: d2oek0c5zwe48d.cloudfront.net
22
# ASSET_HOST=d2oek0c5zwe48d.cloudfront.net
33

4+
# Port to serve application
5+
PORT=5000
6+
47
# current environment:
58
RACK_ENV=development
69

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ log/*.log
44
tmp/*
55
coverage/*
66
rerun.txt
7-
config/database.yml
87
doc/**/*
98
vendor/bundle
109
vendor/cache

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- Switch web server from [Thin](https://github.com/macournoyer/thin) to [Puma](https://github.com/puma/puma)
56
- Update [Uglifier](https://github.com/lautis/uglifier) version up to 2.7.2
67
- Add [Rubocop-Rspec](https://github.com/nevir/rubocop-rspec) for reporting violations of Ruby style guide in specs
78
- Add [Slim-Lint](https://github.com/sds/slim-lint) for reporting violations of Ruby style guide in `.slim` templates

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ gem "kaminari"
3131
gem "responders"
3232
gem "rollbar", "~> 0.10.3"
3333
gem "seedbank"
34-
gem "thin"
34+
gem "puma"
3535
gem "pundit"
3636
gem "rack-canonical-host"
3737

Gemfile.lock

+2-7
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ GEM
109109
columnize (0.8.9)
110110
crack (0.4.2)
111111
safe_yaml (~> 1.0.0)
112-
daemons (1.1.9)
113112
database_cleaner (1.3.0)
114113
debug_inspector (0.0.2)
115114
debugger-linecache (1.2.0)
@@ -131,7 +130,6 @@ GEM
131130
launchy (~> 2.1)
132131
mail (~> 2.2)
133132
erubis (2.7.0)
134-
eventmachine (1.0.7)
135133
execjs (2.6.0)
136134
factory_girl (4.5.0)
137135
activesupport (>= 3.0.0)
@@ -210,6 +208,7 @@ GEM
210208
slop (~> 3.4)
211209
pry-rails (0.3.2)
212210
pry (>= 0.9.10)
211+
puma (2.13.4)
213212
pundit (1.0.0)
214213
activesupport (>= 3.0.0)
215214
quiet_assets (1.0.2)
@@ -353,10 +352,6 @@ GEM
353352
therubyracer (0.12.1)
354353
libv8 (~> 3.16.14.0)
355354
ref
356-
thin (1.6.1)
357-
daemons (>= 1.0.9)
358-
eventmachine (>= 1.0.0)
359-
rack (>= 1.0.0)
360355
thor (0.19.1)
361356
thread_safe (0.3.5)
362357
tilt (1.4.1)
@@ -418,6 +413,7 @@ DEPENDENCIES
418413
metamagic
419414
pg
420415
pry-rails
416+
puma
421417
pundit
422418
quiet_assets
423419
rack-canonical-host
@@ -442,7 +438,6 @@ DEPENDENCIES
442438
spring
443439
spring-commands-rspec
444440
therubyracer
445-
thin
446441
uglifier (>= 2.7.2)
447442
web-console (~> 2.0)
448443
webmock

Procfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: bundle exec rails server thin -p $PORT -e $RACK_ENV
1+
web: bundle exec puma -C config/puma.rb

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ It's based on Rails 4 and Ruby 2.2.3.
2828

2929
## Development Gems
3030

31-
* [Thin](https://github.com/macournoyer/thin) as Rails web server
31+
* [Puma](https://github.com/puma/puma) as Rails web server
3232
* [Foreman](https://github.com/ddollar/foreman) for managing development stack with Procfile
3333
* [Letter Opener](https://github.com/ryanb/letter_opener) for opening mail in the browser instead of sending it
3434
* [Bullet](https://github.com/flyerhzm/bullet) for detecting N+1 queries and unused eager loading

config/database.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
defaults: &defaults
2+
adapter: postgresql
3+
encoding: unicode
4+
min_messages: warning
5+
timeout: 5000
6+
pool: <%= [ENV.fetch("MAX_THREADS", 5), ENV.fetch("DB_POOL", 5)].max %>
7+
8+
development:
9+
database: application_dev
10+
<<: *defaults
11+
12+
test:
13+
database: application_test
14+
<<: *defaults
15+
16+
production: &deploy
17+
<<: *defaults
18+
19+
staging: *deploy

config/database.yml.example

-32
This file was deleted.

config/puma.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
workers ENV.fetch("WEB_CONCURRENCY", 2).to_i
2+
threads_count = ENV.fetch("MAX_THREADS", 5).to_i
3+
threads threads_count, threads_count
4+
5+
rackup DefaultRackup
6+
port ENV.fetch("PORT", 5000)
7+
environment ENV.fetch("RACK_ENV", "development")
8+
9+
preload_app!
10+
11+
on_worker_boot do
12+
ActiveRecord::Base.establish_connection
13+
end

0 commit comments

Comments
 (0)