Java Client sessions and Load Balancer in High Availability

Hello,

I am using Java Client in my project, but due to the high volume of traffic I will receive, I am reusing the same NuxeoClient object (in order to avoid a lot of nuxeo connections). I have a lot of users, but all of them will connect to my services (that use Java Client) with the same Nuxeo user. I am using Spring Boot, so I have a class with a NuxeoClient object and the following method:

@PostConstruct
private void connect() {
    nuxeoClient = new  NuxeoClient.Builder().url(url).authentication(username, password).connect();
}

Note the “PostConstruct” annotation; the Nuxeo Client object is initialized when the application starts. Then, in my services, I just @Autowired the class with the NuxeoClient object. I am doing this because I have detected a “big” delay in the nuxeo connection (around 500 ms), so I want to have this delay only with the first request.

Before implementing this solution (generating a NuxeoClient object in every client request):

  • Request #1: 600 ms (500 ms connection + 100 ms service logic).
  • Request #2: 600 ms (500 ms connection + 100 ms service logic).

After implementing my solution:

  • Request #1: 600 ms (500 ms connection + 100 ms service logic).
  • Request #2: 100 ms (100 ms service logic).

The problem with this solution is the load balancer in a high availability cluster. If the load balancer has sticky sessions, all the requests go to the same nuxeo server. However, according to the nuxeo documentation, I cannot have a load balancer without sticky sessions: “Load balancing can be managed by software or hardware, but in all cases (even if you use Nuxeo as a bare server without a UI) the only constraint we ask for is to have a load balancer configured with sticky sessions.”

Info: https://doc.nuxeo.com/nxdoc/nuxeo-cluster-architecture-introduction/

So, how can I proceed? Is it mandatory to open a new session per request in order to implement a high availability cluster? Cannot I reuse sessions to get a better performance?

I have removed sticky sessions from the load balancer, and the requests seem to be working fine, but the load balancer is not working properly, as all the requests go to the same nuxeo server node.

Thank you.

0 votes

1 answers

1230 views

ANSWER



Hello,

I forgot to reply to this topic, as my problem was solved. When I created this topic, I thought Nuxeo Java Client SDK generate sessions and store the cookie; however, that's not true: https://doc.nuxeo.com/client-java/3.2/authentication/

Java Client SDK uses Basic Authentication, so each request is 100% independent. What takes time is the building of the “NuxeoClient” object that works as a template.

After some exhaustive research in my architecture, I realised one of my servers wasn't configured correctly; that's why the load balancing didn't work as expected. Now everything works fine.

Regards.

0 votes