[英]Implementing event-driven lightweight threads
Inspired by libraries like Akka and Quasar I started wondering how these actually work "under the hood". 受Akka和Quasar之类的图书馆的启发,我开始想知道它们实际上是如何“在后台”工作的。 I'm aware that it is most likely very complex and that they all work quite different from each other.
我知道这很可能非常复杂,并且它们彼此之间的工作方式完全不同。
I would still like to learn how I would go to implement a (at most) very basic version of my own "event-driven lightweight threads" using Java 8. 我仍然想学习如何使用Java 8实现(最多)我自己的“事件驱动的轻量级线程”的非常基本的版本。
I'm quite familiar with Akka as a library, and I have an intermediate understanding about concurrency on the JVM. 我对Akka作为一个库非常熟悉,并且对JVM的并发有一个中间的了解。
Could anyone point me to some literature covering this, or try to describe the concepts involved? 谁能指出我的一些有关这方面的文献,还是试图描述其中涉及的概念?
In Akka it works like this: 在Akka中,它的工作方式如下:
ActorRef.tell(msg)
, the msg
is put into the mailbox of the referenced actor (though, this wouldn't be enough to run anything) ActorRef.tell(msg)
, msg
将放入引用的actor的邮箱中(尽管这不足以运行任何东西) akka.actor.throughput
are handled by this one task in one go. akka.actor.throughput
中指定的数量)。 If the mailbox still has messages afterwards, another task is scheduled on the dispatcher to handle the remaining messages. So, there are basically two work queues: 因此,基本上有两个工作队列:
The hardest part of writing this efficiently is the thread pool. 有效编写此代码最困难的部分是线程池。 In the thread pool a bunch of worker threads need to access their task queue in an efficient way.
在线程池中,一堆工作线程需要以有效的方式访问其任务队列。 By default, Akka uses JDK's ForkJoinPool under-the-hood which is a very sophisticated work-stealing thread pool implementation.
默认情况下,Akka在底层使用JDK的ForkJoinPool,这是一个非常复杂的窃取线程池的实现。
Could anyone point me to some literature covering this,
谁能指出我有关这方面的一些文献,
I am the architect for Chronicle Queue and you can read how it is used and works here on my blog https://vanilla-java.github.io/tag/Microservices/ 我是Chronicle Queue的架构师,您可以在我的博客https://vanilla-java.github.io/tag/Microservices/上阅读其用法和工作方式。
try to describe the concepts involved?
试图描述涉及的概念?
You have; 你有;
For some of the systems I work on you can achieve latencies of 30 micro-seconds in Java (network packet in to network packet out) 对于我正在使用的某些系统,您可以用Java实现30微秒的延迟(网络数据包输入到网络数据包输出)
In Akka, 在阿卡
1.Actor system allocates the threads from thread pool to actors that have messages to process. 1.Actor系统将线程池中的线程分配给需要处理消息的actor。
2.When the actor has no messages to process,thread is released and allocated to other actors that have messages to process 2.当actor没有消息要处理时,线程被释放并分配给其他有消息要处理的actor
This way asynchronous actor systems can handle many more concurrent requests with the same amount of resources since the limited number of threads(thread pool) never sit idle while waiting for I/O operations to complete. 通过这种方式,异步参与者系统可以使用相同数量的资源处理更多并发请求,因为有限数量的线程(线程池)在等待I / O操作完成时永远不会处于空闲状态。
For more information you can download & check this e-book https://info.lightbend.com/COLL-20XX-Designing-Reactive-Systems_RES-LP.html?lst=BL&_ga=1.214533079.1169348714.1482593952 有关更多信息,您可以下载并查看此电子书https://info.lightbend.com/COLL-20XX-Designing-Reactive-Systems_RES-LP.html?lst=BL&_ga=1.214533079.1169348714.1482593952
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.