【问题标题】:wrk is displaying odd results on Rack vs Sinatra benchmarkwrk 在 Rack vs Sinatra 基准测试中显示奇怪的结果
【发布时间】:2015-10-21 05:32:38
【问题描述】:

我正在使用 sinatra 和 rack 对“hello world”等价物进行基准测试。

有问题的命令wrk -t12 -c400 -d30s:12 个线程,400 个打开的 HTTP 连接,30 秒。

机架:

require 'rack'

app = Proc.new do |env|
    ['200', {'Content-Type' => 'text/html'}, ['A barebones rack app.']]
end

Rack::Handler::Thin.run app

# wrk $ wrk -t12 -c400 -d30s http://localhost:8080
# Running 30s test @ http://localhost:8080
#   12 threads and 400 connections
#   Thread Stats   Avg      Stdev     Max   +/- Stdev
#     Latency    11.82ms   38.97ms 488.51ms   99.32%
#     Req/Sec   705.04    568.62     2.20k    61.82%
#   16576 requests in 30.08s, 1.55MB read
#   Socket errors: connect 157, read 274, write 0, timeout 0
# Requests/sec:    551.05
# Transfer/sec:     52.74KB

辛纳屈:

require 'sinatra'

get '/' do
  status 200
  headers \
    'Content-Type' => 'text/html'
  'A barebones rack app.'
end

# wrk $ wrk -t12 -c400 -d30s http://localhost:4567
# Running 30s test @ http://localhost:4567
#   12 threads and 400 connections
#   Thread Stats   Avg      Stdev     Max   +/- Stdev
#     Latency    40.12ms   90.46ms   1.39s    98.67%
#     Req/Sec   265.47    147.50     1.17k    73.15%
#   90322 requests in 30.08s, 18.78MB read
#   Socket errors: connect 157, read 333, write 0, timeout 0
# Requests/sec:   3002.52
# Transfer/sec:    639.21KB

规格:

如果 Rack 和 Sinatra 都运行 Thin,为什么 Sinatra 管理 3002.52~ req/s 而纯 Rack 只管理 551.05 req/s?我错过了什么?

【问题讨论】:

标签: ruby sinatra benchmarking rack wrk


【解决方案1】:

我没有安装 wrk,我没有心情安装,但我使用 time 运行了你的两个示例:

# run.sh
for i in {1..1000}
do 
  curl localhost:8080/ > /dev/null 2>&1
done

# sinatra, run via `bundle exec ruby sinatra.rb -p 8080`
$ time sh run.sh             
sh run.sh  3.67s user 2.79s system 66% cpu 9.768 total

# rack, run via `bin/rackup config.ru`
$ time sh run.sh
sh run.sh  3.65s user 2.87s system 74% cpu 8.799 total

# sinatra with the puma server, by adding the line `set :server, "puma"`
$ time sh run.sh      
sh run.sh  3.67s user 2.71s system 92% cpu 6.924 total

我得到了非常相似的结果,所以这可能与wrk 或您的系统有关。我正在运行 OSX Mavericks,但我发现 this answer 表示要使用 time 进行基准测试,您应该真正使用 chrt 以避免与其他进程发生争用。我不确定chrt 的OSX 等价物是什么。也许这就是您的系统上正在发生的事情,或者端口以不同的速度运行,无论出于何种原因。

我还使用 bundle install --binstubs --path vendor.noindex 对我的 gem 进行了沙盒处理,也许这也会对您的系统产生影响。

否则,我看不出造成这种差异的任何原因。我对我得到的结果有点惊讶,因为我预计 Sinatra 比 Rack 重很多,但对于更复杂或更大的应用程序,情况似乎有所不同。或许不是,Sinatra 是一个如此整洁的小图书馆。

【讨论】:

    猜你喜欢
    • 2012-06-27
    • 2018-02-15
    • 2020-07-04
    • 2014-04-24
    • 2013-11-22
    • 1970-01-01
    • 1970-01-01
    • 2011-12-26
    • 2016-10-04
    相关资源
    最近更新 更多