# Event Loop

**URL:** <https://discuss.aerospike.com/t/event-loop/6088>\
**Category:** C Client Library\
**Created:** [March 31, 2019, 8:28am UTC](https://discuss.aerospike.com/t/event-loop/6088 "2019-03-31T08:28:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shikhil\_Gupta](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/shikhil_gupta/32/1082_2.png) [@Shikhil\_Gupta](https://discuss.aerospike.com/u/Shikhil_Gupta)\
**Post date:** [March 31, 2019, 8:28am UTC](https://discuss.aerospike.com/t/event-loop/6088/1 "2019-03-31T08:28:20Z")

</div>

Hi, I was trying to understand this param async\_max\_conns\_per\_node([C Client API: as\_config Struct Reference](https://www.aerospike.com/apidocs/c/d0/d99/structas__config.html#ab55a0a0837199c2214a3802311e06e94)). 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?

---

<div class="post-metadata">

**Author:** ![Brian](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/brian/32/2211_2.png) [@Brian](https://discuss.aerospike.com/u/Brian)\
**Post date:** [April 1, 2019, 6:56pm UTC](https://discuss.aerospike.com/t/event-loop/6088/2 "2019-04-01T18:56:49Z")

</div>

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:

```auto
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;
}

```
