redis的socket event loop
2024-08-23 20:40:58
很早之前就因为nosql就听说了redis,直到去年才真正去了解,只能说相见恨晚。
因为数据库相关,我以为这应该是个庞然大物,万万没想到,源码不到2M,所以,我不知道该说啥了。。。
还是来点靠谱的:
/* 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
按照redis作者的排位,从上到下,性能是递减的,也就是evport>epoll>kqueue>select。libevent库上面有个benchmark,可能比较权威,http://libevent.org/ (那破图我能说点什么吗)
这个排位估计众说纷纭,对我来说,够用就好。
下面是redis定义的事件轮询函数原型:
/* Prototypes */
aeEventLoop *aeCreateEventLoop(int setsize);
void aeDeleteEventLoop(aeEventLoop *eventLoop);
void aeStop(aeEventLoop *eventLoop);
int aeCreateFileEvent(aeEventLoop *eventLoop, int fd, int mask,
aeFileProc *proc, void *clientData);
void aeDeleteFileEvent(aeEventLoop *eventLoop, int fd, int mask);
int aeGetFileEvents(aeEventLoop *eventLoop, int fd);
long long aeCreateTimeEvent(aeEventLoop *eventLoop, long long milliseconds,
aeTimeProc *proc, void *clientData,
aeEventFinalizerProc *finalizerProc);
int aeDeleteTimeEvent(aeEventLoop *eventLoop, long long id);
int aeProcessEvents(aeEventLoop *eventLoop, int flags);
int aeWait(int fd, int mask, long long milliseconds);
void aeMain(aeEventLoop *eventLoop);
char *aeGetApiName(void);
void aeSetBeforeSleepProc(aeEventLoop *eventLoop, aeBeforeSleepProc *beforesleep);
int aeGetSetSize(aeEventLoop *eventLoop);
int aeResizeSetSize(aeEventLoop *eventLoop, int setsize);
看到这个让我想起了大概是2007年微软推出mvc三层架构里的数据库访问层,封装各类数据库api,来实现一个抽象统一的数据访问中间层,
那么,在这里对不同socket IO复用实现也进行了统一的封装。或者很类似设计模式里的bridge模式。
多的我也不说了,参考大神的博客:
http://www.kegel.com/c10k.html
http://pl.atyp.us/content/tech/servers.html
最新文章
- WAMP2.5 Forbidden
- 【IOI2000】邮局设置问题
- VS-Visual Studio-IIS Express 支持局域网访问
- 使用 IL 实现类型转换
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag
- 浅谈JavaScript计时器
- response.redirect和server.Transfer的差别详解
- IE6的那些css常见bug(汇总)
- robotframework的分支和循环
- UI—视图的生命周期
- Java 异常处理笔记
- BZOJ2282: [Sdoi2011]消防
- 手把手 学习Git
- 网站开发进阶(二十三)Address already in use: JVM_Bind <;null>;:8088
- FLASK简单入门
- Python爬取网络图片
- Python关于类的实操
- interface接口——公共规范标准
- adjustPan 没作用
- android开发(34) 自定义 listView的分割线( 使用xml drawable画多条线)