Announcing availability of the Amazon Web Services CRT HTTP Client in the Amazon Web Services SDK for Java 2.x

by Zoe Wang | on

We are excited to announce the general availability (GA) of the Amazon Web Services Common Runtime (CRT) HTTP Client in the Amazon Web Services SDK for Java 2.x . With release version 2.20.0 of the SDK, the Amazon Web Services CRT HTTP Client can now be used in production environments.

The Amazon Web Services CRT HTTP Client is an asynchronous, non-blocking HTTP client that can be used by Amazon Web Services service clients to invoke Amazon Web Services APIs. You can use it as an alternative to the default Netty implementation of the SdkAsyncHttpClient interface. It offers faster SDK startup time and smaller memory footprint, which is especially important with Amazon Web Services Lambda, as well as lower P90 latency and enhanced connection management.

Faster startup time and smaller memory footprint

The Amazon Web Services CRT HTTP Client is built on top of the Java bindings of the Amazon Web Services CRT , which is written in C. It has faster startup time than other HTTP clients supported in the SDK.

We have observed an improvement of up-to 76% in startup latency and a reduction of up-to 14% in memory usage in Lambda when switching from the Netty async HTTP client to the Amazon Web Services CRT HTTP client. Note that the result may vary based on the application configuration such as Lambda function memory setting. The following charts show the Lambda cold start duration and max memory usage between the Netty async HTTP client ( NettyNioAsyncHttpClient ) and the Amazon Web Services CRT HTTP client ( AwsCrtAsyncHttpClient ) from our tests. In our test code, we used a DynamoBD async SDK client to send a ListTables request.

AWS Lambda Cold Start Duration Comparison

AWS Lambda Max Memory Usage Comparison

Lower P90 request latency

In addition to cold-start improvement, we observed an improvement of up-to 9% in P90 latency when comparing the Amazon Web Services CRT HTTP client with Netty async HTTP client.

The following chart compares the P90 latency between Amazon Web Services CRT HTTP client and the Netty async HTTP client. The test application used an S3AsyncClient to send a getObject request to download a small S3 object.

P90 Latency Comparison

Enhanced connection management

The Amazon Web Services CRT HTTP client has a connection health option that ensures “unhealthy” connections are not being reused. Based on your use-case, you can simply set a throughput threshold that determines whether a connection is healthy. If the connection falls below the set threshold for a configured amount of time, the Amazon Web Services CRT HTTP client will treat the connection as unhealthy and close it, after the in-progress request finishes. If your application is hitting a network path that results in a dramatically slower throughput, this option will help the application recover by closing the slow connection and establishing a fresh connection for new requests.

In addition, the Amazon Web Services CRT HTTP client offers enhanced DNS load balancing support. It has an asynchronous DNS resolver that polls each requested DNS address at a regular interval and balances the traffic across multiple endpoints, which allows for automatic fail-over in the unlikely event of a slow endpoint or server outage.

Getting Started

To use the Amazon Web Services CRT HTTP client, first add the aws-crt-client dependency to your pom.xml. Search the Maven central repository for the most recent versions of the aws-crt-client artifact.

<dependency>
    <groupId>software.amazon.awssdk</groupId>
    <artifactId>aws-crt-client</artifactId>
    <version>${aws.sdk.version}</version>
</dependency>

Then, configure your application to use the Amazon Web Services CRT HTTP client in one of the following ways.

Option 1 (preferred): Specify the CRT HTTP client through the client builder

This is the preferred option. It allows you to customize options such as max concurrency based on your use-case.

// Creating an asynchronous S3 client with a CRT HTTP client that is managed by the SDK
S3AsyncClient.builder()
             .httpClientBuilder(AwsCrtAsyncHttpClient.builder()
                                                     .maxConcurrency(100))
             .build();

The SDK by default includes netty-nio-client dependency. If you opt-in to the Amazon Web Services CRT HTTP Client in your application, it’s recommended to remove netty-nio-client from your application to reduce the package size. Following is the sample POM file for an application that only has the CRT HTTP client in the classpath.

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>software.amazon.awssdk</groupId>
                <artifactId>bom</artifactId>
                <version>${aws.java.sdk.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
    <dependencies>
         <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>s3</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>software.amazon.awssdk</groupId>
                    <artifactId>netty-nio-client</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>aws-crt-client</artifactId>
        </dependency>
    </dependencies>

Option 2: Configure the HTTP client using a system property at JVM startup

The following option will create an Amazon Web Services CRT HTTP client with the default configuration.

# Specify the default asynchronous HTTP client as AwsCrtAsyncHttpClient 
java -Dsoftware.amazon.awssdk.http.async.service.impl=\ 
software.amazon.awssdk.http.crt.AwsCrtSdkHttpService \ 
MyService.jar

Option 3: Configure the HTTP client using a system property in Java code.

Similar to option 2, the following option will create an Amazon Web Services CRT HTTP client with the default configuration.

System.setProperty("software.amazon.awssdk.http.async.service.impl",
                   "software.amazon.awssdk.http.crt.AwsCrtSdkHttpService");

Limitation

In this release, HTTP/2 protocol is not yet supported in the Amazon Web Services CRT HTTP Client. However, we are planning to implement it in the future. In the meantime, if you are using the service SDK clients that require HTTP/2 support such as KinesisAsyncClient and TranscribeStreamingAsyncClient , consider using NettyAsyncHttpClient instead.

Conclusion

In this blog post, we showed you how to get started with Amazon Web Services CRT HTTP Client. To learn more about how to configure the client, visit our Developer Guide and API Reference . We would love your feedback on this HTTP client and as well as any other features you would like to see implemented in the future. Please let us know by opening a GitHub issue .

Zoe Wang

Zoe Wang

Zoe is a Senior Software Development Engineer working on the Amazon Web Services SDK for Java. She is passionate about building tools to improve the developer experience. You can find her on GitHub @zoewangg .


The mentioned AWS GenAI Services service names relating to generative AI are only available or previewed in the Global Regions. Amazon Web Services China promotes AWS GenAI Services relating to generative AI solely for China-to-global business purposes and/or advanced technology introduction.