Performance issue with Thin

It's not about scalability on a huge site, but the lowest possible latency for a very small app.

I have a little app with Thin and Sinatra. My app generates the page in about 50ms. After getting the browser request, thin waits 50ms and then it takes 300ms sending the page, to Chromium at localhost.

(It takes 300ms to send a static a.html with the word "test" on it, too, so it seems to be a lower bound on my machine)

Why is that? Should Mongrel be faster sending the data? Or maybe Passenger?

The generating time was taken on Sinatra, by doing Time.new.to_f then printing the diff. The wait / send time was taken at Chromium "resources" tab.

The fact that thin waits 50ms before starting to send anything makes sense, if the app happen to set the header at the end of the output.

But spending 300ms just _sending_ the page to localhost page does not. It's a 1kb file. Maybe it's forking before every page? (But it doesn't reload automatically like shotgun, so this makes no sense; it must be something else)

I could still optimize my app (since its performance is bound by an sql query that is taking less than 10ms), but my bottleneck isn't there, it's on Thin.

For comparison, djb's publicfile can send a 100kb image in this same 300ms. (I know it's unfair)

Some versions: ruby 1.9.2p0, thin 1.2.7

Elias Gabriel Amaral da Silva wrote in post #962579:

It's not about scalability on a huge site, but the lowest possible latency for a very small app.

I have a little app with Thin and Sinatra.

[...]

Then you're off topic for this list. This is the Rails mailing list. Please go to a Thin or Sinatra forum, or (failing that) to the main Ruby list.

Best,