事件流驱动的并发
Event-Driven Architecture | 基于事件流驱动的并发
基于事件驱动的服务器,无需为每一个请求创建额外的对应线程,虽然可以省去创建线程与销毁线程的开销;但它在处理网络请求时,会把侦听到的请求放在事件队列中交给观察者,事件循环会不停的处理这些网络请求。最为经典的进程模型与事件驱动模型的对比当属
下图以

We could implement a mechanism which takes the events from the selector and distributes or “dispatches” them to interested methods. If you would like react to an event you can thus subscribe a method to it. Once the event occurs the dispatcher then calls the subscribed methods (often called “handlers”) one by one and one after another. Not only does Netty implement this reactor pattern for you but it further extends it with the concepts of pipelines: Instead of having a single handler attached to an event it allows you to attach a whole sequence of handlers which can pass their output as input to the next handler. How is this useful? Usually, networking applications work in layers: You have raw byte streams which represent HTTP which might me used to transport compressed and encrypted data and so on. With Netty you can now chain a HTTP decoder which passes its output to a decompression handler which passes its output to an decrypt handler and so on… In short: Event handlers in Netty are composable and composition is at the very core of most maintainable and extendable code.
而对于业务逻辑层而言,不但要跟内网的网络服务通信,还要跟外网的服务通信,在业务逻辑层也产生了大量的外网网络
Go 的goroutine Python 3 的coroutine Kotlin 的coroutine nodejs 的异步回调swoole 1 的异步回调和swoole 2 的coroutine erlang/elixir 的process 也算是coroutine VertX 的异步回调