For all deployment architectures, Oracle recommends the following load balancing practices.
Use load balancers with the MDEX Engine to increase throughput and ensure availability in the event of hardware failure. Oracle recommends including two hardware-based load-balancing switches configured redundantly in your configuration. Having two load balancers ensures their availability in the event of a load balancer hardware failure.
Use the "least connections" model as the best routing algorithm for balancing traffic to the Dgraphs. The “round robin” model can have negative consequences, especially when occasional long-running queries are possible and the site is operating near its maximum traffic load.
Ensure that return traffic from Dgraphs to the client tier is directly transmitted, and does not pass back through the load balancer hardware.
Use scripting for load balancers. For example, you can use
http://[host]:[port]/admin?op=ping
on the load balancer to check whether the Dgraph process is running on this port. If it is not running, the load balancer fails over to another port, and directs queries to the MDEX Engine that is currently available.
In a load balancing situation, consider enabling session affinity on the application server that directs server requests to the load balanced Dgraphs.
Session affinity, also known as “sticky sessions”, is the function of the load balancer that directs subsequent requests from each unique session to the same Dgraph in the load balancer pool. Implementing session affinity makes the utilization of the Dgraph cache more effective, which improves performance of Dgraph access and the application server.
To facilitate session affinity, your application code can call
ENEQuery.setQueryInfo()
to create an
ENEQueryInfo
object. In this object, you set
query-specific information in name/value pairs (such as the session ID and
query ID) for the MDEX Engine to log.
Alternatively, you can also set this information by calling
HttpENEConnection.addHttpHeader()
and specifying a
name/value pair.
In either approach, the Web application sends the name/value pairs to
the MDEX Engine. However, the
setQueryInfo()
method adds the name/value pairs to the
query object itself; while the
addHttpHeader()
method adds the name/value pairs to the
header of the HTTP GET request.
In cases where long URLs interact poorly with a load balancer, you may
need to force a POST request. You can force a POST request by calling
HttpENEConnection.setMaxUrl()
and specifying an upper
limit on the length of the URL. Any URLS longer than the specified value are
sent to the MDEX Engine using a POST request. You can also call
setMaxUrl()
and specify a value of 0 to force a POST
request for all queries regardless of URL length.
Remember that application code automatically sends a query using a POST
if the URL becomes too long to send using a GET request. The
setMaxUrl()
provides a way to force the request type if
necessary.
Session affinity increases the latency overhead of the load balancer. Therefore, Oracle recommends testing the load balanced environment for performance optimization. This helps to determine whether the benefit of increased leverage from the Dgraph cache exceeds the cost of increased latency in the load balancer.