异步事件模型
来源:互联网 发布:mac废纸篓清空不了 编辑:程序博客网 时间:2024/06/16 07:47
原文: http://blog.chinaunix.net/uid-23242010-id-94816.html
traffic server设计了一个基于事件驱动的多线程模型,通过EventSystem+Continuation完成了所有函数的异步调度。下图摘自apache提供的traffic server开发文档,给出了事件模型的结构图。
![](http://blog.chinaunix.net/attachment/201101/19/23242010_1295431224PByQ.png)
EventSystem=EventProcessor+Event+Ethread。EventProcessor负责创建一个(组)线程Ethread,并分配给该(组)线程一个事件类型EventType。
Continuation是一个被动的由事件驱动的状态机。一个Continuation执行的是一个逻辑上相对完整的功能。
EventProcessor通过指定具体的EventType调度某个Continuation,根据EventType与Continuation构造一个Event,通过Event触发一个正确的Ethread进行异步调度执行该Continuation。
TS启动时候已经创建了一些处理多种事件类型的Ethread,如专用于网络处理的线程,对应事件类型为ET_NET。默认事件类型为ET_CALL。目前,最新的ts2.1.5版本在启动时新增了一组事件类型为ET_TASK的线程,这组线程专门用于插件开发以及后台任务执行等作用。
TS启动时候已经创建了一些处理多种事件类型的Ethread,如专用于网络处理的线程,对应事件类型为ET_NET。默认事件类型为ET_CALL。目前,最新的ts2.1.5版本在启动时新增了一组事件类型为ET_TASK的线程,这组线程专门用于插件开发以及后台任务执行等作用。
有三种方式调度一个Continuation:在将来的某个时间调度,在距当前某个时间以后调度,以及每隔一个时间段就执行一次Continuation,在EventProcessor中对应的三个函数为schedule_at,schedule_in, schedule_every。上图中将Continuation以sleeping作为修饰,意指Continuation需要Event事件唤醒执行。
最后给出trafficserver的sdk开发文档中对异步事件模型的描述:
- Traffic Server is a multi-threaded process. There are two main reasons why a server might use multiple threads:
- To take advantage of the concurrency available with multiple CPUs and multiple I/O devices.
- To manage concurrency from having many simultaneous client connections. For example, a server could create one thread for each connection, allowing the operating system (OS) to control switching between threads.
- Traffic Server uses multiple threads for the first reason. However, Traffic Server does not use a separate OS thread per transaction because it would not be efficient when handling thousands of simultaneous connections.
- Instead, Traffic Server provides special event-driven mechanisms for efficiently scheduling work: the event system and continuations. The event system is used to schedule work to be done on threads. A continuation is a passive, event-driven state machine that can do some work until it reaches a waiting point; it then sleeps until it receives notification that conditions are right for doing more work. For example, HTTP state machines (which handle HTTP transactions) are implemented as continuations.
- Continuation objects are used throughout Traffic Server. Some might live for the duration of the Traffic Server process, while others are created (perhaps by other continuations) for specific needs and then destroyed. Traffic Server Internals (below) shows how the major components of Traffic Server interact. Traffic Server has several processors, such as cache processor and net processor, that consolidate cache or network I/O tasks. Processors talk to the event system and schedule work on threads. An executing thread calls back a continuation by sending it an event. When a continuation receives an event, it wakes up, does some work, and either destroys itself or goes back to sleep & waits for the next event.
更加详细的描述请查看千石的blog。
0 0
- 异步事件模型
- 异步事件模型
- 异步事件模型
- 事件模型或异步模型
- 异步编程和事件模型
- Winsock异步事件通知模型WSAAsyncSelect
- 并发事件: 实现 CLR 异步编程模型
- 实现 CLR 异步编程模型 并发事件
- 异步事件分发模型设计一
- Netty框架之异步事件驱动模型
- Netty框架之异步事件驱动模型
- Netty框架之异步事件驱动模型
- Winsock异步模型之(事件通知模型 WSAAsyncSelect)
- socket模型-异步事件选择模型的正常退出
- Winsock的事件I/O异步模型——WSAEventSelect
- Netty 基于事件驱动模型实现的异步IO
- WinSock 异步I/O模型[3]---事件选择 - WSAEventSelect
- 异步模型
- Java进程间通信
- 轮询 设备驱动
- shell脚本调试
- VS2013环境下GSL数学库的使用说明(亲测)
- 饭卡(DP)
- 异步事件模型
- C++类模板中使用异常知识点
- ThreadPoolExecutor线程池参数设置技巧
- 一天搞定CSS:文本text--05
- C++创建单链表
- 蒟蒻养成记——构造数列(2)
- NOJ_1004
- Leetcode学习(17)—— Single Number
- turtle图形函数画图