These are chat archives for petabridge/akka-bootcamp

8th
May 2015
Alexander Lapikov
@lapikov
May 08 2015 10:48
Several notes reg. naming of methods in Akka.Net while playing with units 2-4 and 2-5:
  1. As for For Become/BecomeStacked/UnbecomeStacked: IMO it is worth using different base term (behavior) and those methods would be named ReplaceBehavior, PushBehavior, PopBehavior.
  2. As for Stash/Unstash/UnstashAll the same push/pop could be used as an action and message as an object: PushMessage/PopMessage/PopAllMessages. Adding an object to a method makes its purpose more clear.
    I guess you guys intentionally keep all names inherited from Java-based Akka framework so this could be addressed by that team.
Alexander Lapikov
@lapikov
May 08 2015 12:46
blob
(an exception in ChartingActor.cs after clicking "x" button to close the app: the error is sporadical one)
Looks like Charting.Series.Points has been already invalidated since the chart object is about to be destroyed.
Bartosz Sypytkowski
@Horusiath
May 08 2015 12:56
what is the null? series or series.Points?
Alexander Lapikov
@lapikov
May 08 2015 12:56
@Horusiath, series.Points.
Bartosz Sypytkowski
@Horusiath
May 08 2015 12:56
it looks like you have some kind of shared memory which is potentially accessed by multiple actors in the same time
jhorv
@jhorv
May 08 2015 12:57
Question on lesson 1.6 - Actor Lifecycle - you refactor to use PreStart() and PostStop(). In PostStop() you call base.PostStop(), but in PreStart() you don't call the base implementation of that... since base.PostStop() is called explicitly does that mean it's required?
Gerjan
@GerjanOnline
May 08 2015 12:57
yes i had the same issue @lapikov
jhorv
@jhorv
May 08 2015 12:59
I guess I could check the source, but I'm wondering if there is a general recommendation while using Akka.net
Bartosz Sypytkowski
@Horusiath
May 08 2015 12:59
@jphorvath yes, it's required - it could do few things, which are rather important
i.e. stopping child actors of stopping actor
jhorv
@jhorv
May 08 2015 13:02
@Horusiath ah, of course. are there any recommendations on when to call the base method? besides "when you need to" :smile:
Bartosz Sypytkowski
@Horusiath
May 08 2015 13:04
I'm calling them always, number of possible rules and combinations when to use them won't make much sense
Alexander Lapikov
@lapikov
May 08 2015 13:22
blob
Unit 3-1 -- one more issue occurred when UI form is closed:
Looks like there should be some pattern to stop all related actors when UI form is closed (I believe form "Close" event and "UI actor"'s events are executed within the same thread, is it correct)?
jhorv
@jhorv
May 08 2015 13:25
@Horusiath okay, thanks!
Aaron Stannard
@Aaronontheweb
May 08 2015 14:56
@lapikov as for that intermittent error, it happens when the Form itself is disposing all of its UI assets but the actor is still receiving updates. I can't recall if I added an ActorSystem.Shutdown call anywhere on the Form_Closing handler. That would solve that problem.
(didn't occur to me until just now that could happen :p )
Aaron Stannard
@Aaronontheweb
May 08 2015 15:01
or instead of shutting the actorsystem down we could send a PoisonPill to the _chartingActor
looks like we aren't doing either at the moment
Thomas Tomanek
@thomastomanek
May 08 2015 15:03
Not sure if you guys are planning on additions to the bootcamp, but if you are a unit testing/testing best practices would go down very nicely
Alexander Lapikov
@lapikov
May 08 2015 16:22
@Aaronontheweb, thanks. Sending a PoisonPill looks reasonable at least for _chartingActor and probably for Unit 3 as well.
jhorv
@jhorv
May 08 2015 16:26
In lesson 2.4 (maybe others) the link to submit an issue is broken.
Sorry nevermind, found the right place to submit issues manually. I'll also report the broken link.
stevemesser
@stevemesser
May 08 2015 17:12
In Unit 2. I moved ActorSystem ChartActors from program.cs to main.cs and called shutdown during form closing and the exception went away for me.
Aaron Stannard
@Aaronontheweb
May 08 2015 17:25
@sadprofessor we will do some content showing how to use Akka.TestKit at some point - that's becoming a very popular demand
might not be part of bootcamp - we might do that as a series of videos on our youtube channel, blog posts, or maybe a virtual training. Probably some combination of all of them!
@stevemesser yep, that sounds about right - race condition between the forms disposal and the actor
need to kill the actor somehow before the disposal starts
shutting the actorsystem down works, or stopping the charting actor
both should accomplish the same result
glad to see that attendees are the ones figuring this out - makes me feel like we did our job :p
stevemesser
@stevemesser
May 08 2015 17:29
Hopefully, we are learning ;) There is lots to learn for sure!
I may have more questions after the BootCamp than I did before :)
Thomas Lazar
@thomaslazar
May 08 2015 17:31
i have another question. if i ask the actorsystem for an actor with ActorOf, does it get created and is now lying around somewhere until it dies of exceptional reasons or i kill it with a pill?
i'm thinking about an actor that's kindof a singleton that has a state that other actors can query and that can update it's internal state through messages
Bartosz Sypytkowski
@Horusiath
May 08 2015 17:41
@thomaslazar When actor is created, it will reside in memory until explicitly killed/stopped, or it's parent will do the same or actor system is shutdown
Thomas Lazar
@thomaslazar
May 08 2015 17:43
ok. good to know. and it basically gets created through a ActorOf call?
Bartosz Sypytkowski
@Horusiath
May 08 2015 17:44
if you want to have actor which should be GCed, you may use Context.SetReceiveTimeout(timeout) - this method will send a ReceiveTimeout message to actor itself, if it haven't received any message for timeout time - then all what's needed is handling this message i.e. by stopping an actor
if I'm correct actor is not instantiated until first message for it arrives
Thomas Lazar
@thomaslazar
May 08 2015 17:47
well… my idea is to have an actor that loads it's state from DB (gets a message to do so) and has a few basic message handlers that persist changes back to the DB but it's main reason for this actor is to send this information to other actors asking for it.
so it would get created at program start and load it's initial state and then just has to live there till the system gets killed
Bartosz Sypytkowski
@Horusiath
May 08 2015 17:49
I guess you've decided that Akka.Persistence is not your use case, so you may for example create an actor and immediately after send some kind of Populate message to it
Thomas Lazar
@thomaslazar
May 08 2015 17:52
that's what i thought. i ahve to admit that i didn't take a closer loot at Akka.Persistence yet. but mainly for the reason that when i skimmed over the 1.0.1 release notes there was something about only being a SQL Server version
Bartosz Sypytkowski
@Horusiath
May 08 2015 17:53
persistence provider is plugable
Thomas Lazar
@thomaslazar
May 08 2015 17:53
and i need to at least support oracle as well… and maybe DB2 shudder
Bartosz Sypytkowski
@Horusiath
May 08 2015 17:54
hopefully today I'll send a PR which contains a common layer for all SQL-based persistence backends
then almost all you need to do is to define ADO.NET Command SQL string builders and some initialization script for required database tables
(unless I totally missed something :D )
Thomas Lazar
@thomaslazar
May 08 2015 17:57
ok. well maybe Akka.Persistence will be talked about for a bit during that design pattern training course
Aaron Stannard
@Aaronontheweb
May 08 2015 18:18
@thomaslazar so far I've seen a SQL Server, local filesystem, Postgres, and an EventStore plugin for Akka.Persistence
and DataStax's .NET evangelist said he was working on a Cassandra one, which I would personally like to use :p
Thomas Lazar
@thomaslazar
May 08 2015 18:19
well… i currently have a system that uses nhibernate as orm layer. and i want to use akka.net in that system where appropriate.
problem is… i have to be compatible with a delphi legacy app going to the same database… is a lot of pain.
Aaron Stannard
@Aaronontheweb
May 08 2015 18:21
Akka.Persistence may not be the right solution in that case, because it has a bias about how information and events get stored. It uses event sourcing and journaling, because that's what most closely models the internal state of an actor over a period of time
so the other option you always have is just writing some application-layer code inside your Akka.NET apps
and you can use the DI support to inject connections into your actors for talking directly to that database the same say you would an ASP.NET application
this is what I did in my production apps before Akka.Persistence was ported
Thomas Lazar
@thomaslazar
May 08 2015 18:22
yeah… that's what i plan to do
currently trying to figure out Windsor DI Akka foo
Aaron Stannard
@Aaronontheweb
May 08 2015 18:23
let me know if you have any questions on how to do that most effectively - the one issue I ran into doing that is when the lifecycle of my actors didn't reflect the lifecycle of the CassandraContext
i.e. the actor would outlive the context it needed to write to Cassandra
so I changed it so those actors would live forever, but they would grab a new CassandraContext each time they needed to flush a batch to the database
the other approach would be to create a new actor for each cassandra batch
the overhead of creating the new actor is trivially small
but those are the types of problems you'll want to consider when you model it
I ultimately chose to keep a permanent group of actors for doing those writes because the number of concurrent write operations needed to be bounded
otherwise my CPU utilization would have gone nuts - better to limit the parallelization factor to some manageable number
and doing that actually kept my throughput pretty high
Thomas Lazar
@thomaslazar
May 08 2015 18:26
well i plan to inject the sessionfactory into actors and have them get their db sessions from there. nhibernates sessionfactory is thread safe
Aaron Stannard
@Aaronontheweb
May 08 2015 18:26
@thomaslazar that sounds exactly right to me
:thumbsup:
stevemesser
@stevemesser
May 08 2015 18:27
I am not understanding the relationship in Akka.net of threads vs Actors.
Aaron Stannard
@Aaronontheweb
May 08 2015 18:27
@stevemesser this is one of my favorites ;)
so imagine this - you can have a million actors sharing 100 threads
Thomas Lazar
@thomaslazar
May 08 2015 18:27
yeah… just needs consideration on actors part as what to do and such. will probably have to make a set of actors that do DB foo and probably cache it in some way as to not bombard the DB with tons of connections
Aaron Stannard
@Aaronontheweb
May 08 2015 18:28
and the way that works is pretty interesting
actors only run when they have messages in their mailbox to process
otherwise they're totally idle
so when a message arrives in a mailbox for an idle actor, the calling thread (i.e. the thread that made the Tell request to that actor)
will force the mailbox to start a little loop where it pushes at least N messages (this is the dispatcher-throughput setting that you can configure)
if there are that many available into the actor before going idle
so what really happens under the hood is that the mailbox schedules an Action onto a MessageDispatcher
you can think of a MessageDispatcher as an abstraction that wraps the ThreadPool
that Action executes the loop and pushes messages into your actor's OnReceive method
and so the thread executing that action is the same thread that runs your user-defined actor code
when the actor is done processing messages, or when the loop hits its maximum number of messages, that thread gets released
and another actor can start using it
if there are most messages in the actor's mailbox at the end of its run, it'll schedule ANOTHER loop to execute in the future
effectively the actors are able to share thread-time with eachother concurrently
Thomas Lazar
@thomaslazar
May 08 2015 18:33
should make a video about that. like the remoting one (i still have to watch)
Aaron Stannard
@Aaronontheweb
May 08 2015 18:33
yeah, I was just thinking that exactly as I wrote this out lol
I wanted to do one anyway to talk about the ActorCell and how actor restarts actually work
this is part of that same piece of plumbing
Thomas Lazar
@thomaslazar
May 08 2015 18:34
as arnold would say: do eet! do eet nao!
;)
stevemesser
@stevemesser
May 08 2015 18:36
Sounds similar to how CCR works. How do you limit the number of threads AKKA uses?
Aaron Stannard
@Aaronontheweb
May 08 2015 18:36
here's the video @thomaslazar mentioned: https://www.youtube.com/watch?v=6c1gVLyYcMM
@stevemesser so the default MessageDispatcher wraps the built-in CLR ThreadPool, and the threadcount there is managed totally by the CLR
however, we have other types of MessageDispatchers like the ForkJoinDispatcher which use their own threads separate from the ThreadPool
and you can configure the number of threads via HOCON for them
the ForkJoinDispatcher gets used in areas where you have soft real-time requirements. The entire heartbeat system for Akka.Remote and Akka.Cluster rely on them, for instance
stevemesser
@stevemesser
May 08 2015 18:40
Okay, currently I run on a 16 core machine and CCR at startup will get the number of cores and not create more threads than there are cores.
Aaron Stannard
@Aaronontheweb
May 08 2015 18:41
you know, I'm not familiar at all with the CCR
stevemesser
@stevemesser
May 08 2015 18:41
Yeah, its just as a point of reference.
Aaron Stannard
@Aaronontheweb
May 08 2015 18:41
I was just realizing that out loud is all
that's part of Microsoft Robotics right? https://msdn.microsoft.com/en-us/library/bb648752.aspx
stevemesser
@stevemesser
May 08 2015 18:42
Correct
Aaron Stannard
@Aaronontheweb
May 08 2015 18:43
so are you using Akka.NET to build robots? :smile:
stevemesser
@stevemesser
May 08 2015 18:43
Seems from what you are saying unless you tell AKKA otherwise it will create unlimited number of threads if given enough work to do....
Aaron Stannard
@Aaronontheweb
May 08 2015 18:44
Akka.NET won't create an unlimited number of threads - the CLR threadpool will make a determination based on the availability of your hardware
stevemesser
@stevemesser
May 08 2015 18:44
No, my predecessor chose that framework for the concurrency model.
Aaron Stannard
@Aaronontheweb
May 08 2015 18:44
ah
stevemesser
@stevemesser
May 08 2015 18:44
I am a medical rules engine.
Aaron Stannard
@Aaronontheweb
May 08 2015 18:44
Akka.NET robots would be pretty cool
that's cool too!
stevemesser
@stevemesser
May 08 2015 18:45
Yeah, if they could learn to code for me!
Aaron Stannard
@Aaronontheweb
May 08 2015 18:45
the CLR ThreadPool will make a decision about the optimal number of threads per process
it'll check to see if you have hyper-threading enabled, how many cores you have, and so forth
but the number of threads it allocates is usually some scalar value greater than 1 per core
stevemesser
@stevemesser
May 08 2015 18:46
Cool, CCR is where .net got its task and related plumbing for TPL
from
Then they killed it ;)
I am just trying to figure out how to push my current architecture into the AKKA framework...
Aaron Stannard
@Aaronontheweb
May 08 2015 18:49
doh!
stevemesser
@stevemesser
May 08 2015 18:50
At some point after bootcamp I would like to throw a high level system concept at someone for critique.
Aaron Stannard
@Aaronontheweb
May 08 2015 18:50
(warning! Asking for money!) you should check out the training we're doing next week on Akka Architecture and Design patterns - https://petabridge.com/training/akka-design-patterns/
that would be a good forum to get some answers specific to your needs
Thomas Lazar
@thomaslazar
May 08 2015 18:52
apropos training. how's that working anyways? what kind of software do you use to present that stuff? i don't guess we'll all hang out in a google hangout or stuff ;)
stevemesser
@stevemesser
May 08 2015 18:52
Not sure I could get something approved that quickly
Thomas Lazar
@thomaslazar
May 08 2015 18:52
just go to your boss, ask him for his creditcard and use it on the site… that's how i did it :P
Aaron Stannard
@Aaronontheweb
May 08 2015 18:53
@thomaslazar I'll be the one presenting - we're going to email out the details on Tuesday next week a couple of days before the training. We have some live webinar software that we're going to try out :p - GetScreencast or something
I'll have a slack channel open for all of the participants
and I'll be presenting some stuff in PowerPoint and then pausing to do some design exercises
where we'll actually interact and model a problem using some of the architecture / design patterns we just talked about
Thomas Lazar
@thomaslazar
May 08 2015 18:54
ok. am looking forward to it… even if it's starting at 6pm for me on a national holiday. but i convinced my boss that i get the following day off
stevemesser
@stevemesser
May 08 2015 18:54
Too many layers of red tape here for a direct approach like that. Has to come out of someones budget.
I can ask.
Thomas Lazar
@thomaslazar
May 08 2015 18:55
there has to be an advantage for being in a small company
Aaron Stannard
@Aaronontheweb
May 08 2015 18:55
@stevemesser haha, I worked at Microsoft. I feel your pain. Ask your boss and then send me an email at aaron@petabridge.com and let me know if he or she has any objections
and I'll see what I can do to help give you some information to sell them on the ROI of doing it, because we're going to cover some stuff that REALLY helped me when I was working on MarkedUp
Bartosz Sypytkowski
@Horusiath
May 08 2015 18:57
yeah, when I worked at Samsung, we have the same problem - whole team wanted to get sponsored business trip to http://www.codeonthesea.com/ . We were rejected :(
I think, images on the site didn't convince our management
Aaron Stannard
@Aaronontheweb
May 08 2015 18:58
yeah that literally does look like nerd spring break
lol
that's the trick to selling conference seats - make it seem very enterprisey
and maybe a little fun
Bartosz Sypytkowski
@Horusiath
May 08 2015 19:02
I think, that water slide was enterprisey as f**k
Aaron Stannard
@Aaronontheweb
May 08 2015 19:02
hahahaha
stevemesser
@stevemesser
May 08 2015 19:15
Well got shot down. We have to hold a meeting with several architects blah blah blah. I will have to wait.
It has to be there idea to use a new framework ;)
Gary Ewan Park
@gep13
May 08 2015 19:31
@Aaronontheweb how much is that architecture training that you linked to? On a very quick look, I couldn't see a price. Thanks!
Thomas Lazar
@thomaslazar
May 08 2015 19:32
it's a little bit shy of 500$ iirc
Gary Ewan Park
@gep13
May 08 2015 19:39
Hmm, I will have to see if I can get work to swing that. I am only on lesson 1.3, so maybe a little bit early for this higher level learning. @Aaronontheweb are these going to be regular training sessions? Are they recorded to purchase after the fact? Thanks!