macournoyer / thin-turbo

New and ultra-turbo-crazy-fast backend for Thin

macournoyer (author)
Wed Jun 11 19:32:21 -0700 2008
commit  b708830bd819c5b733441b45a4ecb626a9da0d74
tree    b26aa27df2b16c37ca4e92735ae3cf1a658f32b9
parent  8217c704e02202e9a1bf2a92aaf6c0adce38835f
thin-turbo / benchmark / app.rb
100644 28 lines (20 sloc) 0.548 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'rubygems'
require 'rack'
require 'rack/request'
 
class App
  MIN_SIZE = 512
  
  def initialize
    @calls = 0
  end
  
  def call(env)
    status = 200
    body = []
    request = Rack::Request.new(env)
    @calls += 1
    
    sleep request.params['wait'].to_i if request.params['wait'] && @calls % 10 == 0
    
    body << 'X' * (request.params['size'] || MIN_SIZE).to_i
    body << "\r\n"
    
    headers = { 'Content-Type' => 'text/plain', 'Content-Length' => body.join.size.to_s }
    
    [status, headers, body]
  end
end