Skip to content
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

ApacheHttpClientBlockingChannel uses URL to build request #2437

Merged

Conversation

schlosna
Copy link
Contributor

Before this PR

Noticed new URI(String) and some of its side effects in JFRs from services making high volumes of Dialogue requests.

Splitting out of PR #2432

After this PR

==COMMIT_MSG==
Parsing String to URI can be expensive in terms of CPU and allocations for high throughput services.
==COMMIT_MSG==

Possible downsides?

@schlosna schlosna requested a review from carterkozak November 26, 2024 17:27
@changelog-app
Copy link

changelog-app bot commented Nov 26, 2024

Generate changelog in changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Parsing String to URI can be expensive in terms of CPU and allocations for high throughput services.

Check the box to generate changelog(s)

  • Generate changelog entry

Comment on lines 186 to 195
try {
return URIAuthority.create(url.getAuthority());
} catch (URISyntaxException e) {
throw new SafeIllegalArgumentException("Invalid URI authority", e, UnsafeArg.of("url", url));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it's worth rolling the dice with something along these lines to avoid string tokenizing/manipulation overhead? We have most of the data parsed out via URL already, I believe it's just ipv6 brackets that URL doesn't handle well.

String host = url.getHost();
if (host != null && host.startsWith("[") && host.endsWith("]")) {
    host = host.substring(1, host.length() - 1);
}
return new URIAuthority(url.getUserInfo(), host, url.getPort());

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively, it may be safer if we check host != null && host.startsWith("[") and in that case, we use the parsing URIAuthority.create path, otherwise (in the common case) use new URIAuthority(url.getUserInfo(), host, url.getPort());

@VisibleForTesting
static URIAuthority parseAuthority(URL url) {
try {
return URIAuthority.create(url.getAuthority());
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 I've verified that url.getAuthority() is equivalent to URI.getRawAuthority(), which is used internally within apache httpclient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"https://www.example.com:443, www.example.com, 443,",
"https://www.example.com/path/to/foo/bar, www.example.com, -1,",
"https://www.example.com/path/to/foo/bar?baz=quux&hello=world#hash-octothorpe, www.example.com, -1,",
"https://[email protected]:8443/path/to/foo/bar?baz=quux&hello=world#hash-octothorpe ,"
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a couple test cases for encoding edge cases:

  • A URL which includes percent-escaped values in the users password: https://user:slash%[email protected]
  • A URL which includes bracket-formatted ipv6 address: https://user@[::1]/path (perhaps with and without a port)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, added some more test coverage.

@schlosna schlosna force-pushed the davids/ApacheHttpClientBlockingChannel-target branch from b83036c to 76686b4 Compare November 29, 2024 16:47
@schlosna schlosna force-pushed the davids/ApacheHttpClientBlockingChannel-target branch from c637a13 to a03da51 Compare December 1, 2024 04:02
Copy link
Contributor

@carterkozak carterkozak left a comment

Choose a reason for hiding this comment

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

thanks!

@bulldozer-bot bulldozer-bot bot merged commit d5e6f2c into develop Dec 2, 2024
6 checks passed
@bulldozer-bot bulldozer-bot bot deleted the davids/ApacheHttpClientBlockingChannel-target branch December 2, 2024 14:21
@autorelease3
Copy link

autorelease3 bot commented Dec 2, 2024

Released 4.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants