Skip to content

Add "ConcurrencyAcquireDuration" metric for apache-client #2912

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

Merged
merged 8 commits into from
Dec 14, 2021

Conversation

Bennett-Lynch
Copy link
Contributor

The time taken to acquire a new channel from a channel pool can be both non-trivial and highly variable, depending upon whether a new connection needs to be established, and depending upon the overhead of new connection establishment (including TLS handshakes).

The same metric was recently added for netty-nio-client: #2903

Ideally we would avoid the use of ThreadLocal, but the Apache interfaces make it very difficult to expose a request-level MetricsCollector to the connection acquire call. While we can easily wrap a HttpClientConnectionManager to include metrics, the HttpClientConnectionManager, is declared at the Apache-client-level, meaning we would need to create (not just wrap) a new Apache client instance for every request. Apache offers the HttpContext class to help propagate arbitrary attributes, but the context object is not exposed to HttpClientConnectionManager#requestConnection or ConnectionRequest#get. To lease & establish new connection, Apache calls requestConnection/connect. To lease an already-established connection, Apache calls only requestConnection. And only connect is given the context object.

License

  • I confirm that this pull request can be released under the Apache 2 license

The time taken to acquire a new channel from a channel pool can be both
non-trivial and highly variable, depending upon whether a new connection
needs to be established, and depending upon the overhead of new
connection establishment (including TLS handshakes).

The same metric was recently added for netty-nio-client:
aws#2903
@Bennett-Lynch Bennett-Lynch requested a review from a team as a code owner December 11, 2021 05:09
Comment on lines 83 to 93
Instant startGet = null;
if ("get".equals(method.getName())) {
startGet = Instant.now();
}
try {
return method.invoke(orig, args);
} finally {
if (startGet != null) {
recordGetTime(startGet);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to use a dynamic proxy instead of just implementing the ConnectionRequest interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I don't see any reason we must use a proxy here since this is an interface and not a final class. I was just taking advantage of the existing infrastructure that was seemingly awaiting this metric to be plugged in. :) But let me modify it to just use a simple delegation scheme.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use delegation instead. I think the primary reason to use a proxy is that it would automatically support any new interface methods that are added. I don't know how likely that is to happen with these interfaces.

@Bennett-Lynch Bennett-Lynch changed the title Add "ChannelAcquireDuration" metric for apache-client Add "ConcurrencyAcquireDuration" metric for apache-client Dec 13, 2021
@Bennett-Lynch Bennett-Lynch enabled auto-merge (squash) December 14, 2021 00:09
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

76.9% 76.9% Coverage
0.0% 0.0% Duplication

@Bennett-Lynch Bennett-Lynch merged commit 1f15812 into aws:master Dec 14, 2021
aws-sdk-java-automation added a commit that referenced this pull request Feb 29, 2024
…a4bdfc7f6

Pull request: release <- staging/2e29ee54-41b8-4e6f-abe1-e97a4bdfc7f6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants