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

Optimize target selection and URI parsing #2398

Merged
merged 5 commits into from
Nov 1, 2024
Merged

Conversation

schlosna
Copy link
Contributor

Before this PR

While reviewing some JFRs from dialogue client heavy service, notice that there are a lot of byte[] allocations as a result of parsing String to URI. In most cases, these will be be the same input string, so are good candidates for caching.

image

After this PR

==COMMIT_MSG==
Optimize target selection and URI parsing
==COMMIT_MSG==

Possible downsides?

We don't have a great way to inject cache sizing/weight configuration or tagged metrics, so for now have hardcoded max cache weight.

@schlosna schlosna requested a review from carterkozak October 28, 2024 03:50
@changelog-app
Copy link

changelog-app bot commented Oct 28, 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

Optimize target selection and URI parsing

Check the box to generate changelog(s)

  • Generate changelog entry

Sorry, something went wrong.

Comment on lines 200 to 202
TargetUri.Builder builder = TargetUri.builder().uri(uri);
targetUris.addAll(Collections2.transform(resolvedAddresses, addr -> builder.resolvedAddress(addr)
.build()));
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a big fan of the partial-builder-as-factory pattern, since sometimes folks add protections later on to prevent interactions after build() is called. It shouldn't be an issue here since. the TargetUri type is defined within this repo, so I don't have a terribly strong preference

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we add an efficient TargetUri.of(uri, address) factory method to use instead? That way we bypass the builder entirely.

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 call, updated

.register(stats -> Caffeine.newBuilder()
.maximumWeight(100_000)
.<String, Parsed>weigher((key, _value) -> key.length())
.expireAfterAccess(Duration.ofMinutes(1))
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@schlosna schlosna force-pushed the davids/dns-uri branch 2 times, most recently from 536c6bf to 83c3c0d Compare October 31, 2024 13:12
@carterkozak
Copy link
Contributor

I'm not sure why that check is failing on this PR, but I suspect merging this will fix it: #2403

@carterkozak
Copy link
Contributor

#2403 has merged, could you please rebase this to develop when you have a moment?

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 2559a97 into develop Nov 1, 2024
6 checks passed
@bulldozer-bot bulldozer-bot bot deleted the davids/dns-uri branch November 1, 2024 16:49
@autorelease3
Copy link

autorelease3 bot commented Nov 1, 2024

Released 4.3.0

schlosna added a commit that referenced this pull request Nov 22, 2024
Parsing String to URI can be expensive in terms of CPU and allocations
for high throughput services. This generalizes the caching previously
added to DnsSupport in #2398 to
also cover ApacheHttpClientBlockingChannel requests and
HttpsProxyDefaultRoutePlanner proxy parsing to leverage a shared parsed
URI cache.
schlosna added a commit that referenced this pull request Nov 22, 2024
Parsing String to URI can be expensive in terms of CPU and allocations
for high throughput services. This generalizes the caching previously
added to DnsSupport in #2398 to
also cover ApacheHttpClientBlockingChannel requests and
HttpsProxyDefaultRoutePlanner proxy parsing to leverage a shared parsed
URI cache.
schlosna added a commit that referenced this pull request Jan 26, 2025
Parsing String to URI can be expensive in terms of CPU and allocations
for high throughput services. This generalizes the caching previously
added to DnsSupport in #2398 to
also cover ApacheHttpClientBlockingChannel requests and
HttpsProxyDefaultRoutePlanner proxy parsing to leverage a shared parsed
URI cache.
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.

None yet

3 participants