-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Program.cs
91 lines (75 loc) · 3.52 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//-----------------------------------------------------------------------
// <copyright file="Program.cs" company="Akka.NET Project">
// Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2022 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.Configuration;
using Akka.Pattern;
using ConfigurationFactory = Akka.Configuration.ConfigurationFactory;
namespace PersistenceBenchmark
{
class Program
{
// if you want to benchmark your persistent storage provides, paste the configuration in string below
// by default we're checking against in-memory journal
private static Config config = ConfigurationFactory.ParseString(@"
akka {
suppress-json-serializer-warning = true
persistence.journal {
plugin = ""akka.persistence.journal.sqlite""
sqlite {
class = ""Akka.Persistence.Sqlite.Journal.BatchingSqliteJournal, Akka.Persistence.Sqlite""
plugin-dispatcher = ""akka.actor.default-dispatcher""
table-name = event_journal
metadata-table-name = journal_metadata
auto-initialize = on
connection-string = ""Datasource=memdb-journal.db;Mode=Memory;Cache=Shared""
}
}
}");
public const int ActorCount = 1000;
public const int MessagesPerActor = 100;
static void Main(string[] args)
{
using (var system = ActorSystem.Create("persistent-benchmark", config.WithFallback(ConfigurationFactory.Default())))
{
Console.WriteLine("Performance benchmark starting...");
var actors = new IActorRef[ActorCount];
for (int i = 0; i < ActorCount; i++)
{
var pid = "a-" + i;
actors[i] = system.ActorOf(Props.Create(() => new PerformanceTestActor(pid)));
}
Task.WaitAll(actors.Select(a => a.Ask<Done>(Init.Instance)).Cast<Task>().ToArray());
Console.WriteLine("All actors have been initialized...");
var stopwatch = new Stopwatch();
stopwatch.Start();
for (int i = 0; i < MessagesPerActor; i++)
for (int j = 0; j < ActorCount; j++)
{
actors[j].Tell(new Store(1));
}
var finished = new Task[ActorCount];
for (int i = 0; i < ActorCount; i++)
{
finished[i] = actors[i].Ask<Finished>(Finish.Instance);
}
Task.WaitAll(finished);
var elapsed = stopwatch.ElapsedMilliseconds;
Console.WriteLine($"{ActorCount} actors stored {MessagesPerActor} events each in {elapsed/1000.0} sec. Average: {ActorCount*MessagesPerActor*1000.0/elapsed} events/sec");
foreach (Task<Finished> task in finished)
{
if (!task.IsCompleted || task.Result.State != MessagesPerActor)
throw new IllegalStateException("Actor's state was invalid");
}
}
Console.ReadLine();
}
}
}