Event Loop

Hi, I was trying to understand this param async_max_conns_per_node(C Client API: as_config Struct Reference). I believe this param determine number of asynchronous connection you can make in parallel. But then why should this limit affected by no of event loop?

Also, I could not find the much example also over internet. Can anybody help us to understand?

Having limits on both connections per node and event loop commands/connections is not strictly necessary, but it does give the user more options to allocate resources based on their use-case.

async_max_conns_per_node limits the number of async connections on a node. Each server node can be configured for a strict limit on connections. These connections can then be allocated to client applications. For example, each server node defines 10,000 max connections and there are 20 client applications. Then, async_max_conns_per_node would be set to 500 (or less to allow potential new clients to be started later) for each client application.

as_policy_event max_commands_in_process defines the maximum number of commands to run concurrently in each event loop. Since one connection is assigned to each command, this also effectively limits the number of connections per event loop. If you don’t need/want two limits, then just set max_commands_in_process and adjust async_max_conns_per_node accordingly as follows:

as_policy_event p;
as_policy_event_init(&p);
p.max_commands_in_process = 50;  // Each command in process has 1 assigned connection.
p.max_commands_in_queue = 50000; // Each command in queue does not have an assigned connection.

uint32_t event_loops_size = 10;
as_error err;

if (as_create_event_loops(&err, &p, event_loops_size, NULL) != AEROSPIKE_OK) {
    printf("Error: %d %s\n", err.code, err.message);
    return false;
}

as_config c;
as_config_init(&c);
as_config_add_hosts(&c, "hostname", 3000);
c.async_max_conns_per_node = p.max_commands_in_process * event_loops_size;

aerospike as;
aerospike_init(&as, &c);

if (aerospike_connect(&as, &err) != AEROSPIKE_OK) {
    printf("Error: %d %s\n", err.code, err.message);
    return false;
}