HawtDispatch 与 Java 的执行器有何不同? (和网络)
令人沮丧的是,HawtDispatch 的网站将其描述为“线程池和 NIO 事件通知框架 API”。
让我们首先来看“线程池”部分。 Java提供的大部分Executor基本上也是线程池。 HawtDispatch 有何不同?
它显然也是一个“NIO 事件通知框架 API”。我假设它是 NIO 顶部的一个薄层,它接收传入数据并传递给它的“线程池”概念,并在线程池调度程序找到时间时将其传递给使用者。正确的? (欢迎对 NIO 进行任何改进)。有人做过netty vs HD 的性能分析吗?
Frustratingly, HawtDispatch's website describes it as "thread pooling and NIO event notification framework API."
Let's take the 'thread pooling' part first. Most of the Executors provided by Java are also basically thread pools. How is HawtDispatch different?
It is also apparently an "NIO event notification framework API." I'm assuming it is a thin layer on top NIO which takes incoming data and passes to its notion of 'thread pool,' and passes it to a consumer when the thread pool scheduler finds the time. Correct? (Any improvement over NIO is welcomed). Has anyone done any performance analysis of netty vs HD?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HawtDispatch 被设计为单个系统范围的固定大小线程池。它提供了 2 种 Java Executors 的实现:
与java执行器模型不同,所有全局和串行调度队列共享一个固定大小的线程池。您可以使用数千个串行调度队列,而无需增加线程数。串行调度队列可以像 Erlang 邮箱一样使用来驱动反应式 Actor 风格的应用程序。
由于 HawtDispatch 使用固定大小的线程池来处理所有全局和串行队列执行,因此它执行的所有 Runnable 任务都必须是非阻塞的。在某种程度上,这类似于 NodeJS 架构,只不过它使用多个线程而不是一个线程。
与 Netty 相比,HawtDispatch 并不是一个实际处理套接字数据的框架。它没有提供如何编码/解码、缓冲和处理套接字数据的框架。它所做的只是当可以在非阻塞套接字上读取或写入数据时执行用户配置的 Runnable。然后由您的应用程序实际读取/写入套接字数据。
HawtDispatch is designed to be a single system wide fixed size thread pool. It provides implements 2 flavors of Java Executors:
Executors.newFixedThreadPool(n)
executor)Executors.newSingleThreadExecutor()
executor)Unlike the java executor model all global and serial dispatch queues share a single fixed size thread pool. You can use thousands of serial dispatch queues without increasing your thread count. Serial dispatch queues can be used like Erlang mailboxes to drive reactive actor style applications.
Since HawtDispatch is using a fixed size thread pool for processing all global and serial queue executions, all Runnable tasks it executes must be non-blocking. In a way this is similar to the NodeJS architecture except it using multiple threads instead of just one.
In comparison to Netty, HawtDispatch is not a framework for actually processing socket data. It does not provide a framework for how encode/decode, buffer and process the socket data. All it does is execute a user configured Runnable when data can be read or written on the non-blocking socket. It's up to you application then to actually read/write the socket data.