tags:

views:

324

answers:

3

Many people have asked about Rails hosting on this site, but I'm not familiar enough with the back end of things to know if there's a difference.

I want to host some Ruby CGI 'webservices', basically just ruby methods that take parameters from a POST request, access a MySQL db and return data.

I've looked at RoR and it seems like overkill for this, from what I can tell it's for speeding up the development of data baesd CRUD sites, which is not at all what I'm doing.

So my question is, does this affect the hosting provider I choose? Does anyone recommend a good Ruby host for CGI operations? I'm not familiar with FastCGI, mod_ruby, Passenger, Mongrel etc. and what they mean for performance, scalability etc. I just want to host my ruby scripts with reasonably good performance, and all the info out there(and here) seems to be focused on rails.

A: 

I think you might want to look into Rack. It allows you to do the kinds of things you're talking about and shrugs off the weight of frameworks like Rails or Merb. Rack applications can be hosted at a place like Heroku.

Jason Punyon
Heroku looks interesting, but I ran into an issue on windows with the 'heroku create' command telling me 'No ssh public key found in ...You may want to specify the full path to the keyfile.'
LoveMeSomeCode
Sorry man...I'm on a Mac so I've never used it from windows...
Jason Punyon
I've also not used the windows version but I'd second the vote for Heroku. They have a kickass free version until you're ready to upgrade.
Chuck Vose
A: 

I think you may want to use Rails anyway, if only because having the framework sitting around will not cost you anything and you will probably find it quite useful in the future to have had Rails experience. (To name just one thing: you could put it on your résumé.)

But, to answer the question, there are lightweight Ruby web frameworks that may be more to your liking. See Camping, Nitro, and Sinatra. (Links over here.)

Regarding hosting providers, I imagine any Rails site can do what you want, because all of them will have a Ruby interpreter installed. If they don't, you can run a VPS and install anything you feel like. Different hosting providers give you turnkey ("cloud computing") environments or just virtual systems you can administrate yourself.

DigitalRoss
+5  A: 

First, if you want lightweight, Sinatra is usually my first pick. Pair it up with rack and Passenger for best results. It's not CGI, but realistically speaking, CGI is rarely a good match-up with Ruby.

Here's the "Hello World!" Sinatra app from the main page:

require 'rubygems'
require 'sinatra'
get '/hi' do
  "Hello World!"
end

Hard to get more lightweight than that.

As for providers, anybody that supports Passenger (mod_rack) should be able to handle Sinatra. I'm a big fan of Slicehost personally, but they're a VPS host, which means you need to be able to install and manage the entire stack yourself. If you don't mind paying a tiny bit extra for the infrastructure, Heroku makes installation and deployment dead simple, so long as your needs don't exceed what they provide (sounds like they won't). In the unlikely event that you're only using 5MB or if you're using an external storage mechanism like Amazon RDS, Heroku may actually be free for you.

Update:

  • Passenger is an Apache module that allows Rack applications to be run inside of Apache.
  • Rack is a middleware layer that separates the web server and the web framework from each other. This allows web frameworks to run on any web server for which there is an adapter.
  • Sinatra is a lightweight web framework that runs on top of Rack.

Once Passenger and Rack are installed (gem install rack, gem install passenger) you just need to edit the Apache vhost to point at the config.ru file for your Sinatra app and create the required directories as per the Passenger docs and you'll be good to go.

Bob Aman
sorry for the noob response, but this is my first CGI endeavor outside of .NET -- why would I need Sinatra(or Rack/Passenger/Camping) ? Can't I just throw the .rb file into the cgi-bin folder, use 'require cgi', and read the POST variables, run my code and send back a response?
LoveMeSomeCode
Sure, so long as you don't mind the constant startup/shutdown cost you incur. It wouldn't be a big deal if you're just writing "hello world", but you said you need to write to a database. That means you need to load and unload the database adaptor on every single request. In Ruby, load times for libraries like database adaptors tend to be non-trivial. And frankly, Sinatra is maybe 5 minutes more setup time than CGI, and a lot easier to use. If you spend more than an hour of work on this project, I promise Sinatra will save you time, even with the learning curve.
Bob Aman
Hmm... I should probably note... it's 5 minutes set up time for me. First time around will probably be longer because you don't have Passenger installed yet.
Bob Aman
ok, good info as far as performance. but i still dont understand exactly what the function of passenger, rack, and sinatra are separately. i've read the documentation, but i dont really get how to use them as alternatives to the cgi library
LoveMeSomeCode
also, i've heard about fast cgi. would that be better than just cgi and still easy to use?
LoveMeSomeCode
ok i tried the sinatra example on the website and it seemed to work but now i'm even more confused. is sinatra its own webserver? it started listening on port 4567, and i can hit it from my browser, but how do i integrate this with a host that i rent space from? and how is this related to passenger and rack? i have all three of those gems installed, but i only referred to sinatra in the example script. i guess im confused as to which are things i deal with in code, and which are things that get 'intsalled' into apache.
LoveMeSomeCode
I've updated my answer to fill in some of the blanks. Sinatra is not its own webserver, but it does provide a development environment that will allow you to quickly test stuff out with any webserver that you have an available rack adapter for. This usually works out to being Mongrel.As for hosts that you rent space from, your host needs to support Ruby in the first place. Most shared hosts that do, already support Passenger. If you're on a VPS host, you'll usually need to install Passenger yourself.
Bob Aman
As for FastCGI, yes, it would resolve some of the primary CGI issues, but it has its own set of issues and it's generally avoided at this point. Passenger is much, much easier to work with and more importantly, maintain. Your initial setup cost in time may be slightly higher, but your ongoing maintenance cost will be much, much lower.
Bob Aman
Bob Aman