我正在使用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.74KBSinatra:
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?我遗漏了什么?
发布于 2015-07-30 17:42:40
# 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是这样一个整洁的小库。
https://stackoverflow.com/questions/31713951
复制相似问题