Created
May 13, 2015 16:39
-
-
Save annymsMthd/23e5512006b3674edc3d to your computer and use it in GitHub Desktop.
Slow pokes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//----------------------------------------------------------------------- | |
// <copyright file="Program.cs" company="Akka.NET Project"> | |
// Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com> | |
// Copyright (C) 2013-2015 Akka.NET project <https://github.com/akkadotnet/akka.net> | |
// </copyright> | |
//----------------------------------------------------------------------- | |
using System; | |
using System.Collections.Generic; | |
using System.Configuration; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using Akka.Actor; | |
using Akka.Configuration; | |
using Akka.Configuration.Hocon; | |
namespace Samples.Cluster.Simple | |
{ | |
class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
StartUp(args.Length == 0 ? new String[] {"2551", "2552", "0"} : args); | |
Console.WriteLine("Press any key to exit"); | |
Console.ReadKey(); | |
} | |
public static void StartUp(string[] ports) | |
{ | |
var section = (AkkaConfigurationSection)ConfigurationManager.GetSection("akka"); | |
foreach (var port in ports) | |
{ | |
//Override the configuration of the port | |
var config = | |
ConfigurationFactory.ParseString("akka.remote.helios.tcp.port=" + port) | |
.WithFallback(section.AkkaConfig); | |
//create an Akka system | |
var system = ActorSystem.Create("ClusterSystem", config); | |
//create an actor that handles cluster domain events | |
system.ActorOf(Props.Create(typeof (SimpleClusterListener)), "clusterListener"); | |
var slowPokeCount = 1000; | |
List<IActorRef> SlowPokes = new List<IActorRef>(); | |
for (var i = 0; i < slowPokeCount; i ++) | |
{ | |
SlowPokes.Add(system.ActorOf(Props.Create(() => new SlowActor()), string.Format("slowPoke:{0}", i))); | |
} | |
//if (port == "2552") | |
Task.Run(() => | |
{ | |
Thread.Sleep(10000); | |
for(int i =0; i < 100; i ++) | |
{ | |
SlowPokes.ForEach(slow => slow.Tell(i)); | |
} | |
Console.WriteLine("done"); | |
}); | |
} | |
} | |
} | |
public class SlowActor : UntypedActor | |
{ | |
public SlowActor() | |
{ | |
} | |
protected override void OnReceive(object message) | |
{ | |
Thread.Sleep(10000); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment