coherence icon indicating copy to clipboard operation
coherence copied to clipboard

Cluster deployment

Open meznaric opened this issue 8 years ago • 3 comments

I have 2 nodes connected in a cluster. Initially, I had an issue because users would log in in node-1 and whenever load balancer would put them on node-2 session would be lost and the user logged out.

This was easily solvable by implementing persistence layer to coherence as described in wiki. If a session does not exist on node-2 simply check the DB for session entry and retrieve details from the agent.

The issue is however that whenever I update the user model the change is not replicated across the cluster. Model is updated like written in docs:

apply(
  Coherence.Config.auth_module,
  Coherence.Config.update_login,
  [conn, conn.assigns[:current_user], [id_key: Coherence.Config.schema_key]])

Is there a shared conscious how this is normally done?

At the moment I am thinking of naive implementation where update_login is simply called on each node.

meznaric avatar Jul 23 '17 10:07 meznaric

In my case I re-implemented a part of Coherence just to remove that Agent that maintains a cache local to each node...

edevil avatar Jul 26 '17 16:07 edevil

As @edevil points out, you could remove the Agent cache and hit the database each time, presuming the nodes share the same DB. This will add the overhead of a database hit on each page load.

A couple other approaches:

  • Create a single instance of the Agent on one of your nodes and have modify the Session plug to do a distributed request from the store agent.
  • Implement your own update_login API that syncs the changes with each of the nodes.

smpallen99 avatar Jul 30 '17 18:07 smpallen99

This is what I came up with: https://gist.github.com/meznaric/cf823f87dbb591ab16cf9d21f30b5471 It seems to work.

meznaric avatar Aug 02 '17 22:08 meznaric