WardCunningham/Smallest-Federated-Wiki — pull request #331 by kyledrake (2012-12-09 03:15:39+00:00)
Title: Switch to Puma for web server instead of Thin

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!