-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redis 单线程事件循环 #1
Comments
事件库 aeEventLoop 实现细节先来看核心数据结构: /* State of an event based program */
typedef struct aeEventLoop {
int maxfd; // 当前已经注册在此的最大文件描述符
int setsize; // 可“关心”的文件描述符数量
long long timeEventNextId; // 下一个 timer 的id
time_t lastTime; // 上一轮事件循环时的系统事件,用来诊断系统时间偏差
aeFileEvent *events; // 注册的文件事件
aeTimeEvent *timeEventHead; // 注册的时间事件
aeFiredEvent *fired; // 就绪的事件
int stop; // 事件轮询是否停止
void *apidata; /* This is used for polling API specific data */
aeBeforeSleepProc *beforesleep; // 下一次事件轮训之前的钩子函数
aeBeforeSleepProc *aftersleep; // 事件轮询结束后的钩子函数
} aeEventLoop;
/* File event structure */
typedef struct aeFileEvent {
int mask; /* one of AE_(READABLE|WRITABLE) */
aeFileProc *rfileProc; // 读事件就绪时的回调函数
aeFileProc *wfileProc; // 写事件就绪时的回调函数
void *clientData; // fd 对应的 client 实例
} aeFileEvent;
/* Time event structure */
typedef struct aeTimeEvent {
long long id; /* time event identifier. */
long when_sec; /* seconds */
long when_ms; /* milliseconds */
aeTimeProc *timeProc;
aeEventFinalizerProc *finalizerProc;
void *clientData;
struct aeTimeEvent *next;
} aeTimeEvent;
/* A fired event */
typedef struct aeFiredEvent {
int fd;
int mask;
} aeFiredEvent;
1.
|
在关注 redis 单线程/多线程 时,有几个重要的时间节点:
从
Redis v1.0
到Redis v6.0以前
,Redis 的核心网络模型一直都是一个典型的 单Reactor模型,所有的事件都在这个线程内处理完成。本 issue 旨在解释清楚这个 单Reactor模型 的所有运作细节,为以后更好地理解新的 Multi-Reactors/Master-Workers 模型做准备。注:本文基于
Redis v5.0.0
版本分析。The text was updated successfully, but these errors were encountered: