Sha256: 1a09c3272c04ce78fbde4c572130694a635a4818ad6866513eb16c6f4b2604f0

Contents?: true

Size: 1.8 KB

Versions: 15

Compression:

Stored size: 1.8 KB

Contents

require "bundler"

require 'rack'
require 'rack/builder'
require 'rack/handler/puma'
require 'net/http'
require "benchmark"
require "cgi"
Bundler.require(:default)
require "instana/rack"

Thread.new do
  app = Rack::Builder.new {
    map "/" do
      run Proc.new { |env|
        [200, {"Content-Type" => "application/json"}, ["[\"Stan\",\"is\",\"on\",\"the\",\"scene!\"]"]]
      }
    end
    map "/error" do
      run Proc.new { |env|
        [500, {"Content-Type" => "application/json"}, ["[\"Stan\",\"is\",\"on\",\"the\",\"error!\"]"]]
      }
    end
  }

  Rack::Handler::Puma.run(app, {:Host => '127.0.0.1', :Port => 7011})
end

Thread.new do
  app = Rack::Builder.new {
    use ::Instana::Rack
    map "/" do
      run Proc.new { |env|
        [200, {"Content-Type" => "application/json"}, ["[\"Stan\",\"is\",\"on\",\"the\",\"scene!\"]"]]
      }
    end
    map "/error" do
      run Proc.new { |env|
        [500, {"Content-Type" => "application/json"}, ["[\"Stan\",\"is\",\"on\",\"the\",\"error!\"]"]]
      }
    end
  }

  Rack::Handler::Puma.run(app, {:Host => '127.0.0.1', :Port => 7012})
end

sleep(2)
puts "Rack server started in background thread on localhost:7011"
puts "Sleeping for 10 to allow announce"
sleep(10)


puts "Starting benchmarks"
Benchmark.bm do |x|

  uri = URI.parse("http://127.0.0.1:7011/")
  ::Net::HTTP.start(uri.host, uri.port) do |hc|
    x.report("vanilla") {
      1_000.times {
        req = Net::HTTP::Get.new(uri.request_uri)
        hc.request(req)
      }
    }
  end

  uri = URI.parse("http://127.0.0.1:7012/")
  ::Net::HTTP.start(uri.host, uri.port) do |hc|
    x.report("traced ") {
      1_000.times {
        ::Instana.tracer.start_or_continue_trace(:rack_call) do
          req = Net::HTTP::Get.new(uri.request_uri)
          hc.request(req)
        end
      }
    }
  end
end


sleep 10

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
instana-1.8.2 benchmarks/rack_vanilla_vs_traced.rb
instana-1.8.1 benchmarks/rack_vanilla_vs_traced.rb
instana-1.8.0 benchmarks/rack_vanilla_vs_traced.rb
instana-1.7.15 benchmarks/rack_vanilla_vs_traced.rb
instana-1.7.14 benchmarks/rack_vanilla_vs_traced.rb
instana-1.7.14a benchmarks/rack_vanilla_vs_traced.rb
instana-1.7.13 benchmarks/rack_vanilla_vs_traced.rb
instana-1.7.12 benchmarks/rack_vanilla_vs_traced.rb
instana-1.7.11 benchmarks/rack_vanilla_vs_traced.rb
instana-1.7.10 benchmarks/rack_vanilla_vs_traced.rb
instana-1.7.9 benchmarks/rack_vanilla_vs_traced.rb
instana-1.7.8 benchmarks/rack_vanilla_vs_traced.rb
instana-1.7.7 benchmarks/rack_vanilla_vs_traced.rb
instana-1.7.6 benchmarks/rack_vanilla_vs_traced.rb
instana-1.7.5 benchmarks/rack_vanilla_vs_traced.rb