简体   繁体   English

异步I / O的主要用例是什么

[英]What is the primary use case for asynchronous I/O

My application is not web based, just need to use sockets to service around 1000 clients. 我的应用程序不是基于Web的,只需要使用套接字来为大约1000个客户端提供服务。 Throughput and latency are of utmost importance to me. 吞吐量和延迟对我来说至关重要。 Currently using select() from NIO but thinking of moving on to asynchronous IO in NIO.2. 目前正在使用来自NIO的select() ,但考虑在NIO.2中继续使用异步IO。

  1. When should asynchronous I/O be used? 什么时候应该使用异步I / O?
  2. What is the primary use case for asynchronous I/O? 异步I / O的主要用例是什么?

If you are using Infiniband networks I would suggest looking at the Asynchronous IO. 如果您使用的是Infiniband网络,我建议您查看异步IO。

Comparing Java 7 Async NIO with NIO. 将Java 7 Async NIO与NIO进行比较。

However if you are using regular ethernet, it is just as likely to slower as faster. 但是,如果您使用的是常规以太网,则速度可能会更慢。 The coding is more complicated than using non-blocking IO which is more complicated than using blocking IO. 编码比使用非阻塞IO更复杂,非阻塞IO比使用阻塞IO更复杂。

If latency is of utmost importance I suggest you look at using kernel by-pass network adapters like Solarflare. 如果延迟是最重要的,我建议你看看使用像Solarflare这样的内核旁路网络适配器。 However if a 100 micro-second latency is acceptable to you, it is unlikely you need this. 但是,如果您可以接受100微秒的延迟,则不太可能需要此。

Asynchronous IO is very good in situations where you need to scale to handle many concurrent connections. 在需要扩展以处理许多并发连接的情况下,异步IO非常好。 Historically one way of doing this was to dedicate a thread per connection, but this approach has limitations you can read about here . 从历史上看,这样做的一种方法是为每个连接专用一个线程,但这种方法有一些限制, 你可以在这里阅读 With Asynchronous IO you can easier handle many things with less threads and thus scale better. 使用异步IO,您可以使用更少的线程更轻松地处理许多事情,从而更好地扩展。

Depending on the problem it might or might not be the right approach as nothing can beat a single thread when it comes to latency. 根据问题,它可能是也可能不是正确的方法,因为在延迟方面没有任何东西可以击败单个线程。 However, this is a very extreme end and means you care about microseconds. 然而,这是一个非常极端的结束,意味着你关心微秒。 In many cases is a trade-off between latency and throughput/scalability. 在许多情况下,在延迟和吞吐量/可伸缩性之间进行权衡。

In any case it comes down to what you want to solve and what your expectations (numbers) need to be. 无论如何,它归结为您想要解决的问题以及您的期望(数字)需要达到的目标。 Asynchronous IO is great and many cases and so is synchronous. 异步IO很棒,很多情况都是同步的。 There might also be other things you might want to consider such as protocol. 您可能还需要考虑其他一些事项,例如协议。 Multiple clients interested in the same data (streaming) could indicate you want to look at multicast. 对同一数据(流)感兴趣的多个客户端可能表示您想要查看多播。 If traffic is dedicated per client, then that might not be the approach. 如果每个客户端专用流量,则可能不是这种方法。

Not knowing your latency requirements, but assuming they are not in a few microseconds I would definitely look into asychronous IO just reading you have 1000 clients. 不知道你的延迟要求,但假设它们不是几微秒我肯定会看到只是读取你有1000个客户端的同步IO。 Asynchronous IO is by no means slow and synchronous/single thread connections might not scale well for you. 异步IO决不会慢,同步/单线程连接可能无法很好地扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM