ePump是一个基于I/O事件通知、非阻塞通信、多路复用、多线程等机制开发的事件驱动模型的 C 语言应用开发框架,利用该框架可以很容易地开发出高性能、大并发连接的服务器程序。
A C-language framework based on I/O event notification, non-blocking communication and multi-threaded event-driven model helps you to develop servers with high-performance and numerous concurrent connections.
ePump??һ??????I/O?¼?֪ͨ????????ͨ?š???·???á????̵߳Ȼ??ƿ??????¼?????ģ?͵? C ????Ӧ?ÿ?????ܣ????øÿ?ܿ??Ժ????ؿ??????????ܡ??????ӵķ?????????
ePump??һ??????I/O?¼?֪ͨ????????ͨ?š???·???á????̵߳Ȼ??ƿ??????¼?????ģ?͵? C ????Ӧ?ÿ?????ܣ????øÿ?ܿ??Ժ????ؿ??????????ܡ??????ӵķ?????????
ePump???¼??ã?Event Pump????Ӣ?ļ?ƣ?????˼?壬??˼?ǶԸ????????д?¼?????ʱ???¼??Ƚ???ѭ???????ıã???Щ?ײ??¼??????ļ???????FD?Ķ???????Read Readiness????д??????Write Readiness???????ӳɹ???Connected??????ʱ????ʱ??Timeout???ȵȡ?
ePump????????ͼ?ش??ڷ?????ģʽ???ļ???????FD?Ͷ?ʱ??????????״̬?仯??????Ӧ???¼??????ɷ?????Ӧ?Ĺ????̻߳?ePump?̵߳??¼??????У???Щ?߳?ͨ?????ø??¼??????Ļص???????Callback?????????¼???
Ӧ?ó??????ePump????ṩ?Ľӿں?????Ԥ?ȴ?????????????ͨ??Socket?ļ???????FD??????????ʱ???ȣ??????????ӻ??ePump?̵߳ļ?ض????У?????ЩFD?Ͷ?ʱ????״̬????Dz??ò???ϵͳ?ṩ??I/O?¼?֪ͨ??ʩ????epoll??select??poll??kqueue??completion port?ȡ?
???????????????Ҫ???????Կͻ????Ĵ?TCP????????UDP??????Web????????Online??????????Ϣϵͳ?ȡ?????ʵ?ֵ?ͨ?ŷ???????ϵͳ?У?һ??????????ͨ??????һ???????Ľ??̻??߳??????ܲ?????ͨ??ϸ?ڣ??????ȵ?Apache Web??????????????????OS?ṩ??I/O?첽?¼?֪ͨ????·???û???ʵ?ֵ??????´??????????????????????????SQUIDϵͳ??
??Щϵͳ???õĿ?ܣ?Ҫ???ڵȴ??????I/O?豸?????ݵ???֮ǰ?????Լ???Ҫ?????õ????̶?·????ģ?ͣ????Ƕ?CPU??????Ч?ʶ??ٴ???һ???ľ??ޣ???ePump?????һ?ֳ?ָ?Ч????CPU???????????¼?????ģ?Ϳ?ܡ?
ePump?????һ?????̣߳?δ?????Ӷ???̣??¼?????ģ?Ϳ?ܣ??????ļ??????????첽????֪ͨ??Readiness Notification?????ƣ?????Ϊ?ȴ?"??·??"?????ݶ??????ȴ??????̻߳??????̡?
?ÿ??Ϊÿ???ļ???????????iodev_t????Ϊ??ʱ??????Ӧ?ó?????ʱ??iotimer_t???????ò???ϵͳ?ṩ??I/O?¼?֪ͨ??ʩ??epoll??select?ȣ???????????ļ???????FD????Ϊ??????ģʽ???????ӵ?ϵͳ?ļ?ع????б??У?????״̬?仯?????첽?ص?֪ͨ??
???????????ļ?ع??????¼?֪ͨ?ɷ?????ePump?̳߳???ʵ?֣????¼??Ļص?????????Worker?????̳߳ػ?ePump?̳߳?????ɡ?Ϊ?˳?????÷?????Ӳ???????ܣ??????????̵߳ĸ???һ???CPU Core??????һ?¡?
???????ӵĵײ㴦??ϸ?ڶ?????װ??һЩ?????õ?API?ӿں?????ͨ????ЩAPI???????????߿??Կ??ٿ?????֧?Ŵ??ĸ????ܷ?????????
ePump?????????????2003?꿪????eProbe??ܵĻ????Ϸ?չ????????Event Pump????д??????˼??????һ???¼??????ܹ???
???ڲ?ͬ??I/O?¼?֪ͨ????????ͨ?š???·???û??ƣ?????epoll??select??kqueue??completion port i/o?ȣ??????????ԭ????????
???????Ϲ???ԭ???????????ePump??ܵļ??????????ݽṹ??
???ÿ??FD???????ݽṹΪiodev_t???????????ļ???????FD????iodev_t?豸??????豸????????д״̬??FD???͡?Ҫ?????Ķ?д?¼????ص??????ͻص?????????Ԫ???ַ?ȵ?. ???ǰ?TCP????socket??TCP????socket?????????ӵġ????????յģ???UDP????socket??UDP?ͻ?socket??Unix Socket??ICMP Raw Socket??UDP Raw Socket?ȵȣ???ͨ??iodev_t?豸????????
???е?iodev_t?豸????????¼???ePumpϵͳ??iodev_t?豸???????¼????д???????ͨ???¼????????߳??????ûص???????
????iodev_t?豸???ܲ????????¼??Ļ???iotimer_t??ʱ??, ?趨һ??ʱ?䲢??????ʱ????ϵͳ???ӵ?ǰʱ????ָ??ʱ?䵽??ʱ??????Timeout?¼???
iotimer_t??ʱ????һ???Եĺ??????Եģ?iotimer_t??ʱ?????ݽṹ??????ʱ??id???ص??????ͻص?????????ʱ??ʱ??ȡ?
??Unix??OSϵͳ??һ??????ֻ??????һ??ʱ?Ӷ?ʱ??????ϵͳ?ṩ?Ľӿ??????ã????õ???alarm()??setitimer()??????ͨ??ϵͳ?д??????ڸ??ֶ?ʱ??????ͬʱ???ǿ?ƽ̨?Եȣ?ϵͳ?ṩ?Ķ?ʱ???ӿ?һ?㶼??????????????????ePumpϵͳ???????iotimer_t???ݽṹ?????ṩ???뼶???ȡ?ͬʱ???????Ķ?ʱ??????ʵ?֡?
ePump?ܹ??аѶ?ʱ??????һ????Ҫ?Ļ?????ʩ?????ļ????????豸һ????ePump?̼߳?????????
ioevent_t?¼???ePump????ʹ???????¼????͡??????¼??Ķ????¼??Ļص??????Ͳ?????
iodev_t?豸???ڸ???Ӳ???豸??R/W״̬?䶯??????ioevent_t?¼??IJ???????iotimer_t??ʱ???????趨?Ķ?ʱʱ?䣬??ָ??ʱ?䳬ʱ???ʹ?????ʱTimeout?¼???
???⣬Ӧ?ó??????ע???û????ӣ?Hook???¼???ע????û????ӣ?Hook???¼???Ҫ??Callback?ص??????ͻص???????????Ҫ???Ƕ????û??¼???????????
?????????²???????Щ?¼??????ᱻ???͵??????̵߳??¼????У??????????߳????????¼???????????????Ӧ?Ļص????????????¼???
ePump?ܹ????ɶ??߳??????ɵģ????չ??????̣???Щ?̷ֳ߳????࣬һ????ePump?̣߳???һ????worker?̡߳?ePump?߳?ְ????Ҫ?Ǹ???????ļ???????R/W??д״̬?Ͷ?ʱ?????У???????д?¼??Ͷ?ʱ???¼???????ioevent_t?¼??ɷ???????worker?̵߳??¼??????С?worker?߳?ְ???Ǽ????¼????У?ִ???¼??????и????¼??????Ļص???????
ÿ??ePump?̲߳???I/O?¼??첽֪ͨ????????ͨ?š???·???õȻ??ƺ?ģ?ͣ?????select/poll/epoll??ϵͳ???ã????????????ļ???????????I/O??д??????I/O Readiness??ʱ??ePump?ͻᴴ???????Щ?ļ?????????R/W??д?¼???????ЩR/W??д?¼???װ??ePump????б???ioevent_t?¼??????????ɷ???????worker?????̵߳?FIFO?¼??????С???ЩEvent Queue FIFO?¼????????߳??¼?????ģ?͵ĺ??ģ?ÿ??ePump?̺߳?ÿ??worker?̶߳???һ????????FIFO?¼????С????⣬ePump?̻߳?Ҫά?ֲ???????ʱ?????У?????ʱ????ʱʱ????????ʱ????ʱioevent_t?¼????ɷ?????Ӧ??worker?????̵߳??¼??????С?
worker?̵߳???Ҫְ?ܾ????????ȴ????̰߳??¼????У??????¼?????ʱ??ͨ?????ѻ??ƣ????Ѵ??ڹ???״̬??worker?̣߳??????ѵĹ????߳̽?????FIFO?¼??????У?????ء?ѭ????ȡ?߲??????¼????е?ioevent_t?¼???
ioevent_t?¼??Ĵ??????̻??ڻص?????ע????ƣ?Ӧ?ò??ڴ???????ļ???????FD??????????ʱ??ʱ??????FD??Ӧ??iodev_t?豸?Ͷ?ʱ??ʵ????ע?Ტ?ص?????????????ePump?????iodev_t?豸??iotimer_t??ʱ?????ڴ???ioevent_t?¼?ʱ?????Ὣ??ע??Ļص??????ͻص??????????õ?ioevent_t?¼??С???worker?????̴߳??¼??????л?ȡ??ioevent_t?¼???ִ???????õĻص????????ɡ?
ePump?̳߳??˼????ļ???????FD??Ӧ??iodev_t?豸??????iotimer_t??ʱ?????С?????ioevent_t?¼????ɷ?ioevent_t?¼????????¼??????⣬Ҳ????һ??FIFO?¼????У????Ե????¼??ص??????ķ?ʽ?????¼????е??¼???
Ϊ?˱?֤????Ч?ʣ?ePump?ܹ????߳?????????????ePump?̺߳?worker?????̣߳????ΪCPU??Core Processor????????????ȷ????ȫ???д?????
?ȶ??????ʲô?ǿ?ҵ?????ҵ??ҵ????ָ???յ??ͻ??˵????????ҵ??????????Լ??٣?û?г?ʱ???????͵ȴ???ҵ???????̣??෴????ҵ??????ָ?ڴ????ͻ??˵?????ʱ????Ҫ?ϳ?ʱ????????͵ȴ???????????ݿ?????ѯ?????????ҵ?????̵ȡ?
ePump??ܽṹ?dz???????ҵ????????ɷֳ??????ģ?ͣ?
ePump?̼߳ȸ???iodev_t??iotimer_t?ļ?????ioevent_t?¼??Ĵ????ͷַ???ͬʱ?????Գ䵱?????̵߳?ְ?ܣ???????FIFO?¼??????е?ioevent_t?¼??????????????ģ?͵?Ӧ??ϵͳ??Nginx Web????????
???ģ??????ȱ???ǣ?һ??ͨ?????ûص??????????¼??ڼ䣬??????ҵ???????????ʱ??ȴ????????ȣ?Ʃ???д???ݿ?ʱ????ʱ???????ȴ???ѯ????ȣ??ͻᵼ?º?????????iodev_t?豸?е??ļ?????FD??I/O??????Readiness??״̬????iotimer_t??ʱ????ʱ״̬?????ܱ???ʱ??Ч?ش?????һ???¼??Ĵ????ӳ٣??ᵼ?´???????iodev_t?豸??״̬?仯????ʱ???ij?ʱ?ȵò?????ʱ???ٵĴ??????Ӷ????????崦???ϵ??ӳ١???????????û????Ӧ???߱?????
?????????ҵ??????????Apache Web?????????ֶ?ռʽ????/?̼ܹ߳?ģ?ͱȽ??ʺϣ?????????˵?????ֶ?ռʽ????/?߳?ģ?ͣ??Զ??CPU???д?????????????Ч?ʷdz????£??????????ϵ͡?
??ģ?????ĺô??ǣ??Զ??CPU???м???ʹ?????????Ч?ʿɴﵽ???£??ʺϴ?????????Ҫ??????Ӧ?͵?ͨ?Ż?ҵ??ϵͳ??
ePump?߳?ֻ????iodev_t??iotimer_t?ļ?????ioevent_t?¼??Ĵ????ͷַ????????????¼???worker?̸߳????????в?????ioevent_t?¼?????????Щ?¼??Ļص????????Ӷ?????Ӧ?ò?ҵ?????̡?
worker?߳?ִ???ϲ?Ӧ??ע??Ļص?????ʱ??ִ?й??̵???????????̱??????iodev_t?豸??ʱ???ȵ??¼?????ȷ???????豸??ʱ???¼???ͨ??????worker?????߳̽??м?ʱ??Ч?Ĵ?????
????ģ?͵ĺô??ǿ???һ???̶Ⱥܺõؽ??????ҵ????Ӧ?õ?????ͬʱ?dz???Ч?????ö??CPU?IJ??м??㴦????????
ʹ??ePump??ܵĸ???ҵ??ģ??ʱ???߳?????????ΪCPU??Core Processor????????????ePump?߳?????ΪCPU Core??????10-20%??worker?߳?????ΪCPU Core??????80-90%??Ʃ??CPUΪ32?˵ķ???????????ePump?ܹ??????ij???ʱ??ePump?߳???????Ϊ3-6????worker?????߳???????Ϊ26-29????
??Unix??Linux????ϵͳ?У???һ????I/O??д??ص??????豸???????豸?????????ļ?????????ͨ?ļ???Ŀ¼???ַ??豸?ļ???????̡???꣩?????豸?ļ?????Ӳ?̡?????????????????Socket?ȣ?????????ļ????ļ????????Dz???ϵͳ?ں?kernel?????????ļ??ṹ???????????????һ????????ֵ???ں?Ϊÿ??????ά??һ???ļ???????????Ըñ??????????ļ???????fd??0??ʼ??0Ϊ?????룬1Ϊ???????2Ϊ????????????ڽ????д?ÿ???ļ??????????һ???ļ???????fd??????Ӧ???ý??̵??ļ???????ij?????????У?ͨ??fd????д?ͷ????ļ???
ȱʡ?أ?һ?????̴??ļ??????????????????Ƶģ?Linuxϵͳ?????????ư??????????棬?û??????ƺ??ں˼????ơ??ں˼?????????????Ӳ????Դ?Ͳ???ϵͳ??????I/O?????????ƶ???һ???????û??????ܼ??ܴ?????ļ???????????????????shell???
sysctl -a | grep file
??
cat /proc/sys/fs/file-max
?鿴?ں˼????ơ?????ϵͳ?ں?ͬʱ???ļ??????????ƣ???ÿ???û??ͽ?????Ӧ?????ƴ??ļ????????????????û????????ƣ????????ȱʡһ????1024????ȱʡ????£??????ܴ??ļ?????????????1024??
ePumpϵͳ?ڳ?ʼ??ʱ???Ѵ??ļ?????????????Ϊ??ʼ???????????ͨ??ϵͳ????setrlimit???ģ?????߰???????socket???ڵ??ļ??????????????Ӷ?????ϵͳ???I/O??????????????
ePump??ܶ??ļ????????????˷?װ??????iodev_t???ݽṹ??????ÿһ???ļ????????????ļ????????????͡??ص?????????Ԫ???ַ????д״̬???????̵߳???Ϣͳһ??װ??????ePump?̸߳????iodev_t?豸??I/O??д״̬???м?????һ???յ?I/O??д????֪ͨ??Readiness Notification???ʹ???ioevent_t?¼?????ͬ??I/O??д״̬???ͻᴴ????ͬ???¼???ͨ??????Щ?¼?ע?ͬ?Ļص?????????ʵ???¼?????ģ?͵Ĵ????ջ???
????ļ????????ĸ??ֲ?ͬ??I/O??д״̬??ePump?ܹ??ж????˶????ļ??????????ͣ?
#define FDT_LISTEN 0x01
#define FDT_CONNECTED 0x02
#define FDT_ACCEPTED 0x04
#define FDT_UDPSRV 0x08
#define FDT_UDPCLI 0x10
#define FDT_USOCK_LISTEN 0x20
#define FDT_USOCK_CONNECTED 0x40
#define FDT_USOCK_ACCEPTED 0x80
#define FDT_RAWSOCK 0x100
#define FDT_FILEDEV 0x200
#define FDT_TIMER 0x10000
#define FDT_USERCMD 0x20000
#define FDT_LINGER_CLOSE 0x40000
#define FDT_STDIN 0x100000
#define FDT_STDOUT 0x200000
?????ļ?????????????iodev_t?豸??ePump????????????????ʩ????????˵??ePump????һ???????ļ?????????ϵͳ???ļ??????????????¼?????ѪҺһ????????ת????ePump??ܡ?
????ҵ??????????ģ??һ????÷ֲ?ģ?ͣ???ͬ??ģ??֮??һ??ͨ???????ӿ???????ã????ڷֲ??????²?ģ??ͨ????Ϊ??????????ʩ??Ʃ????????㡢I/O??д?ȹ??ܣ??ṩ???????ýӿڸ??ϲ?ģ?飬?ϲ?ģ??ͨ???²?ģ??Ľӿں?????ʹ???????㡢??д?ȹ??ܡ???Ϊ?ײ?֧??ģ?飬?²?ģ????ε????ϲ?ģ??ĺ????????أ?????ǻص???CallBack?????ơ?
ePump?????Ϊ?ײ??????ʩ??????ͬ??ҵ??ϵͳ?ṩ????֧?ţ?ҵ??ϵͳ??????ʵ?ַ????ӣ?ͨ???ص???Callback?????ƣ???ʵ???ϲ?ҵ??ϵͳ?ĺ???ָ??ע?ᵽePump??ܵ??ļ????????豸??ʱ???У???ePump???????豸?Ͷ?ʱ????I/O??д״̬????ʱ????ʱ״̬?????仯ʱ??ͨ???¼?????ģ?ͣ?ִ???ϲ?ϵͳע?ᵽ????״̬?仯???豸?Ͷ?ʱ???Ļص????????Ӷ?????ePump?ײ???߳?CPU???д??????㴦??????????????ӵ?ҵ?????̵?Ŀ?ġ?
ePump?Ļص???CallBack?????Ʒ?װ??ePump???ϲ?ģ???ṩ?Ľӿں????У???ePump?Ľӿں????У?һ?????????Ҫ????ĺ???ָ?룬???????ָ??ָ??????ϲ?ҵ????????????ePump?Ļص????????ص???????ԭ?Ͷ??????£?
typedef int IOHandler (void * vmgmt, void * pobj, int event, int fdtype);
??һ?????????ϲ?ģ??ePump?ӿں????IJ??????룬?ڶ?????pobj????????????event?????ĸ?????fdtype????ePump?ص?????ʱ???ݵIJ?????????
ePump?й?????iodev_t?豸?????iotime_t??ʱ????????״̬?????仯ʱ??ePump???????Ӧ???¼?????Щ?¼????????£?
/* event types include getting connected, connection accepted, readable,
* writable, timeout. the working threads will be driven by these events */
#define IOE_CONNECTED 1
#define IOE_CONNFAIL 2
#define IOE_ACCEPT 3
#define IOE_READ 4
#define IOE_WRITE 5
#define IOE_INVALID_DEV 6
#define IOE_TIMEOUT 100
#define IOE_USER_DEFINED 10000
ePump???ϲ??ṩ?Ļ????ӿں??????£?
void * eptcp_listen (void * vpcore, char * localip, int port, void * para, int * retval,
IOHandler * cb, void * cbpara, int bindtype);
void * eptcp_mlisten (void * vpcore, char * localip, int port, void * para,
IOHandler * cb, void * cbpara);
void * eptcp_accept (void * vpcore, void * vld, void * para, int * retval,
IOHandler * cb, void * cbpara, int bindtype);
void * eptcp_connect (void * vpcore, struct in_addr ip, int port, char * localip, int localport,
void * para, int * retval, IOHandler * cb, void * cbpara);
void * epudp_listen (void * pcore, char * lip, int port, void * para, int * ret, IOHandler * cb, void * cbp);
void * epudp_client (void * pcore, char * lip, int port, void * para, int * ret, IOHandler * cb, void * cbp);
void * epusock_connect (void * pcore, char * sock, void * para, int * ret, IOHandler * cb, void * cbp);
void * epusock_listen (void * pcore, char * sock, void * para, int * ret, IOHandler * cb, void * cbp);
void * epusock_accept (void * pcore, void * vld, void * para, int * ret, IOHandler * cb, void * cbp);
void * epfile_bind_fd (void * pcore, int fd, void * para, IOHandler * cb, void * cbp);
void * epfile_bind_stdin (void * pcore, void * para, IOHandler * cb, void * cbp);
void * iotimer_start (void * pcore, int ms, int cmdid, void * para, IOHandler * cb, void * cbp);
int iotimer_stop (void * viot);
ePump????ṩ?Ĺ??ܽӿں?????????TCP??UDP??Unix Socket??ͨ????ʩ?????????ļ????????¼????????Ͷ?ʱ???¼??ļ????????ڳ???TCP??UDP??Unix Socket֮????ļ?????????????ʹ??epfile_bind_fd?ӿ????????????ļ????????豸????????????չ???????ļ???????FD?????Լ??뵽ePump?ܹ??н??й??????¼???????
???ȣ?scheduling???ǰ???һ???Ļ??ƺ??㷨???????Դ???з???Ĺ??̣?ePump??ܵ???Դ??Ҫ??iodev_t?豸??iodev_t??ʱ????ioevent_t?¼???ePump?̡߳?worker?????̣߳????Ȼ???Ҳ??Χ????Щ??Դ?ķ???????ơ?
ͨ??????Ӧ?ýӿڴ???iodev_t?豸????Ҫѡ??һ??ePump?߳???ִ?и??豸?ļ????;???֪ͨ??Readiness Notification??????????ǰiodev_t?豸??ѡ???ePump?߳̽?????ϵ???а?ePump?߳????????Ͳ???????R/W?¼?????η???ePump?߳???Ҫȡ????iodev_t???豸???ͺͰ????͡?
??Ҫ????ePump?̶߳???iodev_t?豸???????֧??SO_REUSEPORT Socketѡ??IJ???ϵͳ????ҪΪÿһ??ePump?߳???ͬһ????????ͬһ??Listen?˿??ϴ??????iodev_t Listen?豸????????ePump?߳??С?????????Ŀ????ȷ?????пͻ???????????????ʱ??????ePump?̶߳??ܾ????ƽ?ָ??ء???Ȼ??????Linux?ں˰汾????3.9.x??ϵͳ?????ھ?ȺЧӦ????δ?????μ???8.3.2?ڡ?
ָ??ePump?߳?
???ݵ??ò???ָ????ePump?߳?????????ϵ??
????ePump?̵߳??????
ePump?ĸ?????Ҫ?Ǹ??̰߳?iodev_t?豸??????iotimer_t??ʱ???????????߳??????λʱ???ڲ?????ioevent_t??????ָ??????????ѡ??????ص?ePump?̣߳??????ø??ؾ???ط?̯??????ePump?߳??У???????ϵͳ????Ч?ʡ?
Ӧ?ó???????iotimer_t??ʱ??ʱ??ePump???һ?????ePump?̵߳ĵ?ǰ???أ?ѡ??????͵?ePump?߳??????ɰ?ePump?߳????????ͼ?أ????????????ʱ?¼???
??ePump?߳?һ???ǽ?iotimer_t??ʱ?????????ӵ???ePump?̵߳Ĺ?????ʱ???б??ĺ?????ṹ?У??????ǰePump?̴߳???????????״̬??ͨ????????ƻ??ѵ?ǰePump?̣߳??????ڶ?ʱ?????ͽṹ???뵱ǰʱ?????ʱ????????????ϵͳ???á?
?????û??¼??⣬????????ioevent_t?¼?????ePump?̲߳???????ȻҲ??ePump?̸߳?????ػ??ƺ??㷨?????ȣ??????ɷ???worker?????̻߳?ePump?̵߳?FIFO?¼??????У??????¼??ص??????ĵ??ô?????ioevent_t?¼??????????ڽ϶̣????????????????ɵ??¼????С????߳?ִ????ص???????ִ????ϣ???ʵ??????ᱻ???ն???????????
ioevent_t?¼?һ?㶼????ij??iodev_t?豸??iotimer_t??ʱ??????ǰioevent_t?¼??ɷ????ȵ???һ??worker?̣߳?ֱ?Ӿ???ePump???ϵͳ???е?Ч?ʡ?
ͬһ??iodev_t?豸?????????Ļ?????ͬ??ioevent_t?¼???ᱻ???Ȼ?????????
ePump?߳???ePump??ܵĺ?????ʩ???????iodev_t?豸?б???iotimer_t??ʱ???б????й?????ͨ??epoll_wait??select??ϵͳ???ã??????ȴ??豸R/W????֪ͨ??ʱ????ʱ????????ioevent_t?¼??????????Щ?¼????е????ɷ???
???ڵ?eProbe????У?ֻ??һ??ȫ?ֵ?FIFO?¼????У????????????¼??????ӵ??¼?????β????Ȼ?????п??е?worker?????̶߳???????FIFO?????¼??????д????????????ģ?ͼ??ܾ???ط??乤??????һ??ij???¼??????????ж???ʱ??????Ӱ???????¼??Ĵ???????????FIFO???еĹ????????㲥ʽ???????й????̵߳ľ?ȺЧӦ??ͬһ???豸???????????Ķ???¼??ɷ?????ͬ?̴߳????ȵ????أ????ؽ???CPU????Ч?ʣ??????????????Ԥ֪?Ĺ??ϵ????⡣
?Ľ????ePump???????ÿ??worker?????̺߳?ePump?߳??У?????һ????????FIFO?¼????У???Щ?߳?Ҳֻ???Լ???FIFO?????л?ȡ?¼????????¼???ePump?߳̽???????ÿһ???¼????ȷַ?????Щ?̵߳?FIFO?¼??????У??????ü?????ƣ????ѵ?ǰ???ڹ???״̬???̡߳???Ȼ???????worker?????̣߳?????Ȼ??ƽ????Ȱ?ioevent_t?¼???????????̡߳?
ePump?̵߳????ɷ?ioevent_t?¼????㷨???????£?
?¼????ȵĻ????㷨?ǵ????????㷨????ѡ??ǰ??????͵?worker?????̣߳??????¼??ɷ??????̵߳??¼??????С?
????ͬһ??iodev_t?豸?????ĺ???????ioevent_t?¼?????????pipeline??ʽ???ȵ?ͬһ??worker?߳??С?
????ͬһ??iodev_t?豸??????????ͬһ???͵?ioevent_t?¼??????????ͬһ??worker?????̵߳?FIFO?¼??????У???δ??ȡ??ִ?У???ô??????????ͬ?豸ͬ?????¼??ͻᱻ??????
???ĸ?worker?߳???????iotimer_t??ʱ?????䳬ʱ?¼???????Ȼ?ɸ?worker?????̴߳?????
???ePump?????û??????worker?????̣߳???ѡ??ǰ??????͵?ePump?̣߳??????¼??ɷ??????̵߳??¼????С?
???ڴ??ģ??ʱ??Ϣͨ??ϵͳ????̨?????????ܻ?ͬʱά??30???????????ģ??TCP???????ӣ?ÿ????????ʱ???????д?¼??????????շ???????????ePump??ܵĶ??ePump?߳̿??Ծ???ֲ?ʽ?طֵ?30???iodev_t?豸????Щ?豸???????¼???Ҳ?ܿ?ؾ?????ȵ?????worker?????߳??У?û?й???????ɵij?ͻ????ͬ?豸???????¼?????pipeline??ʽ??ͬһ???̴߳?????????˶??߳??????豸??Դ?ij?ͻ???????⣬Ҳ?ر???һ???̹߳ر??ͷ???iodev_t?豸??Դ??????һ???̻߳???ʹ?ø???Դ???쳣???????⡣
ePump????У?worker?????߳??Ǵ???ioevent_t?¼?????Ҫ???壬??????????ѭ??????ȡFIFO?¼??????е??¼???ִ?и??¼??еĻص???????????????ͷŸ?ioevent_t?¼?????????ȡ??һ??ioevent_t?¼????д?????ֱ????????ȫ???¼???ͨ???첽֪ͨ???????????????????ȴ????¼??ĵ?????
worker?????̵߳?ʵʱ??????ePump?????㷨????Ҫ?????????صļ????????????¼??????ӣ?
???????????ӵİٷ???ֵ??Ȩ?ر?????ʵʱ????ó???ֵ??Ϊworker?????̵߳ĸ??ء?
ePump?̵߳??¼??????ɷ???????Ҫ?????ڹ????̵߳ĸ??أ????????????㷨???????????㷨?????ս???Ƕ???????߳??ս?ƽ??سе?ϵͳ?е????д???????
??ȺЧӦ??ָ????̣????̣߳???ͬʱ?????ȴ?ͬһ???¼???ʱ??????״̬????????ȴ???????¼?????????ô???ͻỽ?ѵȴ??????н??̣??????̣߳???????????ȴֻ????һ?????̣??̣߳???????ʱ??ġ?????Ȩ?????Ը??¼????д??????????????̣??̣߳???ȡ??????Ȩ??ʧ?ܣ?ֻ?????½???????״̬????????????????˷Ѿͽ?????ȺЧӦ??
????ϵͳ?ں˶??û????̣??̣߳?Ƶ????????Ч?ĵ??ȡ????????л???????ʹϵͳ???ܴ???ۿۡ????????л???context switch?????ᵼ?? CPU Ƶ?????ڼĴ????????ж???֮?䱼?????????ʱ?仨???˽??̣??̣߳??л????????????????????Ľ??̣??̣߳????档ֱ?ӵ????İ??? CPU ?Ĵ???Ҫ????ͼ??أ?????????????????ϵͳ???????Ĵ?????Ҫִ?С???ӵ????????ڶ?? cache ֮??Ĺ??????ݡ?
????libevent???û????ƽ??̻??̣߳?ֻ?????˽ӿڵ??ã??????̺??̵߳?ʹ?ý?????Ӧ?ó???????????ePump??ܲ????˶??̣߳?δ???汾??֧?ֶ???̣????????ʹ????????¼???ʹ?ö???̻???̵߳?ϵͳ????????????ͬ??Դ?????ٶ?????ڽ??̻??̵߳ľ?Ⱥ???⡣
ePump????У?Ϊÿ??worker?????̵߳???????˽??պʹ????¼???FIFO???У?????worker?????߳???û???¼?????ʱ?????????Ⱥ?FIFO???е??????????ں˶????ϣ?ֱ???????¼????ӵ?FIFO???к??????????ں˶????ѡ?
worker?߳???û?й???һ????FIFO?¼????У??????????ӵ??¼??????ỽ?????д??????ߵ?worker?????̣߳?????ֱ????ePump?߳????ʵ?Աһ???????ż??ʹ??ͥ?????У?Ҳ?????????ӵ??¼?????ePump?̵߳????ɷ???ij??worker?????̵߳?FIFO?¼??????У???ֱ?ӻ??Ѹ??̣߳?worker?????߳????е??????߳̾Ͳ?????ܵ?????ָ?
???ַ?ʽ???????worker?߳???ľ?ȺЧӦ????????ϵͳ????Ч?ʺ?CPU???????ʡ?
ePump????е?ePump?̶߳???????????I/O?¼?֪ͨ??ϵͳ?????ϣ???select??poll??epoll_wait?ȣ??Ⱥ??ļ?????????R/W????״̬????ȴ???ʱʱ?䳬ʱ??????????????״̬??ePump?̣߳??????ѵ?????ֻ?????ࣺ
?????һ??iodev_t?豸???ļ????????????е?ePump?̶߳???????monitor???ˣ???????豸??R/W Readiness??д????ʱ?????е?ePump?߳̾ͻᱻ???ѣ????б????ѵ??߳̽?ȥ??????ļ????????Ĵ???Ȩ????Ȼ????Ҳֻ??һ???߳???ȡ?ô??????豸R/W?¼???Ȩ?ޣ????????????ePump?̵߳ľ?ȺЧӦ??
ePump?????ȷʵ????һ??iodev_t?豸???ͣ????Ǽ???ij??????˿ڵ?Listen?豸??????TCP Listen??UDP Listen????ij??????˿?ʱ????????iodev_t?豸??????Ҫ?????е?ePump?̣߳???????ePump?̶߳Ը??豸????R/W״̬??ش???????????????Ŀ???ǽ???ͬ?ն??û??Ըö˿ڷ?????????ܹ?????ط??䵽??ͬ??ePump?߳??У??????????????????ᵼ??ijһ??ePump?̷߳dz???æ????????ePump?߳?????????е?״̬??
????ePump?̶߳??????˿ڷ????iodev_t?豸??????????????Ҫ?ֱ?????
1. ????ϵͳ?ں?֧??SO_REUSEPORT Socketѡ?????
2. ????ϵͳ?ں˲?֧??SO_REUSEPORTѡ?????
The framework ePump can run on most Unix-like system and Windows OS, especially work better on Linux.
If you get the copy of ePump package on Unix-like system and find the Makefile in the top directory, please type the following commands before getting the library installed:
$ make && make install
The new generated ePump libraries will be installed into the default directory /usr/local/lib, and the header file epump.h is copied to the location /usr/local/include.
After including the header "epump.h", your program can call the APIs provided in it.
#include <epump.h>
Adding the following compiler options in Makefile, you'll be ready to go!
-I/usr/local/include -L/usr/local/lib -lepump
Please refer to the test program for your coding. Further tutorial or documentation will be coming later. Hope you enjoy it!
ePump?????Ŀ?????? adif ??Ŀ?ṩ?Ļ??????ݽṹ???㷨?⡣adif ???ñ? c ???Կ????ij??????ݽṹ???㷨?????⣬??ΪӦ?ó????ӿڻ????⣬Ϊ??д?????ܳ????ṩ???????ɼ??????????????Ŀ?Ŀ??????ڣ????????̿???Ч?ʣ???ȷ??????ϵͳ???е?>?ɿ??ԡ??ȶ??ԡ?adif ??Ŀ?ṩ?????ݽṹ???㷨?⣬??Ҫ???????????ݽṹ?????????ݽṹ?????????ݴ????㷨?????õ??ַ??????ֽ??????ַ?????????ʱ??ȴ??????ڴ???ڴ?صķ????ͷŹ??????????ļ?????־???ԡ??ļ????ʡ??ļ????桢JSon??MIME?ȹ?????ͨ?ű?̡??ļ??????ź??????????????¼?֪ͨ???????ڴ?ȵȡ?
???? adif ??? ePump ??ܿ?????????һ????Դ??Ŀ?? eJet Web ????????eJet Web ????????Ŀ?????? adif ??? ePump ??ܿ??????????????????? Web ????????ϵͳ???????? Zero-Copy ??????֧?? HTTP/1.1??HTTPS ??ȫ?????ܣ??ṩ??????????URI rewrite??Script?ű?????????Cookie??????TLS/SSL???Զ?Redirect??Cache???ش洢????־?ļ??ȹ??ܣ??Ǿ?̬?ļ????ʡ????ء??Լ?PHP???ص?????ƽ̨?????Գ????ļ????ϴ??????ṩ??Ч֧?š????⣬??֧?? Proxy?? ?????????????????? TLS/SSL??FastCGI?? uWSGI?????? Cache ?洢??????CDN?ڵ????ȸ????ܡ?eJetϵͳ??????ΪWeb?????????? PHP Ӧ?á?Python Ӧ?ã?ͬʱ???û???? Proxy ???ܣ?????????????Ϊ CDN ?ַ?ϵͳ????Ҫ?ַ??ڵ㡣
?д???Linux??ϵͳ?ϵ?Ӧ??ƽ̨??ͨ??ϵͳ???????????????????Ա??????ʦ?????ʼ?[email protected]?????ҵ????ߣ?????ͨ??QQ????571527???ź?beijingkehz?????????ԡ?
ePump?????Ŀ????????????????Դ??Ŀ?ĵڶ?????Ŀ????Ϊ??????ϵͳ??????????ܣ??Ǵ???ϵͳ?з?ʵ?????????????ģ?Ϊ????????????ϵͳ?ṩ???֧?š?????ĿԴ????2003?꿪????ɵ?eProbe??Ŀ??????????????˴??????Ż????????ø??Ӽ???Ч??