-
Notifications
You must be signed in to change notification settings - Fork 375
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
Reuse HTTP connection between trace flushes #2227
base: master
Are you sure you want to change the base?
Conversation
3646aa4
to
7d8b375
Compare
7d8b375
to
a139144
Compare
a139144
to
7f68980
Compare
1747a53
to
354311a
Compare
def open_file_descriptors | ||
# Unix-specific way to get the current process' open file descriptors and the files (if any) they correspond to | ||
Dir['/dev/fd/*'].each_with_object({}) do |fd, hash| | ||
hash[fd] = | ||
begin | ||
File.realpath(fd) | ||
rescue SystemCallError # This can fail due to... reasons, and we only want it for debugging so let's ignore | ||
nil | ||
end | ||
end | ||
end |
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.
8248b34
to
da5c144
Compare
spec/support/test_access_patch.rb
Outdated
@@ -1,30 +0,0 @@ | |||
# typed: true |
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.
We have this quite clever monkey patch to expose private members for testing, but is actually never used.
This kind of test-specific, internal access to the tracer (specifically monitoring if the AsyncTransport
has finished flushing) was the best way to write reliable tests around HTTP connection reuse.
But polluting the main class space with methods that won't actually be present when users use ddtrace
in production is scary, since we could write features that use methods that are not available in production, but will always succeed in our test suite.
Because of this, I've moved this monkey patching to a refinement, so that it only applies to the current spec file under test, never leaking to lib/
code.
Because the file changed so much, git thinks I completely deleted it (which I kind of did, for most of the unused features). spec/support/test_access_refinement.rb
contains these new refinements.
ba77e58
to
403da37
Compare
5559f7b
to
919b126
Compare
Codecov Report
@@ Coverage Diff @@
## master #2227 +/- ##
==========================================
- Coverage 98.32% 98.32% -0.01%
==========================================
Files 1120 1125 +5
Lines 60401 60703 +302
==========================================
+ Hits 59389 59685 +296
- Misses 1012 1018 +6
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
919b126
to
6d5a150
Compare
6fe546d
to
12fd980
Compare
12fd980
to
ad96d3e
Compare
I think it would be a bit safer to implement a retry logic first, as unforeseen persistent connections issues would be mitigated by a retry mechanism
This PR changes the Tracing HTTP transport adapter (
lib/ddtrace/transport/http/adapters/net.rb
) to reuse its HTTP connection internally.Previously, we created a new connection and closed it on every trace batch flush, which can happens as frequently as once per second.
This PR does not close the connection, and instead reuses it for successive flushes.
If the remote connection errs out (e.g. other side closes the connection), the connection will be retried internally by
Net::HTTP
.Benchmarking
Invoke the tracer transport pipeline, flushing a single trace containing 50 spans. The tail end of the pipeline will invoke the HTTP client modified in this PR.
Results in "transport flushes per second".
Before
After
Reusing the HTTP connection is 1.75x faster then creating a brand new connection every time.