美文网首页
Akka.net 本地性能测试

Akka.net 本地性能测试

作者: _黑冰_ | 来源:发表于2019-05-17 12:22 被阅读0次

    介绍

    Akka.NET是一套开源的,用于设计跨处理器和网络的可扩展系统。 Akka.net 允许您专注于满足业务需求,而不用去编写底层代码来保证系统的性能。

    本测试用例用于收集Akka.net单机版,在不同硬件环境下的表现。

    软件平台

    • dotnet core 2.2 & C# 7.3
    • Akka.net 1.3.13

    测试代码

    using Akka.Actor;
    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    
    namespace AkkaTest
    {
        class Program
        {
            static async Task Main(string[] args)
            {
                // Create a new actor system (a container for your actors)
                var system = ActorSystem.Create("MySystem");
                int clientCount = 10;
                var greeter = system.ActorOf<GreetingActor>("greeter");
    
                // Create your actor and get a reference to it.
                List<Task<(long m, int cout)>> tasks = new List<Task<(long m, int cout)>>(clientCount);
    
                for (int i = 0; i < clientCount; i++)
                {
                    tasks.Add(Run(greeter));
                }
    
                double allm = 0.0;
                double count = 0.0;
    
                foreach (var item in tasks)
                {
                    var r = await item;
    
                    if (r.m == 0) //出错了客户端数量-1
                        clientCount--;
    
                    allm += r.m;
                    count += r.cout;
                }
    
                Console.WriteLine(count + "/" + (allm / clientCount));
    
                float mc = (float)(count / (allm / clientCount));
                float sc = mc * 1000;
    
                Console.WriteLine(sc + " TPS");
    
    
                Console.ReadLine();
            }
    
    
            private static async Task<(long m, int count)> Run(IActorRef greeter)
            {
                try
                {
    
    
                    int count = 10000;
                    int p = 0;
    
                    var stop = System.Diagnostics.Stopwatch.StartNew();
    
                    while (p < count)
                    {
                        //Ask测试
                        //await greeter.Ask(new GreetingMessage());
                        //Tell测试
                        greeter.Tell(new GreetingMessage());
                        p++;
                    }
                    stop.Stop();
                   
                    Console.WriteLine($"我调用了{count} 用了{stop.ElapsedMilliseconds}毫秒");
    
                    return (stop.ElapsedMilliseconds, count);
    
    
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return (0, 0);
                }
    
            }
        }
        public class GreetingMessage
        {
        }
        public class GreetingActor : TypedActor, IHandle<GreetingMessage>
        {
            public void Handle(GreetingMessage message)
            {
                Sender.Tell("OK");
            }
        }
    
    }
    
    

    测试环境

    树莓派 3B+ 4C1G / Raspbian

    Ask Tell

    J3455/4G RAM / Ubuntu 18.04

    Ask Tell

    I5 7400 3.0GHz /16G RAM / Windows 10

    Ask Tell

    相关文章

      网友评论

          本文标题:Akka.net 本地性能测试

          本文链接:https://www.haomeiwen.com/subject/gjbnaqtx.html