Sha256: 21f7e6578c37ffe42e772b975e085d76ce547344360002bb33ad620a824c6d1d

Contents?: true

Size: 1.99 KB

Versions: 19

Compression:

Stored size: 1.99 KB

Contents

# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2017

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 {
        [200, {"Content-Type" => "application/json"}, ["[\"Stan\",\"is\",\"on\",\"the\",\"scene!\"]"]]
      }
    end
    map "/error" do
      run Proc.new {
        [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 {
        [200, {"Content-Type" => "application/json"}, ["[\"Stan\",\"is\",\"on\",\"the\",\"scene!\"]"]]
      }
    end
    map "/error" do
      run Proc.new {
        [500, {"Content-Type" => "application/json"}, ["[\"Stan\",\"is\",\"on\",\"the\",\"error!\"]"]]
      }
    end
  }

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

puts ""
puts "Vanilla Rack server started in background thread on localhost:7011"
puts "Instrumented Rack server started in background thread on localhost:7012"
puts ""
puts "Waiting on successful announce to host agent..."
puts ""

while !::Instana.agent.ready? do
  sleep 2
end

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

19 entries across 19 versions & 1 rubygems

Version Path
instana-1.199.6 benchmarks/rack_vanilla_vs_traced.rb
instana-1.199.5 benchmarks/rack_vanilla_vs_traced.rb
instana-1.199.4 benchmarks/rack_vanilla_vs_traced.rb
instana-1.199.3 benchmarks/rack_vanilla_vs_traced.rb
instana-1.199.2 benchmarks/rack_vanilla_vs_traced.rb
instana-1.199.1 benchmarks/rack_vanilla_vs_traced.rb
instana-1.199.0 benchmarks/rack_vanilla_vs_traced.rb
instana-1.198.0 benchmarks/rack_vanilla_vs_traced.rb
instana-1.198.0.pre1 benchmarks/rack_vanilla_vs_traced.rb
instana-1.197.0 benchmarks/rack_vanilla_vs_traced.rb
instana-1.197.0.pre2 benchmarks/rack_vanilla_vs_traced.rb
instana-1.197.0.pre1 benchmarks/rack_vanilla_vs_traced.rb
instana-1.195.4 benchmarks/rack_vanilla_vs_traced.rb
instana-1.195.3 benchmarks/rack_vanilla_vs_traced.rb
instana-1.195.2 benchmarks/rack_vanilla_vs_traced.rb
instana-1.195.1 benchmarks/rack_vanilla_vs_traced.rb
instana-1.195.0 benchmarks/rack_vanilla_vs_traced.rb
instana-1.193.6 benchmarks/rack_vanilla_vs_traced.rb
instana-1.193.5 benchmarks/rack_vanilla_vs_traced.rb