首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wrk在Rack vs Sinatra基准测试中显示了奇怪的结果

wrk在Rack vs Sinatra基准测试中显示了奇怪的结果
EN

Stack Overflow用户
提问于 2015-07-30 09:48:52
回答 1查看 132关注 0票数 2

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

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

代码语言:javascript
复制
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

Sinatra:

代码语言:javascript
复制
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都运行瘦,为什么Sinatra管理3002.52~ req/s,而pure Rack仅管理551.05 req/s?我遗漏了什么?

EN

回答 1

Stack Overflow用户

发布于 2015-07-30 17:42:40

代码语言:javascript
复制
# 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是这样一个整洁的小库。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31713951

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档