Is there an async I/O based Aws java client?
1) Is there an implementation of the aws sdk which uses asynchronous I/O instead of thread pools?
Not that I know of, and I'd be surprised this to be difficult to find, if it would exist already.
2) The current client uses Apache Http Client, if I cannot find an asynch implementation I will fork my own version to implement it. [...] Is there a better alternative?
There is a better alternative indeed - the AWS SDK for Java currently uses the Http Client version 4.x (you linked to the legacy 3.1 version JavaDocs instead) from Apache HttpComponents, which conveniently provides a Async HttpClient as well:
Async HttpClient is a HTTP/1.1 compliant HTTP agent implementation based on HttpCore NIO and HttpClient components. It is a complementary module to Apache HttpClient intended for special cases where ability to handle a great number of concurrent connections is more important than performance in terms of a raw data throughput. [emphasis mine]
As emphasized, it should only be facilitated for respective uses cases, but (as per your comment) you are sending thousands of requests to AWs which means that open requests tend to pile up, so this might help indeed.
Asynchronous IO is not a silver bullet - thread-per-connection is usually faster (throughput-wise) and a lot easier to code:
http://www.mailinator.com/tymaPaulMultithreaded.pdf
It sounds to me like your limiting factor is the IO to Amazon, not the CPU processing of all those connections. The fact that you are seeing a lot of CPU time spent polling the sockets may just be a profiling artifact due to the fact that those calls block. (Something to check: are you actually maxing out CPU usage?)
The new AWS SDK for Java 2.0 preview was announced at June 2017 and provides this functionality.
The SDK now supports truly non-blocking I/O. The 1.11.x version of the SDK already has async variants of service clients. However, they are just a wrapper around a thread pool and the blocking sync client, so they don’t provide the benefits of non-blocking I/O (high concurrency with very few threads). Due to the limitations and poor resource use of the thread-per-connection model, many customers requested support for non-blocking I/O, so we are pleased to announce first class support for non-blocking I/O in our async clients. Under the hood, we use an HTTP client built on top of Netty to make the non-blocking HTTP call.
For more information, see
- Announcement by Jeff Bar
- Original blog post
- Documentation
- Github repo
However, be aware:
- Currently in preview (not recommended for production use yet)
- Needs Java 8+
UPDATE (Jan. 2019)
Current version is 2.3.0 (for a long time out of preview).
Recommended is to use this BOM in maven based projects:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.3.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>