Skip to content

Commit a2738e7

Browse files
adding benchmarks for measuring fallback create and lookup performance (#263)
* adding benchmarks for measuring fallback create and lookup performance * split config specs * moved test case into its own file
1 parent edbca65 commit a2738e7

File tree

2 files changed

+143
-0
lines changed

2 files changed

+143
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="ConfigFallbackLookupSpecs.cs" company="Akka.NET Project">
3+
// Copyright (C) 2013 - 2020 .NET Foundation <https://github.com/akkadotnet/hocon>
4+
// </copyright>
5+
// -----------------------------------------------------------------------
6+
7+
using NBench;
8+
9+
namespace Hocon.Tests.Performance
10+
{
11+
public class ConfigFallbackLookupSpecs
12+
{
13+
private const string LookupFallbackCounterName = "LookupFallbackOp";
14+
15+
private Counter _lookupFallbackOp;
16+
17+
public static readonly Config C1 = @"
18+
akka{
19+
provider = cluster
20+
remote.dot-netty.tcp.port = 8110
21+
}
22+
";
23+
24+
public static readonly Config C2 = @"
25+
akka{
26+
loglevel = DEBUG
27+
remote.dot-netty.tcp.hostname = 0.0.0.0
28+
}
29+
";
30+
31+
public static readonly Config C3 = @"
32+
akka{
33+
remote.dot-netty.tcp.public-hostname = localhost
34+
}
35+
";
36+
37+
private static readonly Config L1 = C1.WithFallback(C2);
38+
39+
private static readonly Config L2 = C1.WithFallback(C3);
40+
41+
[PerfSetup]
42+
public void Setup(BenchmarkContext context)
43+
{
44+
_lookupFallbackOp = context.GetCounter(LookupFallbackCounterName);
45+
}
46+
47+
[PerfBenchmark(
48+
Description = "Tests how quickly Config can be looked up from the second fallback",
49+
RunMode = RunMode.Throughput, NumberOfIterations = 13, RunTimeMilliseconds = 1000,
50+
TestMode = TestMode.Measurement)]
51+
[CounterMeasurement(LookupFallbackCounterName)]
52+
[GcMeasurement(GcMetric.TotalCollections, GcGeneration.AllGc)]
53+
[MemoryMeasurement(MemoryMetric.TotalBytesAllocated)]
54+
public void Lookup_Config_Fallback_2_Deep(BenchmarkContext context)
55+
{
56+
L1.GetString("akka.loglevel");
57+
_lookupFallbackOp.Increment();
58+
}
59+
60+
[PerfBenchmark(
61+
Description = "Tests how quickly Config can be looked up from the third fallback",
62+
RunMode = RunMode.Throughput, NumberOfIterations = 13, RunTimeMilliseconds = 1000,
63+
TestMode = TestMode.Measurement)]
64+
[CounterMeasurement(LookupFallbackCounterName)]
65+
[GcMeasurement(GcMetric.TotalCollections, GcGeneration.AllGc)]
66+
[MemoryMeasurement(MemoryMetric.TotalBytesAllocated)]
67+
public void Lookup_Config_Fallback_3_Deep(BenchmarkContext context)
68+
{
69+
L2.GetString("akka.remote.dot-netty.tcp.public-hostname");
70+
_lookupFallbackOp.Increment();
71+
}
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using NBench;
5+
6+
namespace Hocon.Tests.Performance
7+
{
8+
public class ConfigFallbackSpecs
9+
{
10+
private const string CreateFallbackCounterName = "CreateFallbackOp";
11+
12+
private Counter _createFallbackCounter;
13+
14+
public static readonly Config C1 = @"
15+
akka{
16+
provider = cluster
17+
remote.dot-netty.tcp.port = 8110
18+
}
19+
";
20+
21+
public static readonly Config C2 = @"
22+
akka{
23+
loglevel = DEBUG
24+
remote.dot-netty.tcp.hostname = 0.0.0.0
25+
}
26+
";
27+
28+
public static readonly Config C3 = @"
29+
akka{
30+
remote.dot-netty.tcp.public-hostname = localhost
31+
}
32+
";
33+
34+
private static readonly Config L1 = C1.WithFallback(C2);
35+
36+
private static readonly Config L2 = C1.WithFallback(C3);
37+
38+
[PerfSetup]
39+
public void Setup(BenchmarkContext context)
40+
{
41+
_createFallbackCounter = context.GetCounter(CreateFallbackCounterName);
42+
}
43+
44+
[PerfBenchmark(
45+
Description = "Tests how quickly Config can add a single fallback",
46+
RunMode = RunMode.Throughput, NumberOfIterations = 13, RunTimeMilliseconds = 1000,
47+
TestMode = TestMode.Measurement)]
48+
[CounterMeasurement(CreateFallbackCounterName)]
49+
[GcMeasurement(GcMetric.TotalCollections, GcGeneration.AllGc)]
50+
[MemoryMeasurement(MemoryMetric.TotalBytesAllocated)]
51+
public void Create_Config_Fallback_1_Deep(BenchmarkContext context)
52+
{
53+
var newConfig = C1.WithFallback(C2);
54+
_createFallbackCounter.Increment();
55+
}
56+
57+
[PerfBenchmark(
58+
Description = "Tests how quickly Config can add a two fallbacks",
59+
RunMode = RunMode.Throughput, NumberOfIterations = 13, RunTimeMilliseconds = 1000,
60+
TestMode = TestMode.Measurement)]
61+
[CounterMeasurement(CreateFallbackCounterName)]
62+
[GcMeasurement(GcMetric.TotalCollections, GcGeneration.AllGc)]
63+
[MemoryMeasurement(MemoryMetric.TotalBytesAllocated)]
64+
public void Create_Config_Fallback_2_Deep(BenchmarkContext context)
65+
{
66+
var newConfig = C1.WithFallback(C2).WithFallback(C3);
67+
_createFallbackCounter.Increment();
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)