Пример #1
0
    static void Main(string[] args)
    {
        var context = new RootContext();

        Console.WriteLine($"Is Server GC {GCSettings.IsServerGC}");
        const int messageCount = 1000000;
        const int batchSize    = 100;

        Console.WriteLine("Dispatcher\t\tElapsed\t\tMsg/sec");
        var tps = new[] { 300, 400, 500, 600, 700, 800, 900 };

        foreach (var t in tps)
        {
            var d = new ThreadPoolDispatcher {
                Throughput = t
            };

            var clientCount = Environment.ProcessorCount * 1;
            var clients     = new PID[clientCount];
            var echos       = new PID[clientCount];
            var completions = new TaskCompletionSource <bool> [clientCount];

            var echoProps = Props.FromProducer(() => new EchoActor())
                            .WithDispatcher(d)
                            .WithMailbox(() => BoundedMailbox.Create(2048));

            for (var i = 0; i < clientCount; i++)
            {
                var tsc = new TaskCompletionSource <bool>();
                completions[i] = tsc;
                var clientProps = Props.FromProducer(() => new PingActor(tsc, messageCount, batchSize))
                                  .WithDispatcher(d)
                                  .WithMailbox(() => BoundedMailbox.Create(2048));

                clients[i] = context.Spawn(clientProps);
                echos[i]   = context.Spawn(echoProps);
            }
            var tasks = completions.Select(tsc => tsc.Task).ToArray();
            var sw    = Stopwatch.StartNew();
            for (var i = 0; i < clientCount; i++)
            {
                var client = clients[i];
                var echo   = echos[i];

                context.Send(client, new Start(echo));
            }
            Task.WaitAll(tasks);

            sw.Stop();
            var totalMessages = messageCount * 2 * clientCount;

            var x = (int)(totalMessages / (double)sw.ElapsedMilliseconds * 1000.0d);
            Console.WriteLine($"{t}\t\t\t{sw.ElapsedMilliseconds}\t\t{x}");
            Thread.Sleep(2000);
        }

        Console.ReadLine();
    }
        public void Setup()
        {
            _context = new RootContext(new ActorSystem());

            _echoProps = Props.FromProducer(() => new EchoActor2())
                         .WithMailbox(() => BoundedMailbox.Create(2048));
            _echoActor = _context.Spawn(_echoProps);
            _timeout   = TimeSpan.FromSeconds(5);
        }
Пример #3
0
    static void Main(string[] args)
    {
        Func <IMailbox> unboundedMailbox =
            () => UnboundedMailbox.Create();
        Func <IMailbox> boundedMailbox =
            () => BoundedMailbox.Create(1024 * 1024);

        RunTest(boundedMailbox, "Bounded mailbox");
        RunTest(unboundedMailbox, "Unbounded mailbox");

        Console.ReadLine();
    }
Пример #4
0
        public Task InProcessPingPong()
        {
            var d = new ThreadPoolDispatcher {
                Throughput = Tps
            };

            var clientCount = Environment.ProcessorCount * 1;
            var clients     = new PID[clientCount];
            var echos       = new PID[clientCount];
            var completions = new TaskCompletionSource <bool> [clientCount];

            var echoProps = Props.FromProducer(() => new EchoActor())
                            .WithDispatcher(d)
                            .WithMailbox(() => BoundedMailbox.Create(2048));

            for (var i = 0; i < clientCount; i++)
            {
                var tsc = new TaskCompletionSource <bool>();
                completions[i] = tsc;

                var clientProps = Props.FromProducer(() => new PingActor(tsc, MessageCount, BatchSize))
                                  .WithDispatcher(d)
                                  .WithMailbox(() => BoundedMailbox.Create(2048));

                clients[i] = _context.Spawn(clientProps);
                echos[i]   = _context.Spawn(echoProps);
            }

            var tasks = completions.Select(tsc => tsc.Task).ToArray();

            for (var i = 0; i < clientCount; i++)
            {
                var client = clients[i];
                var echo   = echos[i];

                _context.Send(client, new Start(echo));
            }

            return(Task.WhenAll(tasks));
        }
Пример #5
0
        public PublishSubscribeRouterActor(
            string clusterName,
            ILoggerFactory loggerFactory,
            Func <Subscription, ITopicFilter> topicFilterFactory,
            int sendBufferSize = 8192)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            _topicFilterFactory = topicFilterFactory ?? throw new ArgumentNullException(nameof(topicFilterFactory));

            _lookup = new SubscriptionWriterLookupCache <PID>(new SubscriptionWriterLookup <PID>());

            _logger = loggerFactory.CreateLogger <PublishSubscribeRouterActor>();
            _publishSubscribeRouterActorName = $"{clusterName}_{typeof(PublishSubscribeRouterActor).FullName}";
            Props props = Actor.FromFunc(ReceiveAsync).WithMailbox(() => BoundedMailbox.Create(sendBufferSize));

            PubSubRouterActorPid  = Actor.SpawnNamed(props, _publishSubscribeRouterActorName);
            _topologySubscription = Actor.EventStream
                                    .Subscribe <ClusterTopologyEvent>(clusterTopologyEvent => { PubSubRouterActorPid.Tell(clusterTopologyEvent); });
        }
Пример #6
0
 public Task Unbound() => RunTest(() => BoundedMailbox.Create(1024 * 1024));
Пример #7
0
        private MailboxType LookupConfigurator(string id)
        {
            MailboxType configurator;
            if (!_mailboxTypeConfigurators.TryGetValue(id, out configurator))
            {
                // It doesn't matter if we create a mailbox type configurator that isn't used due to concurrent lookup.
                if(id.Equals("unbounded")) configurator = new UnboundedMailbox();
                else if (id.Equals("bounded")) configurator = new BoundedMailbox(Settings, Config(id));
                else
                {
                    if(!Settings.Config.HasPath(id)) throw new ConfigurationException($"Mailbox Type [{id}] not configured");
                    var conf = Config(id);

                    var mailboxTypeName = conf.GetString("mailbox-type");
                    if (string.IsNullOrEmpty(mailboxTypeName)) throw new ConfigurationException($"The setting mailbox-type defined in [{id}] is empty");
                    var type = Type.GetType(mailboxTypeName);
                    if(type == null) throw new ConfigurationException($"Found mailbox-type [{mailboxTypeName}] in configuration for [{id}], but could not find that type in any loaded assemblies.");
                    var args = new object[] {Settings, conf};
                    try
                    {
                        configurator = (MailboxType) Activator.CreateInstance(type, args);
                    }
                    catch (Exception ex)
                    {
                        throw new ArgumentException($"Cannot instantiate MailboxType {type}, defined in [{id}]. Make sure it has a public " +
                                                     "constructor with [Akka.Actor.Settings, Akka.Configuration.Config] parameters", ex);
                    }

                    // TODO: check for blocking mailbox with a non-zero pushtimeout and issue a warning
                }

                // add the new configurator to the mapping, or keep the existing if it was already added
                _mailboxTypeConfigurators.AddOrUpdate(id, configurator, (s, type) => type);
            }

            return configurator;
        }
Пример #8
0
        private static void Main(string[] args)
        {
            var benchmarkSettings = Configuration.GetConfiguration <InprocBenchmarkSettings>("InprocBenchmarkSettings");

            Console.WriteLine($"Is Server GC {GCSettings.IsServerGC}");
            int messageCount = benchmarkSettings.MessageCount;
            int batchSize    = benchmarkSettings.BatchSize;

            Console.WriteLine("Dispatcher\t\tElapsed\t\tMsg/sec");
            var tps = benchmarkSettings.Throughputs;

            var msgSecs = new List <int>();

            foreach (var t in tps)
            {
                var d = new ThreadPoolDispatcher {
                    Throughput = t
                };

                var clientCount = Environment.ProcessorCount * 1;
                var clients     = new PID[clientCount];
                var echos       = new PID[clientCount];
                var completions = new TaskCompletionSource <bool> [clientCount];

                var echoProps = Actor.FromProducer(() => new EchoActor())
                                .WithDispatcher(d)
                                .WithMailbox(() => benchmarkSettings.MailboxType == "bounded-mailbox" ? BoundedMailbox.Create(2048) : UnboundedMailbox.Create());

                for (var i = 0; i < clientCount; i++)
                {
                    var tsc = new TaskCompletionSource <bool>();
                    completions[i] = tsc;
                    var clientProps = Actor.FromProducer(() => new PingActor(tsc, messageCount, batchSize))
                                      .WithDispatcher(d)
                                      .WithMailbox(() => benchmarkSettings.MailboxType == "bounded-mailbox" ? BoundedMailbox.Create(2048) : UnboundedMailbox.Create());

                    clients[i] = Actor.Spawn(clientProps);
                    echos[i]   = Actor.Spawn(echoProps);
                }
                var tasks = completions.Select(tsc => tsc.Task).ToArray();
                var sw    = Stopwatch.StartNew();
                for (var i = 0; i < clientCount; i++)
                {
                    var client = clients[i];
                    var echo   = echos[i];

                    client.Tell(new Start(echo));
                }
                Task.WaitAll(tasks);

                sw.Stop();
                var totalMessages = messageCount * 2 * clientCount;

                var x = (int)(totalMessages / (double)sw.ElapsedMilliseconds * 1000.0d);
                Console.WriteLine($"{t}\t\t\t{sw.ElapsedMilliseconds}\t\t{x}");
                msgSecs.Add(x);
                Thread.Sleep(2000);
            }

            Console.WriteLine($"Avg Msg/sec : {msgSecs.Average()}");

            Console.ReadLine();
        }