Load balancing and session affinity

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.

Note: The addHttpHeader() method works with the Dgraph but does not work with the Agraph. (The setQueryInfo() method works with both the Dgraph and Agraph.)

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, Endeca 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.