These are chat archives for akkadotnet/akka.net

20th
Aug 2015
Aaron Stannard
@Aaronontheweb
Aug 20 2015 00:40
looks like all of those updated Akka.Remote and Cluster docs are starting to pay off: http://stackoverflow.com/questions/32094660/how-to-detect-remote-actor-disconnection-dissociation#comment52104082_32094660
able to use the new docs to answer their own question
Mike Johnson
@softwaremike
Aug 20 2015 02:59

@bruinbrown (or anyone else who can answer): Related to a question about spray and the ability to hook up a REST interface to an actor system (e.g. so we could provide a way to query some property stored within some actor), you said the following:

Akka-Http is an existing Akka project by the developers of Spray and Tyrpesafe designed to make a HTTP API interface which works directly with actors themselves http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0-M2/scala/http/. If you're not wanting to wait for the release of Aka.Http then it's possible to use any of the existing HTTP API libraries (ASP.Net WebAPI, Nancy, WCF etc) and there's a couple of options on getting your API endpoints connected to your actor system

Can someone elaborate on the currently available "options of getting your API endpoints connected to your actor system"? I'm loving the possibilities with akka.net, just not sure how to "get data out of" it. For example, let's say I'm building an actor system that does something like keep a multiplayer game's player attributes up to date. Then I'm building a web site where I can show current stats on a set of users. I'm thinking the website needs to somehow "look into" the actor system to grab some set of stats from one or more actors. (So it's basically making queries against the actor system from outside the actor system itself.) Are there any examples/patterns to do something like this?
Wolfgang Loder
@kujua
Aug 20 2015 05:51
@softwaremike I use an actor in the API implementation to communicate with the actor system.
In your case there is either the option to push messages with the player attributes to the actor in the API or the API actor asks the actor system for the data.
The latter would use async communication (Tell), or have an Ask with async/await in a thread.
Communication to the client can be done via web sockets (SignalR or similar) to push data to the web client and update when data is available. The Web Crawler example is using this approach: Samples.
tstojecki
@tstojecki
Aug 20 2015 07:19
@Horusiath et all, are there any java/c# samples out there for you work with persistent actors? i have read through the http://getakka.net/docs/Persistence docs, but i am still pretty consufed about how to work with this api... for example, do i need to handle Receive, ReceiveCommand, ReceiveRecovery, etc...
i would like to start with something simple that can persist a few events and rebuild its state on failure
Bartosz Sypytkowski
@Horusiath
Aug 20 2015 07:20
@tstojecki there is no Receive in persistent actors, you have ReceiveCommand instead. ReceiveRecovery is used only, when persistent actors has been resurrected and is trying to recover from the set of events it persisted before
you can look at my example, I'll finish it some day probably :P
I want to change some of the patterns presented, but some basic concepts are already there
tstojecki
@tstojecki
Aug 20 2015 07:22
so this.Receive appears to be available on PersistentActor, but you're saying i should leave it alone
and handle ReceiveCommand instead
i am looking at the example too
tstojecki
@tstojecki
Aug 20 2015 08:46
@Horusiath really nice job with the sample, my head is spinning a little bit, but i think i am getting the gist of it
once i get to a good stopping point i would like to help with docs for this, i think using code snippets from the sample might serve us better the the current persistent docs
Anthony Brown
@bruinbrown
Aug 20 2015 09:48
@softwaremike you can hook up Akka.Net to any of the existing Web frameworks, essentially all you need to do is look up an actor in your actor system typically by doing something like system.ActorSelection("/user/MyActorA/MyActorB") and then once you've got that reference you can easily send data into the system by just using Tell on that address to pass it a message, if you want to then get data out, you can use Ask, which async sends a message and awaits a response from the target (it's up to the target to remember to send back a response, there's no RPC in Akka.Net). Alternatively you can use SignalR and push data down to the clients (this fits in more with the reactive nature of Akka.Net).
Anthony Brown
@bruinbrown
Aug 20 2015 09:54
@softwaremike Here's a simple example of how using ASP.Net Web API 2, you can get data out of the actor system https://gist.github.com/bruinbrown/14a8fc8cfa30ef667135
Suhas Chatekar
@schatekar
Aug 20 2015 09:57
@bruinbrown on SignalR, how well does it scale in a true web scenario if you have got thousands of concurrent users using your webiste?
Roger Johansson
@rogeralsing
Aug 20 2015 10:28
nugot.png
boom!
Suhas Chatekar
@schatekar
Aug 20 2015 10:33
Is this a real website?
Graeme Bradbury
@GraemeBradbury
Aug 20 2015 10:36
Appears to be (google finds it) Now if only they could fix the api rather than just the website
Anthony Brown
@bruinbrown
Aug 20 2015 10:41
@schatekar I've only had experience up to a couple of thousand connections at once but that was on relatively low end VMs, you've then got either signalr backplanes for scale out or multiple servers with consistent hashing if you need really low latency
Roger Johansson
@rogeralsing
Aug 20 2015 10:44
Nugot.net (With an o)
Mike Johnson
@softwaremike
Aug 20 2015 11:19
@bruinbrown and @kujua : Thanks!! Yep, looks like "Ask" is the miracle method I was missing :) Now off to go start prototyping... the potential here is very exciting!
Tomas Vana
@creepone
Aug 20 2015 12:58
@Aaronontheweb Today I upgraded to 1.0.4 and the DI was behaving very strangely, sometimes failing to resolve dependencies. I tracked it down to your akkadotnet/akka.net@5fd1c04 and wanted to ask: what was the motivation to use the Ninject activation blocks ?
Anthony Brown
@bruinbrown
Aug 20 2015 13:47
Anybody got any tips on debugging MultiNodeTests? I've got the child process debugging power tools but it doesn't seem to attach the debugger on child processes. Any tips on running them as well? I've tried launching the multinode test runner with my tests assembly and calling start external program from the tests project
Suhas Chatekar
@schatekar
Aug 20 2015 14:00
Same problem here. Could help if you raise an issue with the steps your are following. I wanted to do that but could not till weekend now. stuck in a place without access to my development box
Graeme Bradbury
@GraemeBradbury
Aug 20 2015 14:12
I've not managed to get a break point to hit yet. (using Start external program) Basically limited myself to running individual dlls and reading the output.
Suhas Chatekar
@schatekar
Aug 20 2015 14:24
@GraemeBradbury that is still a lot of output to read, isn't it?
Graeme Bradbury
@GraemeBradbury
Aug 20 2015 14:27
@schatekar oh yes, even more when you turn on verbose mode :-)
Suhas Chatekar
@schatekar
Aug 20 2015 14:27
with the 7 PRs you submitted, was that 7 times the usual reading of logs? ;)
Graeme Bradbury
@GraemeBradbury
Aug 20 2015 14:32
I've only done 3 pr's for tests :-)
Christian Palmstierna
@cpx86
Aug 20 2015 15:02
@GraemeBradbury One option is to drop a Debugger.Break() where you want the breakpoint. Will force attachment of debugger.
Suhas Chatekar
@schatekar
Aug 20 2015 15:40
@cpx Is that not what VS does internally when you set a breakpoint?
Aaron Stannard
@Aaronontheweb
Aug 20 2015 15:54
@creepone we decided on a standard set of expectations for how DI is supposed to behave in Akka.NET, since it was chaotic and unpredictable from one framework to the next
@stefansedich is publishing a list of all of the settings you should have on your containers for working with actors, but the TL;DR; of it is that we expect the container to manage the lifecycle of the objects
and to automatically dispose those objects on restart / termination
Ninject and others were not doing this before
leaking memory, essentially
Christian Palmstierna
@cpx86
Aug 20 2015 15:57
@schatekar No, those breakpoints are only set when VSHost executes. My guess is that the VSHost exe injects the breakpoints at runtime using internal CLR methods.
Aaron Stannard
@Aaronontheweb
Aug 20 2015 15:59
@creepone but if this is causing some unintended side effects, please file an issue!
I think @stefansedich recommended for Ninject that you bind things .InScope()
@bruinbrown > I've got the child process debugging power tools but it doesn't seem to attach the debugger on child processes. Any tips on running them as well?
there's a little trick to this that isn't very straightforward
blob
Aaron Stannard
@Aaronontheweb
Aug 20 2015 16:05
so you want to open that menu, Debug --> Other Debug Targets --> Child Process Debugging Settings
and then configure it like this
blob
make sure Enable child process debugging is checked
and add NodeTestRunner.exe as an entry, also checked, with action Attach debugger
then press Save
Suhas Chatekar
@schatekar
Aug 20 2015 16:06
@Aaronontheweb could you stick that to a gist or an issue? so that it is easy to refer to in future?
on a second thought, I could do that as well ;)
Aaron Stannard
@Aaronontheweb
Aug 20 2015 16:08
that way we could include it in the official documentation
@GraemeBradbury I'm probably going to end up incorporating #1261 into a larger PR that matches the multi-node test runner itself
going to take some work, but basically I need to get throttling to work
Graeme Bradbury
@GraemeBradbury
Aug 20 2015 16:11
@Aaronontheweb cool, if there is anything i can help with that just holler.
Aaron Stannard
@Aaronontheweb
Aug 20 2015 16:11
will do! I think I'm close to tracking the issue down
turns out there's a meta-spec for exactly this
Suhas Chatekar
@schatekar
Aug 20 2015 16:12
@Aaronontheweb raised #111 for documentation issue
that is on this repo - akkadotnet/getakka.net#111
@Aaronontheweb could you assign that to me?
Anthony Brown
@bruinbrown
Aug 20 2015 16:13
@Aaronontheweb that's exactly what I've got, I'm going to try removing the extension and reinstalling it
Aaron Stannard
@Aaronontheweb
Aug 20 2015 16:13
@schatekar done
the biggest thing we could do to improve usability with the multi-node test runner is this: akkadotnet/akka.net#1196
Aaron Stannard
@Aaronontheweb
Aug 20 2015 16:20
for #1196, we already emit a .JSON file to disk that's just a serialized version of this object https://github.com/akkadotnet/akka.net/blob/dev/src/core/Akka.MultiNodeTestRunner.Shared/Reporting/TestRunTree.cs
I'm running a multi-node test locally right now so I can add one of the output files to the issue :p
but what we'd want to do is change it such that instead of outputting just the JSON file
actually output a static webpage that renders that data into concurrent timelines for each test / node
so we can sort out what's happening, individually, across each node
that'd make it a lot easier to figure out what's going on, right?
Graeme Bradbury
@GraemeBradbury
Aug 20 2015 16:22
I had a quick look at that. Found http://visjs.org/examples/timeline/groups/groups.html so would just be a case of creating the data as visjs data structure and then spitting out into a html file.
Aaron Stannard
@Aaronontheweb
Aug 20 2015 16:22
@GraemeBradbury looks like a great fit!
can we make an adapter for TestRunTree that will render it into a VisJS structure?
btw... love that I can use the scrollwheel for that :p
Graeme Bradbury
@GraemeBradbury
Aug 20 2015 16:24
don't see why not. It's just a different json data strcuture
Aaron Stannard
@Aaronontheweb
Aug 20 2015 16:25
cool, would you mind adding that suggestion about VisJS to the issue comments?
and would one of you brave souls like to claim that issue? :p
Suhas Chatekar
@schatekar
Aug 20 2015 16:26
would d3.js be better in this situation?
Graeme Bradbury
@GraemeBradbury
Aug 20 2015 16:28
I'm on holiday next week so i'll have a look after that if no one else does it before then :-)
@schatekar I've not used either before so don't know which is best. visjs has an example that's almost exactly what we want.
ok, i'm off home to download Shadowrun:HK so I may be on during the hols but otherwise have fun everyone.
Aaron Stannard
@Aaronontheweb
Aug 20 2015 16:31
take care @GraemeBradbury!
Tomas Vana
@creepone
Aug 20 2015 17:12
@Aaronontheweb As I understand it, the problem is that the activation block forces everything to use InScope(), overriding all the original settings. That makes it impossible to reuse global services or any shared infrastructure between actors -> every dependency becomes implicitly owned by the actor (see e.g. this article).
Roger Johansson
@rogeralsing
Aug 20 2015 17:46
@GraemeBradbury I use VisJs for my cluster visualzer. love that lib!
Aaron Stannard
@Aaronontheweb
Aug 20 2015 18:12
@creepone we might have made a mistake then - could you create a Github issue for it?
we did have a lot of discussion about this on #942 and the PR for those changes was open for a couple of weeks while we worked out the details
but the standard is set now for how resources are expected to behave - we still need docs on the website explaining what those are and what the right configuration options are for each container
I'm personally of the opinion that Autofac is the only container that appears to have correct-by-default behavior - the rest of the containers are susceptible to resource leaks by default
and either users have to be trained on how to configure them appropriately, or we do what we did inside the NinjectDependencyResolver - which is try to fix it in the way dependencies are injected into actors
actors are meant to have their own private state and resources
Aaron Stannard
@Aaronontheweb
Aug 20 2015 18:17
the idea of sharing resources amongst actors is a risky idea at best
each actor can and should have its own "instance" of those resources
but the only case where sharing resources makes sense is if those resources are static or immutable
otherwise we're back to shared state concurrency with locks and the pit of doom again
this isn't me saying that "you're doing it wrong" - just trying to explain why we designed DI with the bias it has right now :p
also, regarding this > I'm personally of the opinion that Autofac is the only container that appears to have correct-by-default behavior
I say that as someone who's used Ninject for 5 years :p
Aaron Stannard
@Aaronontheweb
Aug 20 2015 18:23
all that being said, we shouldn't be breaking the behavior of your app - and your container settings should not be overriden
could you create an issue for that?
Tomas Vana
@creepone
Aug 20 2015 18:28
Sure, I'll create one ;)
Aaron Stannard
@Aaronontheweb
Aug 20 2015 18:28
thanks Tomas
sorry that change broke stuff for you :(
Suhas Chatekar
@schatekar
Aug 20 2015 18:29
@Aaronontheweb autofac is my favourite for no particular reason. May be because I trust the people who built it
@GraemeBradbury have good hols mate
Aaron Stannard
@Aaronontheweb
Aug 20 2015 18:35
@creepone and I'll make sure we document some of those DI options - @stefansedich's been wanting to do it but the poor guy is getting married, immigrating, moving, starting a new job, etc all in the next 3 months :p
needless to say, has a lot on his plate :p
Tomas Vana
@creepone
Aug 20 2015 18:41
no problem, for now I'll keep using the v1.0.3 of the Akka.DI.Ninject, luckily there are no other dependencies yet so it's not a big deal
Coinio
@Coinio
Aug 20 2015 21:18
I'm trying to create a simple game test project and have the line below to create lots of BallActors in the game. It just grind to a halt and churns away on a single core when the MaxNumberOfBalls gets big... Would it be best to use a broadcast group with previously created actors, or is there a better way to create a giant pool to broadcast world tick / update messages too?
Props ballRouterProps = Props.Create(() => new BallActor()).WithRouter(new BroadcastPool(startUniverseMessage.MaxNumberOfBalls));
jweimann
@jweimann
Aug 20 2015 22:14
does a nyone know if akka.cluster works with azure worker roles?
Aaron Stannard
@Aaronontheweb
Aug 20 2015 22:26
@Coinio on a single core, you're going to get killed by contention
if you're broadcasting messages continuously to all of those actors, each of them are going to need to dispatch on their respective threads
the greater the number of actors who need to be dispatched, the more contention there will be to get scheduled onto the CPU
you'd run into a similar issue with firing up a large number of TPL tasks
there's a point of diminishing returns, where X = number of possible concurrent operations (equal to number of cores, or 2x cores with hyperthreading)
and Y = the number of pending scheduled operations
when the Y/X ratio exceeds some value the system's throughput will begin to decrease for each increment to Y
so you can either decrease Y or increase X
how big is MaxNumberOfBalls at the moment?
Aaron Stannard
@Aaronontheweb
Aug 20 2015 22:31
@jweimann yes it does - have a version of WebCrawler that does it
haven't released the source yet though
in the meantime, here's a little preview
jweimann
@jweimann
Aug 20 2015 22:32
also probably depends what those ball actors are doing. if they're trying to do physics and update constantly it wouldn't work well to distribute them because they'd have to keep interrupting to process
but if they just took a command for input then updated their position every x seconds or whatever it should be fine. i had a similar system with 50k+ actors moving around that worked well
but they didn't do anything if the velocity didn't change
Aaron Stannard
@Aaronontheweb
Aug 20 2015 22:34
namespace WebCrawler.CrawlService
{
    public class WorkerRole : RoleEntryPoint
    {
        protected ActorSystem ClusterSystem { get; set; }

        private readonly ManualResetEvent _runCompleteEvent = new ManualResetEvent(false);

        public override void Run()
        {
            Trace.TraceInformation("Crawler is running");
            try
            {
                this.Run(this._runCompleteEvent);
            }
            finally
            {
                this._runCompleteEvent.Set();
            }
        }

        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.



            bool result = base.OnStart();

            Trace.TraceInformation("Crawler has been started");

            return result;
        }

        public override void OnStop()
        {
            Trace.TraceInformation("Crawler is stopping");

            this._runCompleteEvent.Set();

            base.OnStop();

            Trace.TraceInformation("Crawler has stopped");
        }

        private void Run(ManualResetEvent shutdownCalled)
        {
            var config = AzureRuntimeBootLoader.CreateRuntimeConfig("WebCrawler.TrackingService", "Akka.Cluster");
            ClusterSystem = ActorSystem.Create("webcrawler", config.Result);

            while (!shutdownCalled.WaitOne())
            {
                ClusterSystem.Shutdown();
                ClusterSystem.AwaitTermination(TimeSpan.FromSeconds(5));
            }
        }
    }
}
And the magic that makes this whole thing work is the AzureRuntimeBootLoader class I wrote
jweimann
@jweimann
Aug 20 2015 22:34
nice :) gonna try that out tonight
Aaron Stannard
@Aaronontheweb
Aug 20 2015 22:35
public static class AzureRuntimeBootLoader
    {
        public static async Task<Config> CreateRuntimeConfig(string seedRoleName, string akkaEndpoint)
        {
            // Need to wait until at least 1 instance of our seed role is up and available
            while(!IsSeedRoleAvailable(seedRoleName))
            {
                await Task.Delay(TimeSpan.FromSeconds(1.5));
            }

            return CreateConfig(seedRoleName, akkaEndpoint);
        }

        public static bool IsSeedRoleAvailable(string seedRoleName)
        {
            if (!RoleEnvironment.Roles.ContainsKey(seedRoleName))
                throw new ArgumentException("Undefined role " + seedRoleName + " in Azure service definition");
            return RoleEnvironment.Roles[seedRoleName].Instances.Any();
        }

        private static Config CreateConfig(string seedRoleName, string akkaEndpoint)
        {
            var section = (AkkaConfigurationSection)ConfigurationManager.GetSection("akka");
            var clusterConfig = section.AkkaConfig;

            var selfAzureAddress = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[akkaEndpoint];
            var selfAkkaAddress = selfAzureAddress.IPEndpoint.Address;
            var selfPort = selfAzureAddress.IPEndpoint.Port;
            var seedNodes = new List<string>();

            var trackerRoles = RoleEnvironment.Roles[seedRoleName].Instances;
            foreach (var trackerEndpoint in trackerRoles.Select(x => x.InstanceEndpoints[akkaEndpoint]))
            {
                seedNodes.Add(string.Format(@"""akka.tcp://{0}@{1}:{2}""", "webcrawler", trackerEndpoint.IPEndpoint.Address, trackerEndpoint.IPEndpoint.Port));
            }

            var remoteConfig = ConfigurationFactory.ParseString(string.Format(@"akka.remote.helios.tcp.public-hostname = ""{0}"" 
            akka.remote.helios.tcp.port = {1}", selfAkkaAddress, selfPort));
            var clusterSeedConfig = ConfigurationFactory.ParseString(string.Format(@"akka.cluster.seed-nodes = [{0}]", string.Join(",", seedNodes)));
            var finalConfig = clusterSeedConfig.WithFallback(remoteConfig).WithFallback(clusterConfig);
            return finalConfig;
        }
    }
jweimann
@jweimann
Aug 20 2015 22:35
have an azure meetup starting today locally
Aaron Stannard
@Aaronontheweb
Aug 20 2015 22:36
the AzureRuntimeBootloader is able to specify a type of Azure role that can be used as a seed node
and the name of a specific internal endpoint
you want to use internal endpoints for Akka.NET
so you can bypass the load-balancer and talk to each VM instance directly
does that make sense @jweimann ?
jweimann
@jweimann
Aug 20 2015 22:47
yep :)
Aaron Stannard
@Aaronontheweb
Aug 20 2015 22:55
:+1:
I'm going to OSS that whole sample soon
working on smoothing out some issues with CPU utilization on the worker nodes
trying to introduce throttling there to stop them from maxing out on massive domains
for the exact diminishing returns reasons I was talking about earlier :p