加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Memcached source code analysis (threading model)--reference

发布时间:2020-12-16 05:54:00 所属栏目:安全 来源:网络整理
导读:? ? ? ? ? ?(thread.c): ? ? ? ? ?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? ?base;? ?*? ?*? ? ?

??????(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) {

???????

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读