Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you choose your HTTP server in Sinatra?

I am running a Sinatra application locally.

Ever since I installed Thin, my Sinatra app always uses it as the web server. However, I have been having performance issues with Thin serving the large amount of static files required by my application, and I would like to switch to either Mongrel or WEBrick.

I cannot seem to figure out how to switch my application over to Mongrel or WEBrick. Even when I put require 'mongrel' or require 'webrick' at the top of my app.rb, upon a ruby app.rb, Sinatra still starts with Thin.

So, my question is: how do you specify the web server for Sinatra to use in development mode? Also, how could I do so in production mode?

like image 830
sffc Avatar asked Apr 02 '13 02:04

sffc


People also ask

What is a Sinatra server?

Sinatra is a lightweight domain-specific programming language and web application library that is used for writing web applications. It provides a faster and simpler alternative to Ruby frameworks such as Ruby on Rails.


1 Answers

You can set the server Sinatra uses with the :server configuration setting:

set :server, 'webrick'  # or thin, mongrel

In production, it is much better to use a more sophisticated server like Phusion Passenger or Unicorn, since they have better performance than Thin, Mongrel, or WEBrick. If you choose Passenger or Unicorn, you would not configure the server within your Sinatra application file itself, but instead typically configure it separately using a Rackup config.ru file.

"Ruby on Rails Server options" is aimed at Rails applications, but is still very relevant for Sinatra apps.

like image 192
Stuart M Avatar answered Oct 21 '22 20:10

Stuart M