Connectivity with Load Balancer
Often, application deployments employ load balancers to prevent requests from overwhelming servers, i.e., prevent clients from accessing the servers directly.
Note
This configuration is for load balancers using a round-robin approach.
Important
Ensure that sticky sessions are not enabled in the load balancer.
In such circumstances, to ensure that your client connects to all the machines in the cluster (which is necessary for both the Partitioned and Partition-Replica topologies), NCache offers the is-load-balancer
configuration.
This configuration works by using multiple requests to establish connections with all the desired servers connected to the load balancer. For example, imagine you have a load balancer connected to three servers where NCache is already connected to server 1 and needs to be connected to the other servers, it will then send repeated requests until it is connected to server 2 and server 3 sequentially. After the first connection is established, the load balancer sends the second request to server 2, NCache will receive the server ID and agree to establish a connection before moving on, as demonstrated below.
However, if the load balancer sends the request to server 3, NCache will reject the connection and try again, as shown below. This process will continue until it is connected to all the servers or until the specified number of retries has been reached (load-balancer-connection-retries
).
Note
The default number of load-balancer-connection-retries
is 15 and the minimum number of retries is 2.
Important
The load-balancer-connection-retries
tag signifies how often the load balancer is prompted per regular connection retry (i.e., connection-retries). Therefore, if connection-retry= 3
and load-balancer-connection-retries= 15
, the load balancer will be prompted 15 times per retry, totaling 45 prompts to the load balancer to get the client connected to the correct machine.
Note
All connection attempts are logged.
Configure NCache to Address the Load Balancer
To enable this flag, you can edit the client.ncconf file (available at %NCHOME%\config
in Windows or opt/ncache/config
in Linux) by setting is-load-balancer
to True, as follows:
<configuration>
<ncache-server connection-retries="3" retry-connection-delay="0" retry-interval="1" load-balancer-connection-retries = "15" command-retries="3" command-retry-interval="0.1" client-request-timeout="90" connection-timeout="5" port="9800" local-server-ip="20.200.20.40" enable-keep-alive="False" keep-alive-interval="30"/>
<cache id="demoCache" client-cache-id="" client-cache-syncmode="optimistic" skip-client-cache-if-unavailable="True" reconnect-client-cache-interval="10" default-readthru-provider="" default-writethru-provider="" load-balance="False" enable-client-logs="True" log-level="info">
<server name="20.200.20.40" is-load-balancer="True"/>
</cache>
</configuration>
Note
You can also do this programmatically using the CacheConnectionOptions API.
See Also
Cache Topologies
Cache Cluster
Cache Client
Client Cache
Bridge for WAN Replication