These are chat archives for akkadotnet/akka.net

1st
Apr 2016
maasba
@maasba
Apr 01 2016 02:54
hello anybody on
Kris Schepers
@schepersk
Apr 01 2016 07:09
@Horusiath Woow, didn't see that coming, awesome! Will be digging into that today ;-)
Kris Schepers
@schepersk
Apr 01 2016 07:52
Still not so clear on the "running in the same directory" part though..
Ralf
@Ralf1108
Apr 01 2016 07:57
@Danthar : you seem right ... so do you have any workaround? Didn't think of when actor is restarting...
Arjen Smits
@Danthar
Apr 01 2016 08:14
@Ralf1108 personally? I'd go with the most explicit route. Use a parent actor for the actor in question. So never let the child actor restart, only allow it to continue or stop. Then use Context.Watch to monitor the child actor, and have the parent actor recreate/reinitialise the child actor when needed. Then only communicate with the child actor through its parent. That way you abstract away the fact your actor needs an extra initialisation step to properly work and the logic is contained in the parent actor.
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 08:23
@schepersk same directory means that all cluster exe files are located under the sam path (so their relative path to sqlite db is the same)
Kris Schepers
@schepersk
Apr 01 2016 08:44
@Horusiath Owkay, thanks! Next issue; I finally have a working demo with sharding, but when I run it a second time, it doesn't work and starts logging a massive amount of errors from PersistentShard.ReceiveRecover. BUT, when I modify the region typeName, it works again, once.
Any ideas?
It's a NullReference exception on trying to recover from the snapshot.. Maybe because the system can't find the EventStream table (still using in memory persistence for the moment)?
Ralf
@Ralf1108
Apr 01 2016 09:22
@Danthar that sounds reasonable and I also created our actor structure with this in mind :-)
but there is still an open question: if an actor is stopped all remaining messages in the mailbox are gone. Is this correct?
scenario is that: there is a manager actor and eventually millions of child actors. because not all child actors are used at the same time I want to stop unused actors to save memory
Ralf
@Ralf1108
Apr 01 2016 09:27
so at a point in time the child actors tells its parent that it hadn't done work for a specific period of time and the manager can then decide to stop the child actor
so it sends a poison pill to the child.
Arjen Smits
@Danthar
Apr 01 2016 09:28
Yes that is correct. You would have to use some form of buffering in combination with an ack to verify that messages are really processed. To me it just reinforces the point that this whole pattern is a bad idea :P
Ralf
@Ralf1108
Apr 01 2016 09:28
if after that new work for the child actor is available but the child actor is not stopped yet.. the manager would send a new message to the child actor.
the child actor has in his mailbox a poison pill and the new work message
so it kills itself and the new work message will be removed also
how to handle it that the new work message is not lost?
Arjen Smits
@Danthar
Apr 01 2016 09:30
Why not restructure your dependancies ?
Ralf
@Ralf1108
Apr 01 2016 09:30
does the manager have to deathwatch the child and hold the new work message back? after the child is terminated the child will be recreated by the manager and the held new work message is forwarded to the child
in what way restructure?
ok.. you already wrote it. buffer the messages in a way. so it seems that deatchwatch is the way to go
Arjen Smits
@Danthar
Apr 01 2016 09:31
No
thats not what i meant
Restructure it that you dont need the init message anymore
So this pageVersionGuid and pageVersionModificationsLoaderActorRef why not pass it along in the workmessage your sending
Ralf
@Ralf1108
Apr 01 2016 09:33
ah... it seems that I didnt clarify that I changed the topic to "How handle messages if child actors can be killed because of a constrain" :-)
Arjen Smits
@Danthar
Apr 01 2016 09:33
ah
Ralf
@Ralf1108
Apr 01 2016 09:33
because the "pageVersionGuid" represents the identity of a page actor
i have millions of pages and one actor per page
normally i would provide the guid via ctor.. but this currently not work with dependey injection paramters
Arjen Smits
@Danthar
Apr 01 2016 09:34
why not include the pageVersionGuid in the name of the actor then ?
Ralf
@Ralf1108
Apr 01 2016 09:34
it is included in the name... but it seems nasty to parse the name and get this guid :D
but i got this. dont allow the page actor to restart... do everything via the manager actor. this should be ok
second topic was how to not loose work messages if child actors could be killed to save memory?
Arjen Smits
@Danthar
Apr 01 2016 09:36
Thats where a passivation pattern comes in handy
Ralf
@Ralf1108
Apr 01 2016 09:37
I'll google it
Arjen Smits
@Danthar
Apr 01 2016 09:37
A child actor can use the ReceiveTimeout method to monitor its own activity, and send a passivate message to its parent once it detects its been idle for x amount of time. Once the parent receives the passivate message it would stop routing messages to the child, buffering them instead. And stop the actor. Once actor termination is confirmed, it would check if there are any new messages for that actor, if so recreate the actor and flush messages from its buffer to it.
^^^^ thats the gist of it
reasons for child actor termination can vary ofcourse
Ralf
@Ralf1108
Apr 01 2016 09:38
yes thx. that I was thinking of :-)
very interesting new world with actors :-)
Ralf
@Ralf1108
Apr 01 2016 11:39
if I call Terminate() on an actor system will this send a "poison pill" to every running actor?
Marc Piechura
@marcpiechura
Apr 01 2016 11:54
@Ralf1108 it stops the root guardian which then stops it's children and so on
afaik Stop sends a Terminate message to the actor
Kris Schepers
@schepersk
Apr 01 2016 12:27
@Horusiath Got things working with the sqlite persistence plugin. There seems to be a problem with the current nuget package for Akka.Cluster.Sharding. Had to take the latest version of de DEV branch, compile it myself and reference that to my project in order to get it to work. It failed on recovering from the journal/snapshot with an ObjectReferenceNullException in PersistentShard.ReceiveRecover for an EntityStarted event.
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 12:54
@schepersk have you setup snapshot store the same way as journal? Also are you using Wire as default serializer?
Kris Schepers
@schepersk
Apr 01 2016 12:56
Not not using Wire for serializer, default. I've taken the configuration for journal and snapshot from the example you pointed to in de repo.
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 12:57
the example uses it by default
Kris Schepers
@schepersk
Apr 01 2016 12:58
Wire yes, but I was referring to the persistence configuration
Roy van Kaathoven
@Rovak
Apr 01 2016 13:19
is there an akka.net equivelant for passing an actor instance to props, like in scala?
val actorInstance = new MyActor()
val props = Props(actorInstance )
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 13:20
@Rovak you can pass expression Props.Create(() => new MyActor())
Roy van Kaathoven
@Rovak
Apr 01 2016 13:29
@Horusiath thanks, but i wanna work with existing instances which i need to pass to Props. The following example doesn't seem to work because the expression i pass is different from the one that Props is expecting
var actorInstance = new MyActor(arg1, arg2, arg3)
var props = Props.Create(() => actorInstance);
I know it isn't best practise and even considered bad, but i'm trying to upgrade an existing framework to start using Akka, and right now the instances are being created in different factories
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 13:33
AFAIK in akka on the JVM you also cannot construct actors directly - taken from akka source code:
throw ActorInitializationException(
        s"You cannot create an instance of [${getClass.getName}] explicitly using the constructor (new). " +
          "You have to use one of the 'actorOf' factory methods to create a new actor. See the documentation.")
Roy van Kaathoven
@Rovak
Apr 01 2016 13:41

In play framework i use the following code snippet to construct child actors in the ActorExample class

class ActorExample @Inject(injector: Injector)  extends Actor (

def buildInstance(action: ActionConfig) = {
    context.actorOf(Props(injector.instanceOfWithParams(action.instance)(action)))
  }

}

injector.instanceOfWithParams uses Guice to create an Actor instance, which i then pass to Props.

actionconfig
trait ActionConfig {
      var id = 0
      var name = ""
      def instance: Class[_]
    }
so it just creates a new instance based on the given Type/Class and then passes the ActionConfig to its constructor

Something similiar doesn't seem to work in Akka.net

    [TestFixture]
    class ServerActorTest
{
        public ServerActor CreateInstance()
        {
            return new ServerActor();
        }

        [Test]
        public async Task TestServer2()
        {
            var system = ActorSystem.Create("MySystem");

            var serverActor = system.ActorOf(Props.Create(() => CreateInstance()));
        }
}

which throws

System.InvalidCastException : Could not convert object of type System.Linq.Expressions.InstanceMethodCallExpressionN to System.Linq.Expressions.NewExpression.
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 13:45
Props.Create expects expression to be passed, because what it does underneat is desconstructing it into prime elements (namely actor type and list of arguments passed to it's constructor)
Roy van Kaathoven
@Rovak
Apr 01 2016 13:47
yea i understand that, i just wanna know if i'm missing a method which accepts an instance, or i need to create a PR which allows instances to be passed to Props
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 13:48
it's not allowed, and probably won't be - props needs to be serializable/deserializable
Roy van Kaathoven
@Rovak
Apr 01 2016 13:50
only when transfered over the wire when using Akka.Remote afaik?
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 13:55
always when it can be part of the message, introducing it would expose whole new category of runtime errors, without actual reason
btw. what signature does injector.instanceOfWithParams has?
Roy van Kaathoven
@Rovak
Apr 01 2016 14:00
 def instanceOfWithParams(clazz: Class[_])(parms: Object*)
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 14:00
and returned type?
Roy van Kaathoven
@Rovak
Apr 01 2016 14:01
Actor
Alex Achinfiev
@aachinfiev
Apr 01 2016 14:34
Hi folks. I have a question about dynamic system creation with different configuration. I need to be able to provide some dynamic configuration and currently we are just spawning multiple systems within the same topshelf startup based on list of roles we want in config file. Can one actor system actually spawn other systems so you could send a message and make this more dynamic? Thanks
ilhadad
@ilhadad
Apr 01 2016 16:21
Is it possible to add different actor types to a sharded region?
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 16:40
@Rovak maybe I should ask this at the beggining - if you're injecting actors to be created, why don't you use akka dependency injection plugins?
Onam
@OnamChilwan
Apr 01 2016 16:41
I am using Akka TestKit but I have an actor which creates a child actor and sends it a message. The trouble is when unit testing I only want to test the parent actor in isolation however when I run the test it also invokes the child actor. Is there a way to prevent this? Seems I can add the child actor as a dependency and I can substitute this with a BlackholeActor from a unit test
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 16:41
@ilhadad you can create multiple sharded regions in each actor system, one per type name
@OnamChilwan TestKit is more integration-like test type than unit-tests, usually actors perform some business action in cooperation, so to test it, you need to make sure, that whole topology of actors is working fine
Roy van Kaathoven
@Rovak
Apr 01 2016 16:44
@Horusiath the framework uses multiple Ninject containers, and afaik the ActorSystem can only have 1 DI container
Onam
@OnamChilwan
Apr 01 2016 16:47
@Horusiath ah right so for unit testing actors simply don't use TestKit?
Stick to basic unit testing and assert agianst behavior as opposed to asserting messages have been published etc as this will be covered from integration tests via Testkit
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 16:54
@OnamChilwan I would faster forget about unit testing, than testkit specs ;) This image well describes sense of testing components working together in isolation:
@Rovak don't get me wrong, I really don't want to offend anybody here, but don't all those issues point to some complexity problems on your company app side?
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 17:00
@aachinfiev you could have one centralized config provider service (i.e. zookeeper, consul) that you could ask for configuration before starting an actor system
then simply retrieve actual config for current service from it
Roy van Kaathoven
@Rovak
Apr 01 2016 17:02
@Horusiath no offence taken, the app is indeed pretty complex, its an enterprise service bus. The app may load multiple projects and these projects should never be allowed to share instances like repositories, database connections, services etc. so each project has their own ninject container. Right now some services which do work in different threads have locks which i want to replace with actors and message passing
there are a LOT of services, and i can't rewrite everything at once. So i want to create a migration path which may not look pretty in the beginning, but i can then slowly refactor everything to akka actors
Zetanova
@Zetanova
Apr 01 2016 17:06
@Horusiath I am still at actor pattern, my current problem is that before i had the same state-model-type for the AR-state and for the read-model. Now i am changing that the AR is using his own State-type. The problem is that the Sender of the create-command shouled be informed with the newly created read-model. I have the idea, to pass a non-persitent event to the EventBus so that the ReadModelProjector can tell the Sender of the create command the entity
But it seams wrong
Roy van Kaathoven
@Rovak
Apr 01 2016 17:07
I tried a different approach where the factories now build Props instances instead, which seems to work fine.
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 17:08
@Rovak this or returning Expr<ActorBase> could work
@Zetanova the view side of persistence plugin is lacking some features. That's why it was obsoleted on the jvm side in favor of persistence queries (which we will probably done too, once streams and persistence query will be ported). Btw. this idea with using third mediator seems neat to overcome current limitations.
Zetanova
@Zetanova
Apr 01 2016 17:15
@Horusiath readmodel generation is working good, the batching is easy and working well. The buffer of events will be flushed on MaxEventCount and Timeout in a single actor for each AR-type. The events are then grouped by Id and each group is processed by the normal Read-Modify-Update CRUD pattern.
triggered by a special event, I could send the readed read-model back to a requestor,
The other option would be the normal one that the client is generating the read-model internaly on client-side and sends only the create-command, without getting the model back.
but then there is a lag, where one client-component has the read-model and maybe an other need it to be created on the read-side (some query)
Zetanova
@Zetanova
Apr 01 2016 17:22
It happens in the UI, after create of some entity the user is moved to the entity-list that need to be refreshed. Of course the possibilty is to inject the client-side created entity into the list, but the "server"-side sorting and paging will be broken
Chris Martin
@trbngr
Apr 01 2016 17:23
hello, strangers!
Onam
@OnamChilwan
Apr 01 2016 17:37
@Horusiath is it fair to say then it isn't possible to truly unit test an actor in isolation?
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 17:42
@OnamChilwan you could do so, ie. by passing children Props through actor's constructor (this is done in few cases) or as part of some message to be send at some point in time. But if those are making a solution too complex, then it's a warning, that maybe a hierarchy of actors should be changed or maybe they are so tightly coupled, that they should be tested as one.
Onam
@OnamChilwan
Apr 01 2016 18:18
Yeah I was thinking that was one option however whilst I was doing this it felt wrong. Thanks for the info, it just seemed from the articles I've read seems a little misleading when they say unit testing
to11mtm
@to11mtm
Apr 01 2016 18:35
I have a question regarding scheduling; If An actor is created, and hangs such that it never returns, will it 'lock' the thread on the thread-pool such that another thing cannot consume it?
Arjen Smits
@Danthar
Apr 01 2016 18:36
@to11mtm you mean if it hangs while processing a message ?
If you block a receive handler. Then it will 'block' a thread on the threadpool. (if it will actually block/lock the thread that was running at that time, depends on your code ofcourse, if your doing async await things, it might not)
to11mtm
@to11mtm
Apr 01 2016 18:41
@Danthar : public SampleDatabaseQueryActor()
{
Receive<IQueryParameters>(param => PerformQuery(param)); // If PerformQuery somehow has an internal deadlock.
}
Arjen Smits
@Danthar
Apr 01 2016 18:42
ah yep that would do it
but if your doing a query, and it deadlocks, wont your dbdriver throw an exception of some kind ?
either way, there is no magic code in the Akka.Net dispatchers that prevents these kind of problems. It needs to adhere to the normal set of rules regarding the TPL like anything else.
Akka.net makes concurrency easier to implement, and prevents alot of the pitfalls that come with the territory. But its not perfect ;) (nothing is)
Christian Duhard
@cduhard
Apr 01 2016 18:46
hmm is there a straight forward way to know when all watched children are stopped?
This feels kinda ugly while (Context.GetChildren().Any(x => x.GetType() == typeof (Account)))
to11mtm
@to11mtm
Apr 01 2016 18:48
Truth!
Is there a good way to 'monitor' for a deadlock in cases like this? Perhaps configuring the dispatcher's deadlines
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 19:45
@cduhard Context.Watch?
Christian Duhard
@cduhard
Apr 01 2016 19:46
they are watched
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 19:47
you can create counter to increment once child of specific type is created, and decrement it on Terminated
Christian Duhard
@cduhard
Apr 01 2016 19:48
yeah, that's an option. what I would like to do is implement sagas like you did in your latest Cqrs app
then I wouldn't have this complex graceful shutdown problem
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 19:49
"someday" I will find time to finish it
Christian Duhard
@cduhard
Apr 01 2016 19:50
thats what's making this harder than it should be. i have to wait for sagas to playout inside my aggregates
i have to cut off incoming messages and lets everything passivate, it shouldn't be hard but it is tricky to keep it simple and foolproof
Christian Duhard
@cduhard
Apr 01 2016 19:55
@Horusiath "someday" soon I hope
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 19:56
there is a huge load of stuff to finish, but I hardly have any time to work on akka from over a month
Christian Duhard
@cduhard
Apr 01 2016 20:01
job getting in the way?
Bartosz Sypytkowski
@Horusiath
Apr 01 2016 20:02
yes. Well, at least it's interesting