是否有基于异步 I/O 的 AWS java 客户端?

发布于 2025-01-04 20:03:24 字数 451 浏览 2 评论 0原文

1) 是否有使用异步 I/O 而不是线程池的 aws sdk 实现?我正在开发一个高度可扩展的 Web 服务,分析显示 CPU 浪费了大量的周期来管理进出亚马逊的网络 I/O。

2)当前客户端使用 Apache Http Client,如果我找不到异步实现 我将分叉我自己的版本来实现它。我正在考虑使用 Jetty Http 客户端。混合使用 Jetty 和 Apache 库是一种不好的形式吗?有更好的选择吗?

1) Is there an implementation of the aws sdk which uses asynchronous I/O instead of thread pools? I am working on a highly scalable web service and profiling shows that the CPU is wasting a lot of cycles managing network I/O to and from amazon.

2)The current client uses Apache Http Client, if I cannot find an asynch implementation I will fork my own version to implement it. I was thinking of using the Jetty Http Client. Is it bad form to mix Jetty and Apache libraries? Is there a better alternative?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

So尛奶瓶 2025-01-11 20:03:24

1) 是否有使用异步的 aws sdk 实现
I/O 而不是线程池?

据我所知,没有,而且如果它已经存在的话,我会惊讶地发现它很难找到。

2) 当前客户端使用 Apache Http Client,如果我找不到
异步实现我将分叉我自己的版本来实现它。 [...] 有更好的吗
替代方案?

确实有更好的替代方案 - AWS SDK for Java 目前使用 Http Client 版本 4.x(您改为链接到旧版 3.1 版本 JavaDocs)来自 Apache HttpComponents,它方便地提供了 异步 HttpClient 以及:

Async HttpClient 是一个兼容 HTTP/1.1 的 HTTP 代理实现
基于HttpCore NIO和HttpClient组件。它是一种互补
Apache HttpClient 的模块用于特殊情况
处理大量并发连接更重要
比原始数据吞吐量方面的性能更高。 [强调我的]


正如所强调的,它应该只针对各自的用例提供便利,但是(根据您的评论)您正在向发送数千个请求AWS,这意味着开放请求往往会堆积起来,所以这可能确实有帮助。

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.

深空失忆 2025-01-11 20:03:24

新的AWS SDK for Java 2.0 预览版于 2017 年 6 月发布并提供此功能。

SDK 现在支持真正的非阻塞 I/O。 SDK 的 1.11.x 版本已经具有服务客户端的异步变体。然而,它们只是线程池和阻塞同步客户端的包装,因此它们不提供非阻塞 I/O 的好处(很少线程的高并发性)。由于每个连接线程模型的限制和资源使用率较低,许多客户请求支持非阻塞 I/O,因此我们很高兴地宣布我们的异步客户端对非阻塞 I/O 提供一流的支持。在底层,我们使用构建在 Netty 之上的 HTTP 客户端来进行非阻塞 HTTP 调用。

有关更多信息,请参阅

但是,请注意:

  • 目前处于预览阶段(尚不建议用于生产使用)
  • 需要 Java 8+

更新(2019 年 1 月)

当前版本是 2.3.0(很长一段时间没有预览)。

建议在基于 Maven 的项目中使用此 BOM:

<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>

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

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>
2025-01-11 20:03:24

异步 IO 不是灵丹妙药 - 每个连接线程通常更快(吞吐量方面)并且更容易编码:

http://www.mailinator.com/tymaPaulMultithreaded.pdf

在我看来,您的限制因素是 Amazon 的 IO,而不是所有这些连接的 CPU 处理。事实上,您看到大量 CPU 时间花在轮询套接字上,这可能只是一个分析工件,因为这些调用会被阻塞。 (需要检查一下:您是否真的达到了 CPU 使用率上限?)

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?)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文