Rails url: //host/controller/method/id
Lighttpd tries to open the file ‘controller/method/id’ from the
Of course this doesn’t work and generates an error 404
This gets caught with: server.error-handler-404 = “/dispatch.fcgi”
Which turns the request into “/dispatch.fcgi”
That gets caught by: fastcgi.server = (".fcgi" =>…
And it finally ends up in Rails.
And how long does this take? Measure it.
My machine is a PowerBook G4 (1.67Ghz, 5,400RM laptop HD using HFS+)
running Lighttpd and setting the 404 handler to a static HTML file.
The file is 36kb so the network transfer isn’t an issue.
apachebench -n 5000 -c 5 gives me:
Requests per second: 1356.48 [#/sec] (mean)
For a direct request:
Requests per second: 1566.91 [#/sec] (mean)
As for a network drive:
Requests per second: 119.37 [#/sec] (mean)
Requests per second: 173.03 [#/sec] (mean)
This is for the same machine above accessing a directory mounted via
AFP over an 802.11g wireless connection. Hardly fast. The remote
server has a standard 80GB 7,200RPM hard drive using ReiserFS. Unless
you’re Yahoo or someone you won’t need to care, and I’d assume that
anyone actually running an app will use a decent fileserver with fast
interconnects and mount drives with NFS.
The bottom line is that the redirection doesn’t take any time worth
Why aren’t the servers setup to mount the app someplace like ‘app’ and
avoid all of this indirection? You can use fastcgi.server = ("/app" =>
to route all URLs starting with ‘app’ into Rails.
Yes, you can, but…
Other than letting you use ‘//host/controller/method/id’ instead of
‘//host/app/controller/method/id’ is there some other advantage to
trying to open the file first?
Page caching. Typo caches all blog posts as a whole action, so it’s
saved as a file. If you get slashdotted the majority of page requests
go like this:
Lighttpd finds file, sends file
Lighttpd forwards request to Rails app
Rails app finds file
Rails add sends file to Lighttpd
Lighttpd sends file to client.
This is Rails serving a static .rhtml file, same machine as above,
served from localhost:
Requests per second: 5.52 [#/sec] (mean)
If you want speed keep it outside of Rails. If you’re serving dynamic
pages the little bit of indirection costs very little compared to DB
queries and starting up a Rails app.