Akka.net 本地性能测试
2019-05-17 本文已影响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


J3455/4G RAM / Ubuntu 18.04


I5 7400 3.0GHz /16G RAM / Windows 10

