Skip to content

Commit

Permalink
Change garbage benchmark to sampling benchmark and improve sampling
Browse files Browse the repository at this point in the history
Use only one client for better readability and make message exchange longer, so more samples can be taken
  • Loading branch information
JohannesDeml committed Apr 20, 2021
1 parent 13a3249 commit 795242b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="GarbageBenchmarkConfig.cs">
// <copyright file="SamplingBenchmarkConfig.cs">
// Copyright (c) 2021 Johannes Deml. All rights reserved.
// </copyright>
// <author>
Expand All @@ -8,23 +8,26 @@
// </author>
// --------------------------------------------------------------------------------------------------------------------

using System.Diagnostics.Tracing;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using Microsoft.Diagnostics.NETCore.Client;
using Microsoft.Diagnostics.Tracing.Parsers;

namespace NetworkBenchmark
{
public class GarbageBenchmarkConfig : ManualConfig
public class SamplingBenchmarkConfig : ManualConfig
{
public GarbageBenchmarkConfig()
public SamplingBenchmarkConfig()
{
Add(DefaultConfig.Instance);

Job baseJob = Job.Default
.WithLaunchCount(1)
.WithWarmupCount(1)
.WithIterationCount(10)
.WithIterationCount(1)
.WithGcServer(true)
.WithGcConcurrent(true)
.WithGcForce(true)
Expand All @@ -34,8 +37,19 @@ public GarbageBenchmarkConfig()

ConfigHelper.AddDefaultColumns(this);

AddDiagnoser(MemoryDiagnoser.Default);
AddDiagnoser(new EventPipeProfiler(EventPipeProfile.GcVerbose));
var providers = new[]
{
new EventPipeProvider(
name: ClrTraceEventParser.ProviderName,
eventLevel: EventLevel.Verbose,
keywords: (long) ClrTraceEventParser.Keywords.Default |
(long) ClrTraceEventParser.Keywords.GC |
(long) ClrTraceEventParser.Keywords.GCHandle |
(long) ClrTraceEventParser.Keywords.Exception
),
};

AddDiagnoser(new EventPipeProfiler(providers: providers, performExtraBenchmarksRun: false));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="GarbageBenchmark.cs">
// <copyright file="SamplingBenchmark.cs">
// Copyright (c) 2020 Johannes Deml. All rights reserved.
// </copyright>
// <author>
Expand All @@ -12,14 +12,14 @@

namespace NetworkBenchmark
{
[Config(typeof(GarbageBenchmarkConfig))]
public class GarbageBenchmark : APredefinedBenchmark
[Config(typeof(SamplingBenchmarkConfig))]
public class SamplingBenchmark : APredefinedBenchmark
{
[Params(NetworkLibrary.ENet, NetworkLibrary.LiteNetLib, NetworkLibrary.NetCoreServer)]
public NetworkLibrary Library { get; set; }

public override int ClientCount { get; set; } = 10;
public override int MessageTarget { get; set; } = 10_000;
public override int ClientCount { get; set; } = 1;
public override int MessageTarget { get; set; } = 100_000;
protected override BenchmarkMode Mode => BenchmarkMode.Garbage;
protected override NetworkLibrary LibraryTarget => Library;

Expand Down
2 changes: 1 addition & 1 deletion NetworkBenchmarkDotNet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static void RunPredefinedBenchmarks(BenchmarkMode mode)

if ((mode & BenchmarkMode.Garbage) != 0)
{
RunBenchmark<GarbageBenchmark>();
RunBenchmark<SamplingBenchmark>();
Console.WriteLine($"Finished {BenchmarkMode.Garbage} Benchmark");
}
}
Expand Down

0 comments on commit 795242b

Please sign in to comment.