Skip to content

Remove eventLoopGroup and hostResolver configs #2017

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 1 commit into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ private boolean testWithClient(KmsAsyncClient asyncKMSClient, int numberOfReques

private boolean testWithNewClient(int eventLoopSize, int numberOfRequests) {

try (EventLoopGroup eventLoopGroup = new EventLoopGroup(eventLoopSize);
HostResolver hostResolver = new HostResolver(eventLoopGroup);
SdkAsyncHttpClient newAwsCrtHttpClient = AwsCrtAsyncHttpClient.builder()
.eventLoopGroup(eventLoopGroup)
.hostResolver(hostResolver)
try (SdkAsyncHttpClient newAwsCrtHttpClient = AwsCrtAsyncHttpClient.builder()
.build()) {
try (KmsAsyncClient newAsyncKMSClient = KmsAsyncClient.builder()
.region(REGION)
Expand Down Expand Up @@ -162,12 +158,7 @@ public void checkAllCombinations(@FromDataPoints("EventLoop") int eventLoopSize,
.put(SdkHttpConfigurationOption.MAX_CONNECTIONS, connectionPoolSize)
.build();

EventLoopGroup eventLoopGroup = new EventLoopGroup(eventLoopSize);
HostResolver hostResolver = new HostResolver(eventLoopGroup);

SdkAsyncHttpClient awsCrtHttpClient = AwsCrtAsyncHttpClient.builder()
.eventLoopGroup(eventLoopGroup)
.hostResolver(hostResolver)
.buildWithDefaults(attributes);

KmsAsyncClient sharedAsyncKMSClient = KmsAsyncClient.builder()
Expand Down Expand Up @@ -203,9 +194,6 @@ public void checkAllCombinations(@FromDataPoints("EventLoop") int eventLoopSize,
awsCrtHttpClient.close();
Assert.assertFalse(failed.get());

hostResolver.close();
eventLoopGroup.close();

CrtResource.waitForNoResources();

float numSeconds = (float) ((System.currentTimeMillis() - start) / 1000.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public void setup() {
hostResolver = new HostResolver(eventLoopGroup);

SdkAsyncHttpClient awsCrtHttpClient = AwsCrtAsyncHttpClient.builder()
.eventLoopGroup(eventLoopGroup)
.hostResolver(hostResolver)
.build();

awsCrtHttpClients.add(awsCrtHttpClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,7 @@ public class AwsCrtClientS3IntegrationTest {
public void setup() {
CrtResource.waitForNoResources();

int numThreads = 4;
eventLoopGroup = new EventLoopGroup(numThreads);
hostResolver = new HostResolver(eventLoopGroup);

crtClient = AwsCrtAsyncHttpClient.builder()
.eventLoopGroup(eventLoopGroup)
.hostResolver(hostResolver)
.build();
crtClient = AwsCrtAsyncHttpClient.create();

s3 = S3AsyncClient.builder()
.region(REGION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import software.amazon.awssdk.crt.http.HttpMonitoringOptions;
import software.amazon.awssdk.crt.http.HttpProxyOptions;
import software.amazon.awssdk.crt.io.ClientBootstrap;
import software.amazon.awssdk.crt.io.EventLoopGroup;
import software.amazon.awssdk.crt.io.HostResolver;
import software.amazon.awssdk.crt.io.SocketOptions;
import software.amazon.awssdk.crt.io.TlsCipherPreference;
import software.amazon.awssdk.crt.io.TlsContext;
Expand Down Expand Up @@ -78,10 +76,8 @@ private AwsCrtAsyncHttpClient(DefaultBuilder builder, AttributeMap config) {
Validate.isPositive(maxConns, "maxConns");
Validate.notNull(builder.cipherPreference, "cipherPreference");
Validate.isPositive(builder.readBufferSize, "readBufferSize");
Validate.notNull(builder.eventLoopGroup, "eventLoopGroup");
Validate.notNull(builder.hostResolver, "hostResolver");

try (ClientBootstrap clientBootstrap = new ClientBootstrap(builder.eventLoopGroup, builder.hostResolver);
try (ClientBootstrap clientBootstrap = new ClientBootstrap(null, null);
SocketOptions clientSocketOptions = new SocketOptions();
TlsContextOptions clientTlsContextOptions = TlsContextOptions.createDefaultClient() // NOSONAR
.withCipherPreference(builder.cipherPreference)
Expand Down Expand Up @@ -288,20 +284,6 @@ public interface Builder extends SdkAsyncHttpClient.Builder<AwsCrtAsyncHttpClien
*/
Builder readBufferSize(int readBufferSize);

/**
* The AWS CRT EventLoopGroup to use for this Client.
* @param eventLoopGroup The AWS CRT EventLoopGroup to use for this client.
* @return The builder of the method chaining.
*/
Builder eventLoopGroup(EventLoopGroup eventLoopGroup);

/**
* The AWS CRT HostResolver to use for this Client.
* @param hostResolver The AWS CRT HostResolver to use for this client.
* @return The builder of the method chaining.
*/
Builder hostResolver(HostResolver hostResolver);

/**
* Sets the http proxy configuration to use for this client.
* @param proxyConfiguration The http proxy configuration to use
Expand Down Expand Up @@ -359,8 +341,6 @@ private static final class DefaultBuilder implements Builder {
private final AttributeMap.Builder standardOptions = AttributeMap.builder();
private TlsCipherPreference cipherPreference = TlsCipherPreference.TLS_CIPHER_SYSTEM_DEFAULT;
private int readBufferSize = DEFAULT_STREAM_WINDOW_SIZE;
private EventLoopGroup eventLoopGroup;
private HostResolver hostResolver;
private ProxyConfiguration proxyConfiguration;
private ConnectionHealthChecksConfiguration connectionHealthChecksConfiguration;

Expand Down Expand Up @@ -403,18 +383,6 @@ public Builder readBufferSize(int readBufferSize) {
return this;
}

@Override
public Builder eventLoopGroup(EventLoopGroup eventLoopGroup) {
this.eventLoopGroup = eventLoopGroup;
return this;
}

@Override
public Builder hostResolver(HostResolver hostResolver) {
this.hostResolver = hostResolver;
return this;
}

@Override
public Builder proxyConfiguration(ProxyConfiguration proxyConfiguration) {
this.proxyConfiguration = proxyConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,13 @@ public class AwsCrtHttpClientSpiVerificationTest {
.dynamicPort()
.dynamicHttpsPort());

private EventLoopGroup eventLoopGroup;
private HostResolver hostResolver;
private SdkAsyncHttpClient client;

@Before
public void setup() throws Exception {
CrtResource.waitForNoResources();

int numThreads = Runtime.getRuntime().availableProcessors();
eventLoopGroup = new EventLoopGroup(numThreads);
hostResolver = new HostResolver(eventLoopGroup);

client = AwsCrtAsyncHttpClient.builder()
.eventLoopGroup(eventLoopGroup)
.hostResolver(hostResolver)
.connectionHealthChecksConfiguration(b -> b.minThroughputInBytesPerSecond(4068L)
.allowableThroughputFailureInterval(Duration.ofSeconds(3)))
.build();
Expand All @@ -88,8 +80,8 @@ public void setup() throws Exception {
@After
public void tearDown() {
client.close();
hostResolver.close();
eventLoopGroup.close();
EventLoopGroup.closeStaticDefault();
HostResolver.closeStaticDefault();
CrtResource.waitForNoResources();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.http.crt;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.any;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static software.amazon.awssdk.http.HttpTestUtils.createProvider;
import static software.amazon.awssdk.http.crt.CrtHttpClientTestUtils.createRequest;

import com.github.tomakehurst.wiremock.junit.WireMockRule;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import software.amazon.awssdk.crt.CrtResource;
import software.amazon.awssdk.crt.io.EventLoopGroup;
import software.amazon.awssdk.crt.io.HostResolver;
import software.amazon.awssdk.http.RecordingNetworkTrafficListener;
import software.amazon.awssdk.http.RecordingResponseHandler;
import software.amazon.awssdk.http.SdkHttpRequest;
import software.amazon.awssdk.http.async.AsyncExecuteRequest;
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
import software.amazon.awssdk.utils.Logger;

public class AwsCrtHttpClientWireMockTest {
private static final Logger log = Logger.loggerFor(AwsCrtHttpClientWireMockTest.class);
private final RecordingNetworkTrafficListener wiremockTrafficListener = new RecordingNetworkTrafficListener();

@Rule
public WireMockRule mockServer = new WireMockRule(wireMockConfig()
.dynamicPort()
.dynamicHttpsPort()
.networkTrafficListener(wiremockTrafficListener));

@BeforeClass
public static void setup() {
System.setProperty("aws.crt.debugnative", "true");
}

@Before
public void methodSetup() {
wiremockTrafficListener.reset();
}

@After
public void tearDown() {
// Verify there is no resource leak.
EventLoopGroup.closeStaticDefault();
HostResolver.closeStaticDefault();
CrtResource.waitForNoResources();
}

@Test
public void closeClient_reuse_throwException() throws Exception {
SdkAsyncHttpClient client = AwsCrtAsyncHttpClient.create();

client.close();
assertThatThrownBy(() -> makeSimpleRequest(client)).hasMessageContaining("is closed");
}

@Test
public void sharedEventLoopGroup_closeOneClient_shouldNotAffectOtherClients() throws Exception {
try (SdkAsyncHttpClient client = AwsCrtAsyncHttpClient.create()) {
makeSimpleRequest(client);
}

try (SdkAsyncHttpClient anotherClient = AwsCrtAsyncHttpClient.create()) {
makeSimpleRequest(anotherClient);
}
}

/**
* Make a simple async request and wait for it to finish.
*
* @param client Client to make request with.
*/
private void makeSimpleRequest(SdkAsyncHttpClient client) throws Exception {
String body = randomAlphabetic(10);
URI uri = URI.create("http://localhost:" + mockServer.port());
stubFor(any(urlPathEqualTo("/")).willReturn(aResponse().withBody(body)));
SdkHttpRequest request = createRequest(uri);
RecordingResponseHandler recorder = new RecordingResponseHandler();
client.execute(AsyncExecuteRequest.builder().request(request).requestContentPublisher(createProvider("")).responseHandler(recorder).build());
recorder.completeFuture().get(5, TimeUnit.SECONDS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,8 @@ public class H1ServerBehaviorTest extends SdkAsyncHttpClientH1TestSuite {

@Override
protected SdkAsyncHttpClient setupClient() {
int numThreads = Runtime.getRuntime().availableProcessors();
try (EventLoopGroup eventLoopGroup = new EventLoopGroup(numThreads);
HostResolver hostResolver = new HostResolver(eventLoopGroup)) {

return AwsCrtAsyncHttpClient.builder()
.eventLoopGroup(eventLoopGroup)
.hostResolver(hostResolver)
.buildWithDefaults(AttributeMap.builder().put(TRUST_ALL_CERTIFICATES, true).build());
}
return AwsCrtAsyncHttpClient.builder()
.buildWithDefaults(AttributeMap.builder().put(TRUST_ALL_CERTIFICATES, true).build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
public class ProxyWireMockTest {
private SdkAsyncHttpClient client;

private EventLoopGroup eventLoopGroup;
private HostResolver hostResolver;

private ProxyConfiguration proxyCfg;

private WireMockServer mockProxy = new WireMockServer(new WireMockConfiguration()
Expand All @@ -75,14 +72,7 @@ public void setup() {
.port(mockProxy.port())
.build();


int numThreads = Runtime.getRuntime().availableProcessors();
eventLoopGroup = new EventLoopGroup(numThreads);
hostResolver = new HostResolver(eventLoopGroup);

client = AwsCrtAsyncHttpClient.builder()
.eventLoopGroup(eventLoopGroup)
.hostResolver(hostResolver)
.proxyConfiguration(proxyCfg)
.build();
}
Expand All @@ -92,8 +82,8 @@ public void teardown() {
mockServer.stop();
mockProxy.stop();
client.close();
eventLoopGroup.close();
hostResolver.close();
EventLoopGroup.closeStaticDefault();
HostResolver.closeStaticDefault();
CrtResource.waitForNoResources();
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<rxjava.version>2.1.9</rxjava.version>
<commons-codec.verion>1.10</commons-codec.verion>
<jmh.version>1.21</jmh.version>
<awscrt.version>0.6.5</awscrt.version>
<awscrt.version>0.8.2</awscrt.version>

<!-- Test dependencies -->
<junit.version>4.12</junit.version>
Expand Down
6 changes: 0 additions & 6 deletions test/sdk-benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,6 @@
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-hpack</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk.crt</groupId>
<artifactId>aws-crt</artifactId>
<version>${awscrt.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-crt-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import org.openjdk.jmh.infra.Blackhole;
import software.amazon.awssdk.benchmark.apicall.httpclient.SdkHttpClientBenchmark;
import software.amazon.awssdk.benchmark.utils.MockServer;
import software.amazon.awssdk.crt.io.EventLoopGroup;
import software.amazon.awssdk.crt.io.HostResolver;
import software.amazon.awssdk.http.SdkHttpConfigurationOption;
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
import software.amazon.awssdk.http.crt.AwsCrtAsyncHttpClient;
Expand All @@ -46,25 +44,17 @@ public abstract class BaseCrtBenchmark implements SdkHttpClientBenchmark {
private MockServer mockServer;
private SdkAsyncHttpClient sdkHttpClient;
private ProtocolRestJsonAsyncClient client;
private EventLoopGroup eventLoopGroup;
private HostResolver hostResolver;

@Setup(Level.Trial)
public void setup() throws Exception {
mockServer = new MockServer();
mockServer.start();

int numThreads = Runtime.getRuntime().availableProcessors();
eventLoopGroup = new EventLoopGroup(numThreads);
hostResolver = new HostResolver(eventLoopGroup);

AttributeMap trustAllCerts = AttributeMap.builder()
.put(SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES, Boolean.TRUE)
.build();

sdkHttpClient = AwsCrtAsyncHttpClient.builder()
.eventLoopGroup(this.eventLoopGroup)
.hostResolver(this.hostResolver)
.buildWithDefaults(trustAllCerts);

client = ProtocolRestJsonAsyncClient.builder()
Expand All @@ -81,8 +71,6 @@ public void tearDown() throws Exception {
mockServer.stop();
client.close();
sdkHttpClient.close();
hostResolver.close();
eventLoopGroup.close();
}

@Override
Expand Down
Loading