2

Hey I'm doing some reading and watching some videos on AKKA.Net and am loving what I am seeing. I want to try AKKA.net in an existing application I have but I need help clarifying some things

Scenario
I want to create an Akka.net cluster with:

  • 3 Nodes/ Machines

  • a shared resource (a counter) between them.

  • a shared Resource statistics readable from all nodes

    Whenever a node cashes a ticket it will take the value of the counter and increment it by one then update the counter. No two tickets should have the same counter value. The shared statistics info is to hold the value if tickets cashed in so it should be deployed to all nodes in the cluster.

Questions

  1. How do I ensure that the tickets have unique counter values? I am used to the locks implimentation but what would be the actor implimentation?
  2. if a node is disconnected from the cluster is an event raised that I can catch to make the necessary adjustments?
Community
  • 1
  • 1
MikeM
  • 61
  • 3

1 Answers1

1
  1. How do I ensure that the tickets have unique counter values?

If you can't access the actor system to request a "counter" or identifier, then use something like a GUID to uniquely identify a resource (Guid.NewGuid()). If you require a global integer counter then you'll have to implement an actor which tracks this counter and dispenses new values on demand.

  1. if a node is disconnected from the cluster is an event raised that I can catch to make the necessary adjustments?

Yes, you can listen to Cluster gossip events and determine when a node has been disconnected and decide if it is no longer available:

http://getakka.net/docs/clustering/cluster-extension#working-with-cluster-gossip

easuter
  • 1,167
  • 14
  • 20
  • Thanks for your answer easuter, your answers are on point but I want some clarification on something. I do require a global counter and at the same time need the system to be fault tolerant. So if I create an actor called the counterActor. Would I deploy it to all nodes for high availability just in case the node with that actor goes down? if so how do I ensure that only one counterActor processes the message at a time? – MikeM Jan 11 '16 at 17:52
  • @MikeM This depends, is it a global counter across all nodes? If so, then you will need a single source to dispense the values. If you try to have multiple actors dispense perfectly sequential values you will have to have some way to coordinate this process, which won't be simple and will be prone to "split brain" scenarios. [Here is a good article](https://aphyr.com/posts/313-strong-consistency-models) about trying to work with consistency on distributed systems. – easuter Jan 13 '16 at 02:25
  • @MikeM In a project I'm working on, I abandoned sequential IDs in favour of GUIDs for the reasons I mentioned in my previous comment. In my database I have column to lookup these GUIDs but use sequential integers for primary/foreign keys, since this will be much faster and index-friendly for the RDBMS. If you *absolutely* require sequencial integers, as far as I know a single global actor will have to do. Lastly, you might also get more info if you ask for more input at [Akka.NET's Gitter chat](https://gitter.im/akkadotnet/akka.net), where more seasoned folks and devs hang out :) – easuter Jan 13 '16 at 02:33