WEBrick High Performance
Rubyforge Project:
rubyforge.org/projects/rctools/
Documentation:
dev.robotcoop.com/Libraries/webrick-high-performance/
About
WEBrick High Performance adds a new HTTP server class that takes advantage of sendfile(2) and fork(2) to drastically improve static file server performance.
Since HighPerformanceServer is a forking webserver it may also speed up regular WEBrick servlets by spreading load across multiple CPUs.
The sendfile(2) system call allows web server writers to offload the job of transfering files from the disk to the socket onto the kernel. The work of parsing HTTP headers is very easy and very fast and WEBrick is nearly fast enough to match Apache.
When additional work is needed to look up or validate file access (for example, the file is stored in MogileFS) it is more performant to write the code in Ruby and use HighPerformanceServer than to write a FastCGI handler and easier than writing an Apache module.
Installing webrick-high-performance
webrick-high-performance depends upon socket_sendfile, and as of 1.0.0 socket_sendfile is only known to work on FreeBSD.
So if you’ve got FreeBSD you only need to install the gem:
$ sudo gem install webrick-high-performance
Using webrick-high-performance
#!/usr/local/bin/ruby -w
require 'rubygems'
require 'webrick'
require 'webrick/highperformanceserver'
config = {}
config[:Port] = 8000
config[:Root] = File. '~/public_html'
WEBrick::HighPerformanceServer.create config do |server|
trap 'INT' do server.shutdown end
trap 'TERM' do server.shutdown end
server.start
end