This repository has been archived by the owner on Feb 14, 2018. It is now read-only.
Switch to Puma for web server instead of Thin #331
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sinatra prior to 1.3 uses "EventMachine" mode of Thin, which disables Ruby
threading. This can dramatically decrease throughput on JRuby and
Rubinius, because it cannot take advantage of multiple CPU cores with
this configuration.
In addition, the MRI (Matz Ruby Implementation) C version of Ruby has a
pattern where it will not block on IO if threading is used, because IO
will run in the background concurrently while work is being done on
other threads.
Unfortunately, Thin with Sinatra < 1.3 forcibly turns threading off due
to EventMachine, which makes it so the server has to stop and wait for
external IO requests to finish until it can continue serving content (the
exception being if you use the special EventMachine drivers, which are
very difficult to implement).
Puma does not have these restrictions. It is a fast, clean
implementation based on threads, and should run well on all Ruby
implementations. It should increase throughput dramatically vs Thin for
sites doing a lot of remote IO. It also has a lot of power features like
HTTP Keepalive. And best of all, it removes the EventMachine dependency!
More information is available from their web site: http://puma.io
This is a fairly big change, so it would be great if a few people tested it and gave it a thumbs up before merging. An alternative solution to this would be to upgrade to a Sinatra >= 1.3 and the latest version of Thin, which will automatically use threaded mode by default, but this seemed like the more conservative option of the two. That said, ultimately it might be nice to upgrade to 1.3+ as well.
I deployed to Heroku with this change and it appears to be working just fine!