These are chat archives for akkadotnet/akka.net

2nd
Feb 2018
Onur Gumus
@OnurGumus
Feb 02 2018 18:12
Why would I use Prestart instead of actor constructor ?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 18:12
if there's anything that can throw an exception et al, probably best to do it in PreStart
you can also skip calls to PreStart when an actor restarts by overriding the PostRestart method and not calling base.PostRestart
some people do this when they don't want to do things like recreate children upon restarting an actor
I usually only do basic assignments inside the constructor like setting an actors' private fields and its initial behavior
Onur Gumus
@OnurGumus
Feb 02 2018 18:13
Yes it makes sense. Prestart is really powerful than the ctor.
Aaron Stannard
@Aaronontheweb
Feb 02 2018 18:13
but stuff like spawning child actors et al I do in PreStart
Onur Gumus
@OnurGumus
Feb 02 2018 18:16
@Aaronontheweb is it possible children can survive if parent restarts?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 18:16
yeah
Onur Gumus
@OnurGumus
Feb 02 2018 18:16
How?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 18:16
need to skip base call to base.PreRestart in your override of PreRestart
Onur Gumus
@OnurGumus
Feb 02 2018 18:16
Oh
we could probably make that more obvious
since it's kind of nestled into the API docs
Onur Gumus
@OnurGumus
Feb 02 2018 18:21
What is the best way to test if parent actor creates its children?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 18:21
the quick and dirty way
Onur Gumus
@OnurGumus
Feb 02 2018 18:22
Which is?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 18:22
Context.ActorSelection([parent path] / "*").Tell(new Identify(null))
that'll select all of the actors on the hierarchy immediately below the parent
doesn't require you to add any test code to the parent actor either
so you can test it from the outside
all of the children who have started at the time the selection is sent
Onur Gumus
@OnurGumus
Feb 02 2018 18:23
Good idea . Never thought of it
Aaron Stannard
@Aaronontheweb
Feb 02 2018 18:23
will reply back with ActorIdentity
since Identify is an automatically received message
meaning that Akka.NET itself handles that
you might need to run that code inside an AwaitAssert in the TestKit
just in case there's a bit of a race between the actors starting up and the actor selection being sent
Onur Gumus
@OnurGumus
Feb 02 2018 18:24
Is it ask or tell?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 18:24
I think I have an example...
Tell in this case
because you can't receive multiple replies back to an Ask
Onur Gumus
@OnurGumus
Feb 02 2018 18:25
How do I get replies then using expectmsg?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 18:25
I'd do something like this
AwaitAssert(() => {
   var probe = CreateTestProbe();
Context.ActorSelection([parent path] / "*").Tell(new Identify(null), probe);
probe.ReceiveN(number of replies);
});
Onur Gumus
@OnurGumus
Feb 02 2018 18:26
Got it.
Aaron Stannard
@Aaronontheweb
Feb 02 2018 18:27
there we go, finally got it formatted correctly
that code will run repeatedly for up to 3 seconds by default
and I think it runs at 500 ms intervals or something
you might have to manually adjust the timeout on the ReceiveN call to be something smaller than 3s
just to guarantee that this code can run multiple times
Onur Gumus
@OnurGumus
Feb 02 2018 18:28
But probably I woul be interested the actors the self rather than count
Aaron Stannard
@Aaronontheweb
Feb 02 2018 18:28
but this is one of the easier ways to deal with racy stuff like that
the ReceiveN call will return the replies back
Onur Gumus
@OnurGumus
Feb 02 2018 18:28
Oh fine
Aaron Stannard
@Aaronontheweb
Feb 02 2018 18:28
and the ActorIdentity message will hold onto an IActorRef for the sender
stevemesser
@stevemesser
Feb 02 2018 18:31

I am trying to follow the pluralsight course "Building Distributed Systems with Akka.NET Clustering" by Simon Anderson

I am trying to use lighthouse and my actorsystem on the same computer.

  1. The lighthouse node starts up fine listening on port 4053
  2. When I start up my actor system I am getting the following errors:

  3. Association with akka.tcp://MyActorSystem@127.0.0.1:4053 has failed Reason is [Disassociated]

  4. Association error [The message cannot be null]
Do I have it configured wrong?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 18:31
hmmm
what versions of Akka.NET are being used in both apps?
the Message cannot be null error message immediately makes me think there's a serialization issue
stevemesser
@stevemesser
Feb 02 2018 18:40
Lighthouse akka 1.3.1 and the example code is using akka 1.0 5.14 ......
probably an issue
Aaron Stannard
@Aaronontheweb
Feb 02 2018 18:55
ah yeah
just update the sample code to Akka.NET v1.3.0 or later
and that should fix it
stevemesser
@stevemesser
Feb 02 2018 18:55
Sorry rookie mistake.. Thanks.
Onur Gumus
@OnurGumus
Feb 02 2018 21:38
Can you tell me why Lighthouse is useful? AFAIK it is a service discovery tool but still unclear to me ?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:38
it's a really simple solution what could otherwise be a hard problem
Onur Gumus
@OnurGumus
Feb 02 2018 21:38
Like ?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:39
in order to form a cluster initially, all of the seed nodes who create the cluster need to contact each other
and from that point onward, anyone who wants to connect to the cluster needs to contact at least one of the seeds who are current members of the cluster
Onur Gumus
@OnurGumus
Feb 02 2018 21:40
So either I hard code them or use lighthouse ?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:40
if your seed nodes are dynamic, i.e. they are part of your application and are affected by deployments
then you have a moving target
Onur Gumus
@OnurGumus
Feb 02 2018 21:40
So lighthouse tracks the seeds?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:41
so to solve that problem, you'd need to use a Service Discovery platform and instrument all of your apps with a bootstrapper to identify seed nodes that are both up and members of the cluster
Lighthouse is the alternative
just park 2-3 lighthouse nodes on static locations on the network
and never touch them during deployments
Onur Gumus
@OnurGumus
Feb 02 2018 21:41
Speeking of seeds and leaders, I am always confused for a cluster whose configuration takes in effect.
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:42
eliminates several different failure classes from the process of starting up a cluster
and reduces the number of moving parts overall
Onur Gumus
@OnurGumus
Feb 02 2018 21:42
Suppose that I have different settings for autodown or split brain settings in different nodes
What happens if leader changes ?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:42
leader will use whatever its local settings are on that node
so its behavior can be different if the configurations are different
Onur Gumus
@OnurGumus
Feb 02 2018 21:43
So the settings may change as the leader changes.
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:43
yeah
Onur Gumus
@OnurGumus
Feb 02 2018 21:43
Another question, if you were to ask 100% uptime for multiple nodes, what is the correct strategy to do so?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:43
a best practice is to have a standardized configuration for most of the Akka.Cluster settings
seed nodes, split brain resolver, etc
only things that should change on a per-node basis are the role settings
Onur Gumus
@OnurGumus
Feb 02 2018 21:44
Lets say not even 1 second down time is not allowed.
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:44
if I had an extremely high level of uptime required
Onur Gumus
@OnurGumus
Feb 02 2018 21:44
And I have persistent actors
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:44
I would do two things
first is, you have to have a partition tolerance strategy where different parts of the cluster can all be down at the same time while remaining available
so that's going to require relaxing your consistency requirements
Onur Gumus
@OnurGumus
Feb 02 2018 21:45
Lets assume no network partition happens (I know it is a big and false assumption)
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:45
since the nodes who can't reach other won't be able to synchronize state
ok
well second strategy then
is you should be using replication aggressively
DistributedData is our built-in implementation
Onur Gumus
@OnurGumus
Feb 02 2018 21:46
Ah yeah I read about that too. But the docs were a bit confusing.
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:46
but essentially you'd want to make sure that any piece of state that has to be available should either be immediately recoverable on the new node (Akka.Persistence)
or better yet, already available on that node even before the prior one is shutdown (DistributedData)
IMHO
I've not been in a scenario with any of the apps I've worked on
Onur Gumus
@OnurGumus
Feb 02 2018 21:47
about this distributed data we have CRDT types.
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:47
where the recovery time of Akka.Persistence / my own persistence layer was a critical factor in processing real-time workloads
Onur Gumus
@OnurGumus
Feb 02 2018 21:47
What if my data is a string string key value pair?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:48
you'd want to use one of the Map types
which is a dictionary, essentailly
essentially*
Onur Gumus
@OnurGumus
Feb 02 2018 21:48
these CRDT types all look numeric
Where are that map types documented?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:48
the Sets are basically hashsets
the Dictionary / Map types on this list are all dictionaries
ORDictionary for instance
Onur Gumus
@OnurGumus
Feb 02 2018 21:49
ORDictionary (also knowns as OR-Map or Observed Remove Map) has similar semantics to OR-Set, however it allows to merge values (which must be CRDTs themselves) in case of concurrent updates.
Yes but it says the types should be CRDT
I don't see strings are CRDT
That's where I am confused.
Or maybe I completely misunderstood things...
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:51
var key = new ORSetKey<string>("keyA");
for instance
Onur Gumus
@OnurGumus
Feb 02 2018 21:51
that's a CRDT?
Hmm
What possible values can that generic type have ?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:52
let me check
I think any type
Onur Gumus
@OnurGumus
Feb 02 2018 21:52
It is serialized ?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:52
yes it does get serialized
Onur Gumus
@OnurGumus
Feb 02 2018 21:53
Understood
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:53
although, disclaimer: at this rate you'd want to ask @Horusiath about DData
he's the implementor and resident expert
since we're approaching the extent of my familiarity with it :p
Onur Gumus
@OnurGumus
Feb 02 2018 21:54
Another question, I am using EventStream for publishing events. As events don't include the sender, I am considering the sender to be part of the event.
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:54
the EventStream has no concept of a sender really
you'd want to package a ref to the sender inside the message
Onur Gumus
@OnurGumus
Feb 02 2018 21:54
Though if I include it as IActorRef, what happens if it is persisted and serialized?
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:54
ah
Onur Gumus
@OnurGumus
Feb 02 2018 21:55
to database for instance
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:55
serializing the IActorRef woudln't work out so well
can't really re-hydrate it
Onur Gumus
@OnurGumus
Feb 02 2018 21:55
then perhaps I should use names
Aaron Stannard
@Aaronontheweb
Feb 02 2018 21:55
you can do what Akka.Persistence does and serialize actor paths
Onur Gumus
@OnurGumus
Feb 02 2018 21:56
Also another thing, if my actor resubscribes to same event multiple times due to restarts, is that okay?
Bartosz Sypytkowski
@Horusiath
Feb 02 2018 21:56
@OnurGumus ORSet is actually AWOR Set (AW -> Add wins)
Onur Gumus
@OnurGumus
Feb 02 2018 21:57
@Horusiath I see.
Bartosz Sypytkowski
@Horusiath
Feb 02 2018 21:57
if you use IDE with support for xmldocs, you'll see that ORSet<> sections are pretty detailed
Onur Gumus
@OnurGumus
Feb 02 2018 21:58
I will check it, thanks @Horusiath .
My experiments show re-subscribing is not an issue. But not sure if it leaks something
Onur Gumus
@OnurGumus
Feb 02 2018 22:39
@Aaronontheweb I noticed that if one of the seeds only contain its own address, on restart, it just doesn't join the cluster but act as remoted only. Is this expected?
Bartosz Sypytkowski
@Horusiath
Feb 02 2018 23:06
@OnurGumus yes. Otherwise, how would node know which address to connect?