Category Archives: rails

Staying Alive with Thin!

TravoltaThin was the first Ruby server to be able to connect to UNIX domain sockets, giving you a little more speed, so you could spend less time browsing and more time dancing and eating ice creams with the people you love. But only Nginx (that I know of) supports UNIX domain sockets. Non-Nginx users might like to have time to dance and eat ice creams with the people they love too!

So that’s why Thin new release (0.7.0 codename Spherical Cow) supports persistent connections (aka Keep-Alive).

Apache & mod_proxy

Under Apache, if a client requests a persistent connection, the connection to the backend server (through mod_proxy) will also be persistent. That means the time spent opening the connection is saved for subsequent requests because all requests will be sent through the same connection. Even cooler is that you have nothing to do to set that up, unless you’ve turned Keep-Alive off.

I ran some benchmarks and I got an average gain of 200 req/sec with Keep-Alive on.
Keep-Alive benchmark

Sadly Nginx doesn’t support persistent connections to backends yet, but it seems to be a highly requested feature, and Igor Syseov (author of Nginx) said he’s working on it several times on the mailing list. Imagine that: UNIX sockets + persistent connections, oooh man!

Hey we develop too, sometimes!

Of course you’ll take advantage of that feature when it’s just you, Thin and your browser. And we can also benchmark it, just for fun, to get numbers that are sure to give you goose bumps: 7800 req/sec is just, ooooh, aaahh, hummm, yeah, that was good!



If you’re looking for even more speed. Thin can now be used as a Swiftiply client. And it’s very easy to use:

thin start --servers 3 --port 8000 --swiftiply

Just add the --swiftiply option. This also means that any Rack adapter can be run through Swiftiply (using the --rackup option) including Ramaze, Camping, Merb, YourCrazyLittleFrameworkThatIsSoooBetterThenAllTheOtherAndThatSupportRack etc.

Speed with control

But what is speed with no control, right?

The main reason why Mongrel couldn’t support persistent connections was because of Ruby 1024 file/socket descriptors limitation. If you don’t close the connection (keep them alive) it’s one less descriptor you can use to process another connection or open a file.

Although EventMachine doesn’t have an infinite number of file descriptors it was reported to handle more then 20 000 concurrent connections.

You can now tune the number of connections a Thin server can handle.

--max-conns: This sets the maximum number of concurrent connections your Thin server can handle. Setting higher then 1024 might require superuser privileges on some system.

--max-persistent-conns: This sets the maximum number of persistent connections your Thin server can handle at the same time. If resource usage is important, you might want to turn that down. You can turn Keep-Alive support off by setting to 0.

Get it!

Spherical Cow also comes with a couple bug fixes and tweak.
As usual, you can get the latest version from RubyForge:

sudo gem install thin

If you have any question, join the Google Group or the #thin channel on freenode.

I hope you like it!



Filed under rails, ruby, thin

MoR7 Presentation

ImageHere’s the code and slides of my presentation :

Hope you liked it!

1 Comment

Filed under montreal, rails, StandoutJobs, thin

Has Zed jumped the shark ?

Zed ShawZed Shaw, the creator of Mongrel, is writing some pretty nasty stuff about the Rails community, ThoughWorks and Ruby.

There’s no work for a smart man in a town full of stupid.

Although I agree there might be some stupid people working with Rails right now, there’s a huge number of very bright people too. And there’s stupid people working with PHP, Java, Python, C, Haskell, Erlang, Lua and Factor too.

The thing is: Rails is getting easier to use every day, lowering the barrier of entry for new coders. The Rails community is growing beginner level coders a lot faster then expert coders now. A year ago, it was probably the opposite. Alpha geeks like being credited for doing hard stuff, solving impossible puzzle, and making code run faster then you could think possible. But Rails is so standardized now, there’s little place for innovation. So new coders to make a name in that community by changing the game again. It was easy before, nothing was there, everything was to be done!

Congratulations because all the idiots who paid ThoughtWorks 6x times salary for junior ass wipes got taken and simply paid to train ThoughtWorks’ new crew

And maybe ThoughWorks is taking advantage of Rails popularity, but it will happen for other cool framework/language too if they get some day to that level of popularity. There’s no reason to shit on the Rails community for this.

After revitalizing myself, getting out of the Rails business (or trying), distancing myself from Mongrel, disconnecting from the Ruby community

Is this the end of Mongrel ?

Zed rant was pretty excessive and even though he claims that everything he writes on his blog is an act, I’m sure he’ll regret this as this will get quoted out of that so-called humorous context.

Strange way to start the new year!

What’s your thoughts on this ?


Filed under rails, ruby

Getting TextMate ready for Rails 2.0

After updating a couple of existing Rails app to 2.0, I found out some of TextMate sugar was out of date. Here’s 2 things I did to put the hot and sweet sugar back into TextMate.

Update the bundle

TextMate bundles are under heavy development all the time, get the latest version from their repo:

svn export

Then double-click on the downloaded Ruby on Rails.tmbundle.

Fix the test commands

I’m a heavy user of Run (command+R), Run Focused Unit Test (shift+command+R) and the Rails menu (shift+ctrl+\) but that do not work with Rails 2 because of a conflict with the builder module.

Rob Sanheim explain how to solve this very easily, just rename the Builder.rb in the Rails bundle.

Hope this helps!


Filed under rails, tips, tutorial

Rack, the frameworks framework

RackWith all the Ruby frameworks popping up, we’re starting to see some similarities. All of them provide something new or unique but one part of their code is always the same. The part that plugs it into a web server. Ultimately, all web servers have to support all frameworks and vice-versa. That is a lot of duplicated code! That makes me yell, running in circles, waving my arms: not DRY, not DRY, not DRY!


Rack (not the iRack) by Christian Neukirchen, solves this problem.

From Rack website:

Rack provides an minimal interface between webservers supporting Ruby and Ruby frameworks.

Rack looks like this in my head:

Handlers on the left (web servers) serve requests to Adapters (frameworks) on the right.
(Don’t ask me what the rabbit is doing there, must be important)

Run Forest!

But Rack can do a lot more then plug Ruby framework into webservers. It is a framework in itself.

When you install it:

sudo gem install rack

You get the rackup command. Which lets you start your app on any supported web server.

require 'rack/lobster'



Start your app: rackup -p3000 then browse to http://localhost:3000, oh the cute lobster!

To run it on other web servers (mongrel by default) play with the -s option.

It’s a framework I said

The Handler API is only 1 method: call(env). Which allows you to use proc as application.

app = proc do |env|
  [200, { 'Content-Type' => 'text/html' }, 'no pepper plz!']
run app


That will return a 200 OK response with the text/html content type and the body no pepper plz!. env contains the request parameters, so you could play with the QUERY_STRING or wrap it inside a Rack::Request and get a request param value with request.params['name'].


You can use middlewares to filter the process. For example, you can add logging and detailed exception support with those 2 lines in your file:

use Rack::CommonLogger, STDOUT
use Rack::ShowExceptions

You can also validate your application, the requests and responses according to the Rack spec automatically using the Rack::Lint middleware.

(There’s also a Reloader, Static, Cascade, File and much more middlewares, check the doc)

You can also have fun with urls:

map '/files' do

map '/lobster' do

Check it out!

Rack is the best example of a very well design Ruby library. The code is simple, well separated and yet, easily extensible, it’s beautiful! I encourage you to check out the code but mostly to use it if you’re building any Ruby web framework (like we need other one!).


Filed under rails, ruby, tutorial

Rontreal On Mails is torromow

Snow make use slowMontreal is white and snowy
Ruby is red and pretty
Rails is red (also) so lets party


Filed under montreal, rails, ruby, StandoutJobs

Defensio launched

Remember my Defensio plugin ? It is used on RefactorMyCode to keep the site clean of any spam and the users happy.

Defensio(hit refresh if you don’t see the new site) is now public, so you can get an API key in seconds and get to speed with my plugin in milliseconds (or less).

Congrats to the Karabunga guys!

Here’s a screenshot of my stats window:

Defensio Stats

Pretty cool!

And you can also subscribe to a feed, so you get notifications of spam in your feed reader.


Filed under montreal, rails, refactormycode