Benchmarks
CPU-bound
Configuration:
- Ruby 4.0.9, 1 thread/fiber
- Raindeer 1.0.60 with LowType's strip mode, which removes types as classes load
- Each column requests the middle route of its group at that path depth, a typical request rather than the best or worst case for a router that checks routes in order
- Sinatra checks every route one by one in the order they are declared, so its speed depends on where a route sits in the list. Roda checks routes one by one too, but only within each branch of its routing tree
Note
Requests Per Second: This CPU-bound metric is a relatively small slice of time in comparison to the typical IO-bound tasks of web applications, such as waiting for the database.
Static routes are nested like REST resources, where a resource has its own route and child routes (/solo2, /solo2/duo5, /solo2/duo5/trio3). Routes with :id are REST collections and members (/solo5, /solo5/:id, /solo5/:id/duo6, /solo5/:id/duo6/:duo_id).
100 routes
40 one segment routes, 30 two segment routes and 30 three segment routes. Each column requests /solo20, /solo1/duo8 and /solo1/duo3/trio2.
| Server | GET / (req/s) | 1 segment (req/s) | 2 segments (req/s) | 3 segments (req/s) | Mean latency (3 segments) |
|---|---|---|---|---|---|
| Roda + Falcon | 20,571.45 | 17,425.18 | 18,745.35 | 18,859.74 | 2.651 ms |
| Raindeer + LowLoop | 19,346.93 | 18,099.27 | 17,711.95 | 16,914.99 | 2.956 ms |
| Raindeer + Falcon | 17,049.40 | 15,659.87 | 15,431.04 | 15,136.00 | 3.303 ms |
| Sinatra + Falcon | 11,033.59 | 9,332.01 | 7,940.30 | 7,084.63 | 7.058 ms |
| Hanami + Falcon | 6,693.12 | 6,661.28 | 6,694.91 | 6,684.02 | 7.481 ms |
| Rails + Falcon | 2,756.65 | 2,760.38 | 2,739.97 | 2,732.74 | 18.297 ms |
100 routes with :id
20 collections with their members, and 5 of them with 6 child collections and their members. Each column requests /solo10, /solo10/42, /solo3/42/duo3 and /solo3/42/duo3/7.
| Server | GET / (req/s) | 1 segment (req/s) | 2 segments (:id) (req/s) | 3 segments (req/s) | 4 segments (:id) (req/s) | Mean latency (4 segments (:id)) |
|---|---|---|---|---|---|---|
| Roda + Falcon | 21,692.96 | 19,984.43 | 19,183.86 | 17,197.22 | 16,931.06 | 2.953 ms |
| Raindeer + LowLoop | 19,356.31 | 17,808.34 | 16,516.46 | 15,904.88 | 15,064.95 | 3.319 ms |
| Raindeer + Falcon | 16,820.25 | 15,933.16 | 14,841.76 | 14,393.95 | 13,932.42 | 3.589 ms |
| Sinatra + Falcon | 10,922.09 | 9,833.31 | 9,386.60 | 6,536.77 | 6,409.12 | 7.801 ms |
| Hanami + Falcon | 6,840.65 | 6,817.94 | 6,286.20 | 6,274.15 | 5,977.25 | 8.365 ms |
| Rails + Falcon | 2,757.84 | 2,756.15 | 2,703.79 | 2,700.17 | 2,650.13 | 18.867 ms |
1000 routes
400 one segment routes, 300 two segment routes and 300 three segment routes. Each column requests /solo200, /solo5/duo15 and /solo5/duo5/trio2.
| Server | GET / (req/s) | 1 segment (req/s) | 2 segments (req/s) | 3 segments (req/s) | Mean latency (3 segments) |
|---|---|---|---|---|---|
| Raindeer + LowLoop | 19,131.09 | 17,735.81 | 17,482.23 | 16,924.33 | 2.954 ms |
| Roda + Falcon | 20,876.98 | 8,700.77 | 17,056.16 | 17,410.18 | 2.872 ms |
| Raindeer + Falcon | 16,564.38 | 15,589.56 | 15,214.07 | 14,810.57 | 3.376 ms |
| Hanami + Falcon | 6,385.41 | 6,788.65 | 6,737.77 | 6,812.12 | 7.340 ms |
| Sinatra + Falcon | 10,460.21 | 4,136.21 | 1,791.02 | 1,698.20 | 29.443 ms |
| Rails + Falcon | 2,731.73 | 2,717.46 | 2,707.59 | 2,683.12 | 18.635 ms |
1000 routes with :id
200 collections with their members, and 10 of them with 30 child collections and their members. Each column requests /solo100, /solo100/42, /solo5/42/duo15 and /solo5/42/duo15/7.
| Server | GET / (req/s) | 1 segment (req/s) | 2 segments (:id) (req/s) | 3 segments (req/s) | 4 segments (:id) (req/s) | Mean latency (4 segments (:id)) |
|---|---|---|---|---|---|---|
| Raindeer + LowLoop | 19,709.25 | 17,806.65 | 16,747.22 | 16,203.84 | 15,382.27 | 3.250 ms |
| Raindeer + Falcon | 16,933.32 | 15,822.95 | 14,737.21 | 14,322.31 | 13,738.07 | 3.640 ms |
| Roda + Falcon | 20,781.29 | 13,895.20 | 13,597.80 | 9,891.65 | 9,791.73 | 5.106 ms |
| Hanami + Falcon | 6,802.30 | 6,751.44 | 6,276.63 | 6,229.99 | 5,946.48 | 8.408 ms |
| Sinatra + Falcon | 10,785.82 | 4,244.31 | 4,388.23 | 1,716.07 | 1,712.73 | 29.193 ms |
| Rails + Falcon | 2,715.48 | 2,718.58 | 2,677.91 | 2,655.20 | 2,623.35 | 19.060 ms |
Templates
The route tables above return a plain string. Here, Raindeer and Roda both render the same list of 10 users, with each value HTML escaped: Raindeer as an RBX template and Roda as an ERB template with its render plugin. Raindeer uses Antlers, which compiles RBX templates to Ruby on their first render, like ERB.
| Server | Template (req/s) | Mean latency (Template) |
|---|---|---|
| Roda + Falcon | 17,731.39 | 2.820 ms |
| Raindeer + LowLoop | 15,329.78 | 3.262 ms |
| Raindeer + Falcon | 13,933.34 | 3.589 ms |
*LowLoop is the default server for Raindeer
See: raindeer-benchmarks repo
IO-bound
Each request to /slow waits 50ms, like a database query, then returns a plain string. One request at a time could do 20 requests per second, so the most a server can do is 20 times the number of requests sent at once. Every app has the same 1000 routes as above.
Every server here waits on requests with Ruby's fiber scheduler, so they all reach that limit at 50 at once, and most do at 200. The differences show at 1000 at once, where each server's CPU cost per request starts to count. Rails timed out at 1000 at once: some of its requests waited longer than Apache Bench's 30 second limit, which stops the test.
| Server | /slow, 50 at once (req/s) | /slow, 200 at once (req/s) | /slow, 1000 at once (req/s) | Mean latency (/slow, 1000 at once) |
|---|---|---|---|---|
| Roda + Falcon | 928.02 | 3,668.80 | 11,940.33 | 83.750 ms |
| Raindeer + Falcon | 937.70 | 3,720.49 | 11,044.21 | 90.545 ms |
| Raindeer + LowLoop | 934.81 | 3,707.42 | 10,336.65 | 96.743 ms |
| Sinatra + Falcon | 936.30 | 3,668.58 | 7,362.98 | 135.815 ms |
| Hanami + Falcon | 914.06 | 3,543.84 | 4,448.49 | 224.796 ms |
| Rails + Falcon | 938.15 | 2,497.55 | timed out | timed out |
Integrations
These integrations are experimental and don't suport the full Raindeer API such as Interval yet.
Falcon
Iodine
If you really need CPU-bound speed then you can boot Raindeer via Iodine. Compared to LowLoop, this currently increases requests per second by ~10-16% and decreases latency by ~14%. It involves a Rack adapter (for now) and of course, the absence of LowLoop with its Matrix, Interval and Async related features.
Iodine Boot:
require 'iodine'
require_relative 'rack_adapter'
Iodine.threads = 1
Iodine.workers = 1
port = ENV.fetch('PORT', '4133')
address = ENV.fetch('BIND', '127.0.0.1')
Iodine.listen(service: :http, handler: RackAdapter.new, port:, address:)
Iodine.start
Rack Adapter:
require 'bundler/setup'
require 'rack'
require 'raindeer/boot'
Low::Events::RequestEvent.define do |observers|
observers << Providers['rain.router']
end
class RackAdapter
HEADER_NAME_CACHE = Hash.new { |cache, key| cache[key] = key.delete_prefix('HTTP_').tr('_', '-').downcase.freeze }
def call(env)
http_request = build_request(env)
response = Low::Events::RequestEvent.take(request: http_request).response
build_rack_response(response)
end
private
BODY_METHODS = %w[POST PUT PATCH].freeze
def build_request(env)
body = env['rack.input']&.read if BODY_METHODS.include?(env['REQUEST_METHOD'])
body = nil if body.nil? || body.empty?
headers = Protocol::HTTP::Headers.new(
env.filter_map do |key, value|
next unless key.start_with?('HTTP_')
[HEADER_NAME_CACHE[key], value]
end
)
query = env['QUERY_STRING']
path = query.nil? || query.empty? ? env['PATH_INFO'] : "#{env['PATH_INFO']}?#{query}"
authority = env['HTTP_HOST'] || "#{env['SERVER_NAME']}:#{env['SERVER_PORT']}"
Protocol::HTTP::Request.new(
env['rack.url_scheme'],
authority,
env['REQUEST_METHOD'],
path,
'HTTP/1.1',
headers,
body
)
end
def build_rack_response(response)
body_data = response.body.respond_to?(:file) ? File.binread(response.body.file.path) : (response.body.read || '')
rack_headers = {}
response.headers.fields.each { |key, value| rack_headers[key.to_s] = value.to_s }
rack_headers['content-length'] ||= body_data.bytesize.to_s
[response.status, rack_headers, [body_data]]
end
end