Memcache   发布时间:2019-11-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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) {

       

大佬总结

以上是大佬教程为你收集整理的Memcached source code analysis (threading model)--reference全部内容,希望文章能够帮你解决Memcached source code analysis (threading model)--reference所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:
猜你在找的Memcache相关文章
其他相关热搜词更多
JavaScriptJS对象html字符串csshttps循环事件json架构npm运算符typescriptuigithub异步数据库dom