zoukankan      html  css  js  c++  java
  • Reactor模式

    定义:

    The reactor design pattern is an event handling pattern for handling service requests delivered concurrently to a service handler by one or more inputs. 
    The service handler then demultiplexes the incoming requests and dispatches them synchronously to the associated request handlers.[1]
    Reactor设计模式是一个事件驱动模式,为了同时处理多个来自输入的请求,进而将请求异步分发给关联的处理器

    主要包括:

    1. Resources
    2. Synchronous Event Demultiplexer、
    3. Dispatcher
    4. Request Handler

    比较线程驱动和事件驱动

    Event-driven approach can separate threads from connections, which only use threads for events on specific callbacks or handlers.
    Reactor模式是事件驱动

    参考:https://dzone.com/articles/understanding-reactor-pattern-thread-based-and-eve

    比较Reactor和Proactor

    Proactor相当于异步的Reactor
    Reactor虽然能够异步地分发请求到时间处理器,但在处理请求是会堵塞其它请求(队列中等待)
    Proactor是可以异步处理IO的

    比较同步IO与异步IO

    实际上同步与异步是针对应用程序与内核的交互而言的。
    同步过程中进程触发IO操作并等待或者轮询的去查看IO操作是否完成。
    异步过程中进程触发IO操作以后,直接返回,做自己的事情,IO交给内核来处理,完成后内核通知进程IO完成。同步与异步如下图所示:

    比较堵塞与非堵塞

    简单理解为需要做一件事能不能立即得到返回应答,如果不能立即获得返回,需要等待,那就阻塞了,否则就可以理解为非阻塞。

    参考:

    https://en.wikipedia.org/wiki/Reactor_pattern

    http://www.artima.com/articles/io_design_patterns2.html

    http://www.cnblogs.com/daoluanxiaozi/p/3274925.html

    http://www.cnblogs.com/Anker/p/3254269.html

    ---栖息之鹰(一个外表懒洋洋的内心有激情的程序员) 此博客为笔者原著,转载时请注明出处,谢谢!
  • 相关阅读:
    EF工作流程
    EF简单的CodeFirst示例(自己创建数据库,不使用数据迁移)
    VS2017连接MySQL数据库
    Entity Framework简介
    ADO.NET
    linq连接
    linq语法
    linq和转换运算符
    学习MVC之前必须掌握的c#知识
    java 中 System
  • 原文地址:https://www.cnblogs.com/roostinghawk/p/8031615.html
Copyright © 2011-2022 走看看