Memcached source code analysis (threading model)--reference
-
- conn_queue_item {
- sfd out of the;
- init_state;
- event_flags;
- read_buffer_size;
- is_udp;
to establish a connection fd
- conn_queue CQ;
- conn_queue {
{
- event_base
-
-
-
{
- sfd out of the;
- State;
- event event;
- which;
- * RBUF;
thread process:
worker threads if MT mode * /
encapsulates create listening socket bound address,set the non-blocking mode and register the listening socket
thread_init all workers thread,look at the core code thread_init
nthreads, event_base * {
-
- (LIBEVENT_THREAD) * nthreads);
- (threads) {
-
-
- (i = 0; i
- fds [2];
- (pipe (fds)) {
-
-
-
-
- (i = 1; i
* me) {
- (! me-> base) {
- base = event_init ();
- (! me-> base) {
-
-
- notify_event,me-> notify_receive_fd,
- base,& me-> notify_event);
-
- (event_add (& me-> 0) == -1) {
-
- new_conn_queue);
all workers thread pipe read end the libevent of read events,wait for the main thread last all workers CQ initialization
fd, which, * arg) {
- buf [1];
-
- (read (fd,buf,1)! = 1)
- (settings.verbose,> 0)
-
- new_conn_queue);
-
- (NULL! = item) {
- sfd,item-> init_state,item-> event_flags,
- read_buffer_size,item-> is_udp,me-> base);
-
SFD is already established connection descriptor,by conn_new function of the descriptor registration the libevent read event,me-> Base on behalf of a thread structure,that is the descriptor event processing the to this workersThreading,the most important elements of conn_new method is:
SFD, init_state, event_flags
- read_buffer_size, event_base * base) {
-
- event,sfd,event_flags,event_handler, *) c);
- event);
- ev_flags = event_flags;
- (event_add (& c-> event,0) == -1) {
- (conn_add_to_freelist (c)) {
- NULL;
-
drive_machine (conn * c) {
- stop =
- SFD,flags = 1;
- sockaddr_storage addr;
- res;
-
-
- (! stop) {
-
- (c-> state) {
- (addr);
- ((sfd = accept (c-> sfd, sockaddr *) & addr,& addrlen)) == -1) {
-
- ((flags = fcntl (sfd, 0)) <0 | |
-
- (try_read_command,(c) = 0) {
conn_states to {
sfd,
- read_buffer_size, {
- = + 1)%
-
-
- sfd = sfd;
- init_state = init_state;
- event_flags = event_flags;
- read_buffer_size = read_buffer_size;
- is_udp = is_udp;
-
- new_conn_queue,item);
-
- Thread_id);
- (write (threads 1)! = 1) {
相关文章
前言设计一个缓存系统,不得不要考虑的问题就是:缓存穿透、...
在192.168.80.100要联网关闭防火墙及SElinuxsystemctlstopfi...
Redis与Memcache对比:1.Memcache是一个分布式的内存对象缓存...
安装Mencache:关闭防火墙及SElinuxsystemctl stop fi...
#安装php的yaf模块,参考https://www.cnblogs.com/shifu204/...
win10下安装配置apache、php、mysql、redis、memcache资源官...