Memcached source code analysis (threading model)--reference

      (thread.c): 

     
  1.   
  2.  conn_queue_item {
  3.  sfd out of the;
  4.  init_state;
  5.  event_flags;
  6.  read_buffer_size;
  7.  is_udp;

 to establish a connection fd 

     
  1.    conn_queue CQ;
  2.  conn_queue {

 

       {
  1.  * / 
  2.  event_base  base;  *  *  
  3.     event  
  4.   
  5.   
  6.  

   

       {
  1.  sfd out of the;
  2.  State;
  3.  event event;
  4.  which;
  5.  * RBUF;
  6.  the status flag and read-write buf information 

  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 *  {
  1.     
  2.  (LIBEVENT_THREAD) * nthreads);
  3.  (threads) {
  4.   
  5.   
  6.  (i = 0; i
  7.  fds [2];
  8.  (pipe (fds)) {
  9.   
  10.   
  11.   
  12.  
  13.  (i = 1; i

    

       * me) {
  1.  (! me-> base) {
  2. base = event_init ();
  3.  (! me-> base) {
  4.   
  5.  
  6. notify_event,me-> notify_receive_fd,
  7. base,& me-> notify_event);
  8.   
  9.  (event_add (& me->  0) == -1) {
  10.   
  11. 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) {
  1.  buf [1];
  2.   
  3.  (read (fd,buf,1)! = 1)
  4.  (settings.verbose,> 0)
  5.   
  6. new_conn_queue);
  7.   
  8.  (NULL! = item) {
  9. sfd,item-> init_state,item-> event_flags,
  10. read_buffer_size,item-> is_udp,me-> base);
  11.     

  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
  1.    read_buffer_size,     event_base * base) {
  2.   
  3. event,sfd,event_flags,event_handler,  *) c);
  4. event);
  5. ev_flags = event_flags;
  6.  (event_add (& c-> event,0) == -1) {
  7.  (conn_add_to_freelist (c)) {
  8.  NULL;
  9.   

     

       drive_machine (conn * c) {
  1.  stop = 
  2.  SFD,flags = 1;
  3.  sockaddr_storage addr;
  4.  res;
  5.   
  6.   
  7.  (! stop) {
  8.   
  9.  (c-> state) {
  10.  (addr);
  11.  ((sfd = accept (c-> sfd,  sockaddr *) & addr,& addrlen)) == -1) {
  12.  
  13.  ((flags = fcntl (sfd,  0)) <0 | |
  14.   
  15.  (try_read_command,(c) = 0) {
  16.  

    

     conn_states to {
  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  

   

      sfd,    
  1.  read_buffer_size,  {
  2.    =  + 1)% 
  3.   
  4.   
  5. sfd = sfd;
  6. init_state = init_state;
  7. event_flags = event_flags;
  8. read_buffer_size = read_buffer_size;
  9. is_udp = is_udp;
  10.   
  11.  new_conn_queue,item);
  12.   
  13.  Thread_id);
  14.  (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资源官...