Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Ddata serialization opts #7014

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/benchmark/Akka.Benchmarks/DData/ORSetBenchmarks.cs
Expand Up @@ -13,7 +13,9 @@
using Akka.Benchmarks.Configurations;
using Akka.Cluster;
using Akka.DistributedData;
using Akka.DistributedData.Serialization;
using BenchmarkDotNet.Attributes;
using static Akka.Benchmarks.DData.RDDBenchTypes;

namespace Akka.Benchmarks.DData
{
Expand Down
16 changes: 16 additions & 0 deletions src/benchmark/Akka.Benchmarks/DData/RDDBenchTypes.cs
@@ -0,0 +1,16 @@
// //-----------------------------------------------------------------------
// // <copyright file="RDDBenchTypes.cs" company="Akka.NET Project">
// // Copyright (C) 2009-2023 Lightbend Inc. <http://www.lightbend.com>
// // Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// // </copyright>
// //-----------------------------------------------------------------------

namespace Akka.Benchmarks.DData;

public class RDDBenchTypes
{

public record struct TestKey(int i);

public record TestVal(string v);
}
@@ -0,0 +1,140 @@
// //-----------------------------------------------------------------------
// // <copyright file="RDLwwDictionaryBenchmarks.cs" company="Akka.NET Project">
// // Copyright (C) 2009-2023 Lightbend Inc. <http://www.lightbend.com>
// // Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// // </copyright>
// //-----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Akka.Actor;
using Akka.Benchmarks.Configurations;
using Akka.Cluster;
using Akka.Configuration;
using Akka.DistributedData;
using Akka.DistributedData.Serialization;
using BenchmarkDotNet.Attributes;

namespace Akka.Benchmarks.DData;

[Config(typeof(MicroBenchmarkConfig))]
public class SerializerLwwDictionaryBenchmarks
{
[Params(typeof(RDDBenchTypes.TestKey), typeof(RDDBenchTypes.TestVal))]
public Type KeyType;

[Params(typeof(RDDBenchTypes.TestKey), typeof(RDDBenchTypes.TestVal))]
public Type ValueType;

[Params(25)]
public int NumElements;

[Params(10)]
public int NumNodes;

private UniqueAddress[] _nodes;
private object _c1;
private ActorSystem sys;
private ReplicatedDataSerializer ser;
private byte[] _c1Ser;
private string _c1Manifest;

[GlobalSetup]
public void SetupSystem()
{
typeof(SerializerLwwDictionaryBenchmarks).GetMethod(
nameof(SerializerLwwDictionaryBenchmarks.CreateItems),
BindingFlags.Instance | BindingFlags.NonPublic)
.MakeGenericMethod(new []{KeyType,ValueType})
.Invoke(this, new object[]{});
var conf = ConfigurationFactory.ParseString(@"akka.actor {
serializers {
akka-replicated-data = ""Akka.DistributedData.Serialization.ReplicatedDataSerializer, Akka.DistributedData""
}
serialization-bindings {
""Akka.DistributedData.IReplicatedDataSerialization, Akka.DistributedData"" = akka-replicated-data
}
serialization-identifiers {
""Akka.DistributedData.Serialization.ReplicatedDataSerializer, Akka.DistributedData"" = 11
}
}");
sys = ActorSystem.Create("rddsb", conf);
ser = (ReplicatedDataSerializer)sys.Serialization.FindSerializerForType(
typeof(IReplicatedDataSerialization));
_c1Ser = ser.ToBinary(_c1);
_c1Manifest = ser.Manifest(_c1);
}

private void CreateItems<TKey,TValue>()
{
var newNodes = new List<UniqueAddress>(NumNodes);
foreach (var i in Enumerable.Range(0, NumNodes))
{
var address = new Address("akka.tcp", "Sys", "localhost", 2552 + i);
var uniqueAddress = new UniqueAddress(address, i);
newNodes.Add(uniqueAddress);
}

_nodes = newNodes.ToArray();
var newElements = new List<TValue>(NumNodes);
foreach (var i in Enumerable.Range(0, NumElements))
{

newElements.Add(generate<TValue>(i));
}

var _c1 = LWWDictionary<TKey, List<TValue>>
.Empty;
int j = 0;
foreach (var node in _nodes)
{
_c1 = _c1.SetItem(node, generate<TKey>(j),
newElements);
j++;
}

this._c1 = _c1;
}

private TValue generate<TValue>(int i)
{
if (typeof(TValue) == typeof(RDDBenchTypes.TestVal))
{
return (TValue)(object)new RDDBenchTypes.TestVal(i.ToString());
}
else if (typeof(TValue) == typeof(RDDBenchTypes.TestKey))
{
return (TValue)(object)new RDDBenchTypes.TestKey(i);
}
else if (typeof(TValue) == typeof(int))
{
return (TValue)(object)i;
}
else if (typeof(TValue) == typeof(string))
{
return (TValue)(object)i.ToString();
}
else if (typeof(TValue) == typeof(long))
{
return (TValue)(object)(i);
}
else
{
return (TValue)(object)(i);
}
}

[Benchmark]
public void Serialize_LWWDict()
{
ser.ToBinary(_c1);
}

[Benchmark]
public void Deserialize_LWWDict()
{
ser.FromBinary(_c1Ser, _c1Manifest);
}
}
@@ -0,0 +1,90 @@
// //-----------------------------------------------------------------------
// // <copyright file="SerializerORDictionaryBenchmarks.cs" company="Akka.NET Project">
// // Copyright (C) 2009-2023 Lightbend Inc. <http://www.lightbend.com>
// // Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// // </copyright>
// //-----------------------------------------------------------------------

using System.Collections.Generic;
using System.Linq;
using Akka.Actor;
using Akka.Benchmarks.Configurations;
using Akka.Cluster;
using Akka.Configuration;
using Akka.DistributedData;
using Akka.DistributedData.Serialization;
using BenchmarkDotNet.Attributes;

namespace Akka.Benchmarks.DData;

[Config(typeof(MicroBenchmarkConfig))]
public class SerializerORDictionaryBenchmarks
{
[Params(25)]
public int NumElements;

[Params(10)]
public int NumNodes;

private UniqueAddress[] _nodes;
private ORDictionary<RDDBenchTypes.TestKey,ORSet<RDDBenchTypes.TestVal>> _c1;
private ORSet<RDDBenchTypes.TestVal> _elements;
private ActorSystem sys;
private ReplicatedDataSerializer ser;
private byte[] _c1Ser;
private string _c1Manifest;

[GlobalSetup]
public void SetupSystem()
{
var newNodes = new List<UniqueAddress>(NumNodes);
foreach(var i in Enumerable.Range(0, NumNodes)){
var address = new Address("akka.tcp", "Sys", "localhost", 2552 + i);
var uniqueAddress = new UniqueAddress(address, i);
newNodes.Add(uniqueAddress);
}
_nodes = newNodes.ToArray();
var newElements = ORSet<RDDBenchTypes.TestVal>.Empty;
foreach(var i in Enumerable.Range(0, NumElements)){
newElements = newElements.Add(_nodes[0],new RDDBenchTypes.TestVal(i.ToString()));
}
_elements = newElements;

_c1 = ORDictionary<RDDBenchTypes.TestKey, ORSet<RDDBenchTypes.TestVal>>
.Empty;
int j = 0;
foreach(var node in _nodes)
{
_c1 = _c1.SetItem(node, new RDDBenchTypes.TestKey(j), _elements);
j++;
}
var conf = ConfigurationFactory.ParseString(@"akka.actor {
serializers {
akka-replicated-data = ""Akka.DistributedData.Serialization.ReplicatedDataSerializer, Akka.DistributedData""
}
serialization-bindings {
""Akka.DistributedData.IReplicatedDataSerialization, Akka.DistributedData"" = akka-replicated-data
}
serialization-identifiers {
""Akka.DistributedData.Serialization.ReplicatedDataSerializer, Akka.DistributedData"" = 11
}
}");
sys = ActorSystem.Create("rddsb", conf);
ser = (ReplicatedDataSerializer)sys.Serialization.FindSerializerForType(
typeof(IReplicatedDataSerialization));
_c1Ser = ser.ToBinary(_c1);
_c1Manifest = ser.Manifest(_c1);
}

[Benchmark]
public void Serialize_ORDictionary()
{
ser.ToBinary(_c1);
}

[Benchmark]
public void Deserialize_ORDictionary()
{
ser.FromBinary(_c1Ser, _c1Manifest);
}
}
90 changes: 90 additions & 0 deletions src/benchmark/Akka.Benchmarks/DData/SerializerORSetBenchmarks.cs
@@ -0,0 +1,90 @@
// //-----------------------------------------------------------------------
// // <copyright file="SerializerORSetBenchmarks.cs" company="Akka.NET Project">
// // Copyright (C) 2009-2023 Lightbend Inc. <http://www.lightbend.com>
// // Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// // </copyright>
// //-----------------------------------------------------------------------

using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Akka.Actor;
using Akka.Actor.Setup;
using Akka.Benchmarks.Configurations;
using Akka.Cluster;
using Akka.Configuration;
using Akka.DistributedData;
using Akka.DistributedData.Serialization;
using Akka.Serialization;
using BenchmarkDotNet.Attributes;

namespace Akka.Benchmarks.DData;

[Config(typeof(MicroBenchmarkConfig))]
public class SerializerORSetBenchmarks
{
[Params(25)]
public int NumElements;

[Params(10)]
public int NumNodes;

private ActorSystem sys;
private ReplicatedDataSerializer ser;
private UniqueAddress[] _nodes;
private RDDBenchTypes.TestVal[] _elements;
private ORSet<List<RDDBenchTypes.TestVal>> _c1;
private byte[] _c1Ser;
private string _c1Manifest;

[GlobalSetup]
public void SetupSystem()
{
var newNodes = new List<UniqueAddress>(NumNodes);
foreach(var i in Enumerable.Range(0, NumNodes)){
var address = new Address("akka.tcp", "Sys", "localhost", 2552 + i);
var uniqueAddress = new UniqueAddress(address, i);
newNodes.Add(uniqueAddress);
}
_nodes = newNodes.ToArray();
var newElements = new List<RDDBenchTypes.TestVal>(NumNodes);
foreach(var i in Enumerable.Range(0, NumElements)){
newElements.Add(new RDDBenchTypes.TestVal(i.ToString()));
}
_elements = newElements.ToArray();

_c1 = ORSet<List<RDDBenchTypes.TestVal>>.Empty;
foreach(var node in _nodes){
_c1 = _c1.Add(node, _elements.ToList());
}

var conf = ConfigurationFactory.ParseString(@"akka.actor {
serializers {
akka-replicated-data = ""Akka.DistributedData.Serialization.ReplicatedDataSerializer, Akka.DistributedData""
}
serialization-bindings {
""Akka.DistributedData.IReplicatedDataSerialization, Akka.DistributedData"" = akka-replicated-data
}
serialization-identifiers {
""Akka.DistributedData.Serialization.ReplicatedDataSerializer, Akka.DistributedData"" = 11
}
}");
sys = ActorSystem.Create("rddsb", conf);
ser = (ReplicatedDataSerializer)sys.Serialization.FindSerializerForType(
typeof(IReplicatedDataSerialization));
_c1Ser = ser.ToBinary(_c1);
_c1Manifest = ser.Manifest(_c1);
}
[Benchmark]
public void Serialize_ORSet()
{
ser.ToBinary(_c1);
}

[Benchmark]
public void Deserialize_ORSet()
{
ser.FromBinary(_c1Ser, _c1Manifest);
}

}
12 changes: 12 additions & 0 deletions src/benchmark/Akka.Benchmarks/Program.cs
Expand Up @@ -5,7 +5,10 @@
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Reflection;
using System.Threading;
using Akka.Benchmarks.DData;
using BenchmarkDotNet.Running;

namespace Akka.Benchmarks
Expand All @@ -14,6 +17,15 @@ class Program
{
static void Main(string[] args)
{
//var w = new SerializerORDictionaryBenchmarks();
//w.NumElements = 25;
//w.NumNodes = 30;
//w.SetupSystem();
//Console.WriteLine("Running");
//while (true)
//{
// w.Serialize_ORDictionary();
//}
BenchmarkSwitcher.FromAssembly(Assembly.GetExecutingAssembly()).Run(args);
}
}
Expand Down
Expand Up @@ -14,4 +14,8 @@
<ProjectReference Include="..\..\..\core\Akka.Coordination\Akka.Coordination.csproj"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.2.2" />
</ItemGroup>

</Project>
Expand Up @@ -14,7 +14,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.2.2" />
<PackageReference Include="Hyperion" Version="$(HyperionVersion)"/>
<PackageReference Include="NonBlocking" Version="2.1.2" />
</ItemGroup>

</Project>