Memcached source code analysis (threading model)--reference

      (thread.c): 

Highlighter" data-iceapw="38" data-iceapc="49">
     
  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 

Highlighter" data-iceapw="27" data-iceapc="38">
     
  1.    conn_queue CQ;
  2.  conn_queue {

 

Highlighter" data-iceapw="75" data-iceapc="62">
       {
  1.  * / 
  2.  event_base  base;  *  *  
  3.     event  
  4.   
  5.   
  6.  

   

Highlighter" data-iceapw="32" data-iceapc="42">
       {
  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:  

Highlighter" data-iceapw="15" data-iceapc="13">
     

 

Highlighter" data-iceapw="14" data-iceapc="13">
     worker threads if MT mode * / 

 

Highlighter" data-iceapw="5" data-iceapc="7">

 encapsulates create listening socket bound address,set the non-blocking mode and register the listening socket   

Highlighter" data-iceapw="13" data-iceapc="13">
     

  thread_init all workers thread,look at the core code thread_init 

Highlighter" data-iceapw="118" data-iceapc="113">
      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

    

Highlighter" data-iceapw="89" data-iceapc="79">
       * 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     

Highlighter" data-iceapw="79" data-iceapc="75">
        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: 

Highlighter" data-iceapw="74" data-iceapc="93">
       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.   

     

Highlighter" data-iceapw="118" data-iceapc="138">
       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.  

    

Highlighter" data-iceapw="80" data-iceapc="53">
     conn_states to {
  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  

   

Highlighter" data-iceapw="80" data-iceapc="83">
      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) {

       

相关文章

1. memcached内部不会监视记录是否过期,而是在get时查看记录的时间戳,检查记录是否过期。 这种技术被...
add方法添加时,如果存在返回falseset方法添加时,如果存在就是覆盖,不存就是添加 1. set方法会在设置时,...
相信还是有很多项目使用memcache,可能有些人说有点out了,但是呢??? 项目上的东西不是你想换就能换...
在前边的tomcat session server msm的那篇博客我们用memcached做tomcat session服务器,默认官方memcac...
在线聊天室(onlinechatrooms)是一个共多人进行沟通交流的网络平台,随着越来越多的新技术的发明和成熟...
1.通过yum安装 复制代码代码如下:yum-yinstallmemcached#安装完成后执行:memcached-h#出现memcached帮助...