Skip to content

Commit

Permalink
Refactor Benchmark performance test
Browse files Browse the repository at this point in the history
  • Loading branch information
jmmorato committed Oct 2, 2024
1 parent aeda905 commit 3776682
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 97 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci_standard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ jobs:
flag-name: coverage-windows-${{ join(matrix.*, '-') }}
fail-on-error: false

- name: Performance Test
shell: pwsh
run: |
dotnet publish ${{ github.workspace }}/Tests/BenchmarkPerformance/BenchmarkPerformance.csproj --configuration Release --framework net8.0 --runtime win-${{ matrix.BuildPlatform }}
${{ github.workspace }}/Tests/BenchmarkPerformance/bin/Release/net8.0/win-${{ matrix.BuildPlatform }}/publish/BenchmarkPerformance.exe 1
working-directory: ${{ github.workspace }}

build_linux:
runs-on: ubuntu-20.04

Expand Down Expand Up @@ -243,6 +250,13 @@ jobs:
flag-name: coverage-linux-x64-Release
fail-on-error: false

- name: Performance Test
shell: pwsh
run: |
dotnet publish ${{ github.workspace }}/Tests/BenchmarkPerformance/BenchmarkPerformance.csproj --configuration Release --framework net8.0 --runtime linux-x64
${{ github.workspace }}/Tests/BenchmarkPerformance/bin/Release/net8.0/linux-x64/publish/BenchmarkPerformance.exe 1
working-directory: ${{ github.workspace }}

build_macos_x64:
runs-on: macos-13

Expand Down Expand Up @@ -513,3 +527,5 @@ jobs:
carryforward: coverage-windows-x64-Release,coverage-windows-x86-Release,coverage-linux-x64-Release,coverage-macos-x64-Release,coverage-macos-arm64-Release
fail-on-error: false



Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Linq;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Exporters.Csv;
using BenchmarkDotNet.Jobs;
Expand All @@ -12,7 +11,11 @@ internal class LatencyTestConfiguration : ManualConfig
{
public LatencyTestConfiguration()
{
AddJob(Job.Default.WithIterationCount(1).WithToolchain(InProcessEmitToolchain.Instance));
AddJob(Job.Default
.WithIterationCount(10)
.WithUnrollFactor(1)
.WithInvocationCount(1)
.WithToolchain(InProcessEmitToolchain.Instance));
AddColumnProvider(DefaultConfig.Instance.GetColumnProviders().ToArray());
AddColumn(new LatencyAverageColumn());
AddColumn(new LatencyDeviationColumn());
Expand Down
4 changes: 3 additions & 1 deletion Tests/BenchmarkPerformance/PerformanceTests/LatencyTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using BenchmarkDotNet.Attributes;
using OpenDDSharp.BenchmarkPerformance.CustomColumns;

namespace OpenDDSharp.BenchmarkPerformance.PerformanceTests;

[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global", Justification = "Required by BenchmarkDotNet.")]
public class LatencyTest
{
private OpenDDSharpLatencyTest _openDDSharpLatencyTest;
Expand Down Expand Up @@ -127,4 +129,4 @@ private void LatencyStatistics(string name)
File.WriteAllText(Path.Combine(LatencyNinetyNineColumn.OutputFolder, ninetyNineFile),
_latencyHistory[count * 99 / 100].TotalMilliseconds.ToString("0.0000", CultureInfo.InvariantCulture));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
using OpenDDSharp.DDS;
using OpenDDSharp.OpenDDS.DCPS;
using CdrWrapper;
using OpenDDSharp.OpenDDS.RTPS;

namespace OpenDDSharp.BenchmarkPerformance.PerformanceTests;

internal sealed class OpenDDSharpLatencyTest : IDisposable
{
private const int DOMAIN_ID = 42;
private const string RTPS_DISCOVERY = "RtpsDiscovery";

private readonly ManualResetEventSlim _evt;
private readonly Random _random = new ();
private readonly int _totalInstances;
private readonly int _totalSamples;
private readonly byte[] _payload;
private readonly Dictionary<int, InstanceHandle> _instanceHandles = new();
private readonly KeyedOctets _sample;

private int _count;

Expand All @@ -35,39 +37,39 @@ public OpenDDSharpLatencyTest(int totalInstances, int totalSamples, ulong totalP
_totalSamples = totalSamples;
_evt = new ManualResetEventSlim(false);

_payload = new byte[totalPayload];
_random.NextBytes(_payload);
var payload = new byte[totalPayload];
_random.NextBytes(payload);

InitializeDDSEntities();
}

public IList<TimeSpan> Run()
{
_count = 0;

var latencyHistory = new List<TimeSpan>();

_readerThread.Start();
var sample = new KeyedOctets
_sample = new KeyedOctets
{
ValueField = _payload,
ValueField = payload,
};
}

public IList<TimeSpan> Run()
{
var latencyHistory = new List<TimeSpan>();

for (var i = 1; i <= _totalSamples; i++)
{
for (var j = 1; j <= _totalInstances; j++)
{
sample.KeyField = j.ToString(CultureInfo.InvariantCulture);
_sample.KeyField = j.ToString(CultureInfo.InvariantCulture);

if (!_instanceHandles.TryGetValue(j, out var instanceHandle))
{
instanceHandle = _dataWriter.RegisterInstance(sample);
instanceHandle = _dataWriter.RegisterInstance(_sample);
_instanceHandles.Add(j, instanceHandle);
}

var publicationTime = DateTime.UtcNow.Ticks;

_dataWriter.Write(sample, instanceHandle);
_dataWriter.Write(_sample, instanceHandle);

_evt.Wait();

Expand All @@ -76,7 +78,7 @@ public IList<TimeSpan> Run()
latencyHistory.Add(latency);

_evt.Reset();
};
}
}

_readerThread.Join();
Expand All @@ -86,6 +88,25 @@ public IList<TimeSpan> Run()

private void InitializeDDSEntities()
{
Ace.Init();

var disc = new RtpsDiscovery(RTPS_DISCOVERY)
{
SedpMulticast = false,
SedpLocalAddress = "127.0.0.1:0",
SpdpLocalAddress = "127.0.0.1:0",
ResendPeriod = new TimeValue
{
Seconds = 1,
MicroSeconds = 0,
},
};

ParticipantService.Instance.AddDiscovery(disc);
ParticipantService.Instance.DefaultDiscovery = RTPS_DISCOVERY;
ParticipantService.Instance.SetRepoDomain(DOMAIN_ID, RTPS_DISCOVERY);


_dpf = ParticipantService.Instance.GetDomainParticipantFactory();

var guid = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
Expand All @@ -108,8 +129,6 @@ private void InitializeDDSEntities()
Seconds = 0,
MicroSeconds = 500_000,
},
SendBufferSize = 1048576,
RcvBufferSize = 4194304,
};
config.Insert(transport);

Expand All @@ -134,12 +153,11 @@ private void InitializeDDSEntities()
History =
{
Kind = HistoryQosPolicyKind.KeepLastHistoryQos,
Depth = 10,
Depth = 1,
},
};
var dw = _publisher.CreateDataWriter(_topic, dwQos);
_dataWriter = new KeyedOctetsDataWriter(dw);
// TransportRegistry.Instance.BindConfig(configName, _dataWriter);

var subQos = new SubscriberQos
{
Expand All @@ -153,12 +171,11 @@ private void InitializeDDSEntities()
History =
{
Kind = HistoryQosPolicyKind.KeepLastHistoryQos,
Depth = 10,
Depth = 1,
},
};
var dr = _subscriber.CreateDataReader(_topic, drQos);
_dataReader = new KeyedOctetsDataReader(dr);
// TransportRegistry.Instance.BindConfig(configName1, _dataReader);

_dataWriter.Enable();
_dataReader.Enable();
Expand Down Expand Up @@ -214,5 +231,10 @@ public void Dispose()

_participant.DeleteContainedEntities();
_dpf.DeleteParticipant(_participant);

ParticipantService.Instance.Shutdown();

Ace.Fini();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ internal sealed class RtiConnextLatencyTest : IDisposable
private readonly Random _random = new ();
private readonly int _totalInstances;
private readonly int _totalSamples;
private readonly byte[] _payload;
private readonly Dictionary<int, InstanceHandle> _instanceHandles = new();
private readonly KeyedOctetsTopicType _sample;

private int _count;

Expand All @@ -39,35 +39,37 @@ public RtiConnextLatencyTest(int totalInstances, int totalSamples, ulong totalPa

_evt = new ManualResetEventSlim(false);

_payload = new byte[totalPayload];
_random.NextBytes(_payload);
var payload = new byte[totalPayload];
_random.NextBytes(payload);

InitializeDDSEntities();

_count = 0;

_readerThread.Start();

_sample = new KeyedOctetsTopicType();
_sample.Value.AddRange(payload);
}

public IList<TimeSpan> Run()
{
var latencyHistory = new List<TimeSpan>();

_readerThread.Start();

var sample = new KeyedOctetsTopicType();
sample.Value.AddRange(_payload);

for (var i = 1; i <= _totalSamples; i++)
{
for (var j = 1; j <= _totalInstances; j++)
{
sample.Key = j.ToString(CultureInfo.InvariantCulture);
_sample.Key = j.ToString(CultureInfo.InvariantCulture);

if (!_instanceHandles.TryGetValue(j, out var instanceHandle))
{
instanceHandle = _dataWriter.RegisterInstance(sample);
instanceHandle = _dataWriter.RegisterInstance(_sample);
_instanceHandles.Add(j, instanceHandle);
}

var publicationTime = DateTime.UtcNow.Ticks;
_dataWriter.Write(sample);
_dataWriter.Write(_sample);

_evt.Wait();

Expand Down Expand Up @@ -101,6 +103,8 @@ public void Dispose()

_participant.DisposeContainedEntities();
_participant.Dispose();

DomainParticipantFactory.Instance.Dispose();
}

private void InitializeDDSEntities()
Expand Down
Loading

0 comments on commit 3776682

Please sign in to comment.