Redis 源码简洁剖析 08 - epoll
2022/2/10 19:23:56
本文主要是介绍Redis 源码简洁剖析 08 - epoll,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
- select, poll, epoll
- 源码分析
- 参考链接
- Redis 源码简洁剖析系列
select, poll, epoll
关于 select, poll, epoll,网络 IO 演变发展过程和模型介绍 这篇文章讲得很好,本文就不浪费笔墨了。
Redis 如何针对不同操作系统,选择不同的 IO 多路复用机制,具体代码在 ae.c。
/* Include the best multiplexing layer supported by this system. * The following should be ordered by performances, descending. */ #ifdef HAVE_EVPORT #include "ae_evport.c" #else #ifdef HAVE_EPOLL #include "ae_epoll.c" #else #ifdef HAVE_KQUEUE #include "ae_kqueue.c" #else #include "ae_select.c" #endif #endif #endif
从代码中可看到,有 epoll 就会使用 epoll(Linux);没有的话则会使用 kqueue(MacOS)或 select(Windows)。
源码分析
由于我的开发环境是 Mac,所以分析 ae_kqueue.c 文件。在 Linux 系统下可以分析 ae_epoll.c 文件。kqueue 的详细介绍:Kernel Queues and Events。
typedef struct aeApiState { int kqfd; struct kevent *events; /* Events mask for merge read and write event. * To reduce memory consumption, we use 2 bits to store the mask * of an event, so that 1 byte will store the mask of 4 events. */ char *eventsMask; } aeApiState;
kevent 定义在 event.h 源文件中。
struct kevent { uintptr_t ident; /* identifier for this event */ int16_t filter; /* filter for event */ uint16_t flags; /* general flags */ uint32_t fflags; /* filter-specific flags */ intptr_t data; /* filter-specific data */ void *udata; /* opaque user data identifier */ };
具体源码 // todo。
参考链接
- 极客时间:09 | Redis 事件驱动框架(上):何时使用 select、poll、epoll?
- 深入剖析 Netty 源码设计(一)——深入理解 select poll epoll 机制
- 网络 IO 演变发展过程和模型介绍
- Kernel Queues and Events
- Kernel Queues: An Alternative to File System Events
Redis 源码简洁剖析系列
最简洁的 Redis 源码剖析系列文章
Java 编程思想-最全思维导图-GitHub 下载链接,需要的小伙伴可以自取~
原创不易,希望大家转载时请先联系我,并标注原文链接。
这篇关于Redis 源码简洁剖析 08 - epoll的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-26阿里云Redis项目实战:新手入门教程
- 2024-09-26阿里云Redis资料入门教程
- 2024-09-25阿里云Redis入门教程:快速掌握Redis的基本操作
- 2024-09-25阿里云Redis学习:新手入门教程
- 2024-09-21Redis资料入门教程:轻松掌握Redis基础知识
- 2024-09-21Redis资料:入门级用户必学教程
- 2024-09-21Redis资料:新手入门教程与实践指南
- 2024-09-20Redis教程:从入门到实践的全面指南
- 2024-09-20Redis教程:初学者快速入门指南
- 2024-09-20Redis教程:新手入门与实践指南