Skip to content

Instantly share code, notes, and snippets.

@sdogruyol
Created January 5, 2016 06:48
Show Gist options
  • Save sdogruyol/34ffe2f60acfeba9b095 to your computer and use it in GitHub Desktop.
Save sdogruyol/34ffe2f60acfeba9b095 to your computer and use it in GitHub Desktop.

Kemal vs Sinatra Benchmark

This is just for demonstration purpose. A simple app just returning "Hello World". First in Kemal (Crystal) and then in Sinatra(Ruby with thin).

Kemal (Crystal)

Kemal Version: 0.6.0 Crystal Version: 0.10.0

# app.cr
require "kemal"

get "/" do
  "Hello World!"
end

Sinatra (Ruby with Thin)

Sinatra Version: 1.4.6 Ruby Version: 2.2.2p95 Thin Version: 1.6.4

# app.rb
require "sinatra"

set :environment, :production
set :server, %w[thin]

get "/" do
  "Hello World!"
end

Running the benchmark

wrk is used to run this benchmark with 100 connections.

To run Kemal: crystal build --release src/app.cr && ./app To run Sinatra: ruby app.rb -p 3000

Finally to run benchmark:

wrk -c 100 -d 20 http://localhost:3000

@wieczorek1990
Copy link

So, I've enabled threads in uwsgi and rerun the test:

Running:

uwsgi --wsgi-file app.py --http :3000 --callable app -T
Running 20s test @ http://localhost:3002
  2 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    30.59ms    7.60ms 228.06ms   97.35%
    Req/Sec     1.65k   125.58     1.96k    70.50%
  65673 requests in 20.01s, 5.70MB read
  Socket errors: connect 0, read 65672, write 0, timeout 0
Requests/sec:   3281.32
Transfer/sec:    291.60KB

@wieczorek1990
Copy link

Well I run Sinatra with passenger and it's a lot better:

#app.rb
require 'sinatra/base'

class HelloApp < Sinatra::Base
  get '/' do
    'Hello World!'
  end
end
#config.ru
require File.absolute_path("app.rb")

run HelloApp
#Gemfile
source 'https://rubygems.org/'

gem 'sinatra'
gem 'passenger'

Running:

set -x RACK_ENV production
bundle exec passenger start

Results:

Running 20s test @ http://localhost:3002
  2 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    20.52ms    8.85ms 210.95ms   93.66%
    Req/Sec     2.51k   274.79     3.05k    74.75%
  99720 requests in 20.01s, 33.28MB read
Requests/sec:   4982.54
Transfer/sec:      1.66MB

@wieczorek1990
Copy link

You should list the command line options on the website. Had trouble finding the production mode.

@wieczorek1990
Copy link

You could write that kemal needs ssl development headers to build (libssl-dev).
Made some other benchmarks, put them in a docker. Gonna test rust frameworks someday.
https://github.com/wieczorek1990/benchmarks

@wieczorek1990
Copy link

Added rust: nickel and iron.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment