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

Implement a HttpUrlConnection and Apache HC4 based channels #335

Merged
merged 22 commits into from
Feb 18, 2020

Conversation

carterkozak
Copy link
Contributor

Gives us a data point to compare other clients with.

@carterkozak carterkozak changed the title Implement a HttpUrlConnection based channel Implement a HttpUrlConnection and Apache HC4 based channels Feb 16, 2020
@carterkozak carterkozak force-pushed the ckozak/blocking_channels branch from e14fb78 to 723ead7 Compare February 16, 2020 20:57
@carterkozak carterkozak force-pushed the ckozak/blocking_channels branch from 723ead7 to b718a73 Compare February 16, 2020 22:53
@changelog-app
Copy link

changelog-app bot commented Feb 17, 2020

Generate changelog in changelog/@unreleased

Type

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

Description

Implement a HttpUrlConnection and Apache HC4 based channels

Check the box to generate changelog(s)

  • Generate changelog entry

final class ApacheHttpClientBlockingChannel implements BlockingChannel {
private static final Logger log = LoggerFactory.getLogger(ApacheHttpClientBlockingChannel.class);

private final CloseableHttpClient client;
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok so at the moment we're potentially leaving a connection manager open by not closing this anywhere, which is why you wrote up #339 (comment) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's correct.

}
}
headers = tmpHeaders;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

seeing the lazy initialization of this makes me wonder if we should document the thread-safety expectations of Response somewhere?

String value = header.getValue();
if (value != null) {
tmpHeaders
.computeIfAbsent(header.getName(), _name -> new ArrayList<>(1))
Copy link
Contributor

@iamdanfox iamdanfox Feb 18, 2020

Choose a reason for hiding this comment

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

you sure you don't want to pull this out to a static method reference? ;) it's gonna allocate one whole lambda every time we call headers()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh you know I want to. Keeping simple for now :-)


@Override
public boolean isChunked() {
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, are there ever worlds where we explicitly wouldn't want chunked? Do people just do it when you know the request size and want to save the bytes in between each chunk?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's correct. There's an optimization where we could internally buffer data, and if we hit the end of content before something like 8k or 16k bytes we could send a content-length request.
We already have relatively large buffers configured at the OS level so we're fine writing to the socket, we just can't walk back to the headers and add a content-length.


private HttpUrlConnectionChannels() {}

public static Channel create(ClientConfiguration conf, UserAgent baseAgent, TaggedMetricRegistry metrics) {
Copy link
Contributor

@iamdanfox iamdanfox Feb 18, 2020

Choose a reason for hiding this comment

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

Low importance as I think this will be used for benchmarking over prod usage, but might be worth doing the same ClientConf preconditions here?

Kinda spicy that we literally can't even control cipher suites...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps in a follow-up, I have a WIP to move some of the validation to Channels.create we pick the node selection strategy, qos, etc.

I'll open a PR to update the readme with a description of each of our current clients and describe our confidence (e.g. don't use java9 or httpurlconnection)

include 'dialogue-client-test-lib'
include 'dialogue-core'
include 'dialogue-example'
include 'dialogue-httpurlconnection-client'
include 'dialogue-hc4-client'
include 'dialogue-java-client'
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it's not this PR, but could we rename this to dialogue-java9-client as the -java suffix is a bit overloaded in conjure-land

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can do that separately. I think email-service will need to be updated.

settings.gradle Outdated
include 'dialogue-client-test-lib'
include 'dialogue-core'
include 'dialogue-example'
include 'dialogue-httpurlconnection-client'
include 'dialogue-hc4-client'
Copy link
Contributor

@iamdanfox iamdanfox Feb 18, 2020

Choose a reason for hiding this comment

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

dialogue-apache-hc4? seems a tad over concise for anyone who doesn't know what HttpComponents4 are

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought hc stood for HttpClient, though that name is overloaded with java these days ;-)

Feign calls it httpclient https://github.com/OpenFeign/feign/tree/master/httpclient
As does dropwizard-metrics: https://metrics.dropwizard.io/3.1.0/manual/httpclient/

+1 for apache-hc4 to disambiguate from other clients.

@bulldozer-bot bulldozer-bot bot merged commit 0593d6b into develop Feb 18, 2020
@bulldozer-bot bulldozer-bot bot deleted the ckozak/blocking_channels branch February 18, 2020 17:11
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