-
Notifications
You must be signed in to change notification settings - Fork 398
Reuse HTTP connection between trace flushes #2227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e7f3073
Reuse HTTP connection between trace flushes
marcotc ad96d3e
Benchmark
marcotc a0b3268
Small cleanup
marcotc ef8f890
Address agent remote disconnection
marcotc 0757d06
Remove unused require
marcotc 27c8260
Add comment for future reference
marcotc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # frozen_string_literal: true | ||
| # typed: false | ||
|
|
||
| # Used to quickly run benchmark under RSpec as part of the usual test suite, to validate it didn't bitrot | ||
| VALIDATE_BENCHMARK_MODE = ENV['VALIDATE_BENCHMARK'] == 'true' | ||
|
|
||
| return unless __FILE__ == $PROGRAM_NAME || VALIDATE_BENCHMARK_MODE | ||
|
|
||
| require 'benchmark/ips' | ||
| require 'ddtrace' | ||
| require 'webrick' | ||
| require_relative 'dogstatsd_reporter' | ||
|
|
||
| class TracingHttpTransportBenchmark | ||
| def initialize | ||
| @port = Datadog::Transport::HTTP::DO_NOT_USE_ENVIRONMENT_AGENT_SETTINGS.port | ||
| @transport = Datadog::Transport::HTTP.default | ||
| @spans = test_traces(50) | ||
| end | ||
|
|
||
| def start_fake_webserver | ||
| ready_queue = Queue.new | ||
|
|
||
| require 'webrick' | ||
|
|
||
| server = WEBrick::HTTPServer.new( | ||
| Port: @port, | ||
| StartCallback: -> { ready_queue.push(1) } | ||
| ) | ||
| server_proc = proc do |req, res| | ||
| res.body = '{}' | ||
| end | ||
|
|
||
| server.mount_proc('/', &server_proc) | ||
| Thread.new { server.start } | ||
| ready_queue.pop | ||
| end | ||
|
|
||
| # Return some test traces | ||
| def test_traces(n, service: 'test-app', resource: '/traces', type: 'web') | ||
| traces = [] | ||
|
|
||
| n.times do | ||
| trace_op = Datadog::Tracing::TraceOperation.new | ||
|
|
||
| trace_op.measure('client.testing', service: service, resource: resource, type: type) do | ||
| trace_op.measure('client.testing', service: service, resource: resource, type: type) do | ||
| end | ||
| end | ||
|
|
||
| traces << trace_op.flush! | ||
| end | ||
|
|
||
| traces | ||
| end | ||
|
|
||
| def run_benchmark | ||
| Benchmark.ips do |x| | ||
| benchmark_time = VALIDATE_BENCHMARK_MODE ? { time: 0.01, warmup: 0 } : { time: 70, warmup: 2 } | ||
| x.config(**benchmark_time, suite: report_to_dogstatsd_if_enabled_via_environment_variable(benchmark_name: 'tracing_http_transport')) | ||
|
|
||
| x.report("http_transport #{ENV['CONFIG']}") do | ||
| run_once | ||
| end | ||
|
|
||
| x.save! 'tmp/tracing-http-transport-results.json' unless VALIDATE_BENCHMARK_MODE | ||
| x.compare! | ||
| end | ||
| end | ||
|
|
||
| def run_forever | ||
| while true | ||
| 100.times { run_once } | ||
| print '.' | ||
| end | ||
| end | ||
|
|
||
| def run_once | ||
| success = @transport.send_traces(@spans) | ||
|
|
||
| raise('Unexpected: Export failed') unless success | ||
| end | ||
| end | ||
|
|
||
| puts "Current pid is #{Process.pid}" | ||
|
|
||
| TracingHttpTransportBenchmark.new.instance_exec do | ||
| if ARGV.include?('--forever') | ||
| run_forever | ||
| else | ||
| run_benchmark | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,6 +95,8 @@ def stop | |
| def stop_worker | ||
| @stopped = true | ||
|
|
||
| @transport.stop | ||
|
|
||
| return if @worker.nil? | ||
|
|
||
| @worker.stop | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to a shared spec helper, now that checking for leaked FDs is needed in multiple places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided not to use this approach for HTTP testing, but I feel like this refactor is still good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should move this out of this PR.