Original: Twemproxy source analysis of the second Nc_run

Source: Internet
Author: User

The Nc_run function is not a few lines. The main functions are Core_start, Core_loop, and Core_stop.


Where Core_start is used to initialize the basic parameter values of conn,mbuf,msg these important data structures, It is more important to set the context variable in the instance based on the configuration file and command line parameters (the previous section we mentioned that a Twemproxy instance corresponds to a context variable CTX) The Core_loop function is primarily called event_wait waiting for an IO event to occur. Core_stop is the function of the reverse operation of the Core_start function  1.core_startcore_start to the important data structure conn,mbuf,msg set the basic parameters (such as each mbuf size, etc.), The other is to use Core_ctx_create to instance the context variable CTX assignment value. Here, let's focus on core_ctx_create. This function assigns a value to the Contex type variable CTX According to the configuration file and command line arguments. The main operations in the assignment are: 1). CTX->CF = Conf_create (nci->conf_filename); This function assigns a value to the CF variable in CTX. The        CF variable is of type Conf. The reason for this type is that the function used by the operation and the results obtained after parsing are included in the structure. Conf_create sets the function pointers and parsing types in CF first, then processes them, and finally saves the processed results in the ARG array of the Conf struct. Note: The contents of the last configuration file are all contained in the ARG array of the Conf struct, and the pool in the configuration file and the server information in each pool are saved in the Conf pool array. 2). Server_pool_init (&ctx->pool, &ctx->cf->pool, CTX); This function is based on the ctx->cf-> Pool (This is not a single pool type) information, build the CTX Pool array (Contex's pool type is also an array). 3). Ctx->stats = Stats_create (Nci->stats_port, nci->stats_addr, Nci->stats_interval,nci->hostname, &ctx->pool); This function is guaranteed in Ctx->stats->current (or Ctx->stats->shadow or ctx->stats->sum), each of the Server_poo has a stats_server_pool. and every The server corresponds to a stats_server. and (the relationship between Stats_server and Stats_server_pool) is consistent with the relationship between (server and Server_pool). Similarly, all stats_server_pool make up the ctx->stats->current (or Ctx->stats->shadow or ctx->stats->sum) An array (that is, struct member Stats_pool), just as all server_pool make up an array of CTX (struct member Server_pool). It's a little bit around, but the one by one correspondence is well understood. 4). Ctx->evb = Event_base_create (event_size, &core_core);      This function call Event_base_ Create (), we get a event_base5 that can hold 1024 event.     status = Server_pool_preconnect (CTX); function if Server_pre_connect is set, the connection to the backend Redisserver is established in advance 6).     status = Proxy_init (CTX);       Start monitoring  

2. Core_loop NSD = event_wait (Ctx->evb, ctx->timeout); Waits for the event to occur 3.core_stop the parameters when the cleanup process runs. In the next chapter we will explore the epoll mechanisms used in twemproxy.

Original: Twemproxy source analysis of the second Nc_run

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.