Skip to content

Commit 610288e

Browse files
authored
Merge pull request #582 from ckadluba/benchmark-tests
Improved Benchmark Tests
2 parents 5787666 + af9de4a commit 610288e

File tree

11 files changed

+272
-21
lines changed

11 files changed

+272
-21
lines changed

.github/workflows/perftests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
shell: pwsh
1616

1717
- name: Run performance tests
18-
run: ./RunPerfTests.ps1
18+
run: ./RunPerfTests.ps1 -Filter ${{ secrets.PERF_TESTS_FILTER }}
1919
shell: pwsh
2020

2121
- name: Upload perf test results artifact

.github/workflows/release.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
shell: pwsh
3737

3838
- name: Run performance tests
39-
run: ./RunPerfTests.ps1
39+
run: ./RunPerfTests.ps1 -Filter "*QuickBenchmarks*"
4040
shell: pwsh
4141

4242
- name: Get last commit message
@@ -55,28 +55,30 @@ jobs:
5555
5656
$nupkgFile = Get-ChildItem -Path "artifacts/$baseFileName*.nupkg" | Select-Object -First 1
5757
$snupkgFile = Get-ChildItem -Path "artifacts/$baseFileName*.snupkg" | Select-Object -First 1
58-
$perfReportSinkFile = Get-ChildItem -Path "artifacts/perftests/Serilog.Sinks.MSSqlServer.PerformanceTests.SinkBenchmarks-report.csv" `
58+
$perfReportSinkFile = Get-ChildItem -Path "artifacts/perftests/Serilog.Sinks.MSSqlServer.PerformanceTests.SinkQuickBenchmarks-report.csv" `
59+
| Select-Object -First 1
60+
$perfReportAuditSinkFile = Get-ChildItem -Path "artifacts/perftests/Serilog.Sinks.MSSqlServer.PerformanceTests.AuditSinkQuickBenchmarks-report.csv" `
5961
| Select-Object -First 1
6062
6163
if (-not $nupkgFile) { Write-Error "nupkg file not found" ; exit 1 }
6264
if (-not $snupkgFile) { Write-Error "snupkg file not found" ; exit 1 }
6365
if (-not $perfReportSinkFile) { Write-Error "Benchmark report for sink file not found" ; exit 1 }
66+
if (-not $perfReportAuditSinkFile) { Write-Error "Benchmark report for audit sink file not found" ; exit 1 }
6467
6568
$nupkgFilePath = $nupkgFile.FullName -replace '\\', '/'
6669
$snupkgFilePath = $snupkgFile.FullName -replace '\\', '/'
6770
$perfReportSinkFilePath = $perfReportSinkFile.FullName -replace '\\', '/'
71+
$perfReportAuditSinkFilePath = $perfReportAuditSinkFile.FullName -replace '\\', '/'
6872
69-
Write-Host "Uploading files: $nupkgFilePath, $snupkgFilePath $perfReportPipelineFilePath"
73+
Write-Host "Uploading files: $nupkgFilePath, $snupkgFilePath $perfReportSinkFilePath $perfReportAuditSinkFilePath"
7074
7175
gh release create v${{ env.VERSION }} `
7276
--title "v${{ env.VERSION }}" `
7377
--notes "$(Get-Content last_commit_message.txt)" `
74-
$nupkgFilePath $snupkgFilePath $perfReportSinkFilePath
78+
$nupkgFilePath $snupkgFilePath $perfReportSinkFilePath $perfReportAuditSinkFilePath
7579
shell: pwsh
7680

7781
- name: Publish to nuget.org
78-
env:
79-
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
8082
run: |
8183
nuget push artifacts\*.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_API_KEY }}
8284
shell: pwsh

RunPerfTests.ps1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
Push-Location $PSScriptRoot
1+
[CmdletBinding()]
2+
param (
3+
[Parameter(Mandatory = $false)]
4+
[string]
5+
$Filter = "*"
6+
)
7+
8+
echo "perf: Performance tests started with Filter = $Filter"
9+
10+
Push-Location $PSScriptRoot
211

312
$artifactsPath = "$PSScriptRoot\artifacts\perftests"
413

@@ -13,7 +22,7 @@ $perfTestProjectPath = "$PSScriptRoot/test/Serilog.Sinks.MSSqlServer.Performance
1322
Push-Location "$perfTestProjectPath"
1423

1524
echo "perf: Running performance test project in $perfTestProjectPath"
16-
& dotnet run -c Release
25+
& dotnet run -c Release -- -f $Filter
1726

1827
cp ".\BenchmarkDotNet.Artifacts\results\*.*" "$artifactsPath\"
1928
Pop-Location

src/Serilog.Sinks.MSSqlServer/Serilog.Sinks.MSSqlServer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474

7575
<ItemGroup>
7676
<InternalsVisibleTo Include="$(AssemblyName).Tests" PublicKey="0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b81894191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066b19485ec" />
77+
<InternalsVisibleTo Include="$(AssemblyName).PerformanceTests" PublicKey="0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b81894191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066b19485ec" />
7778
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" PublicKey="0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7" />
7879
</ItemGroup>
7980

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using BenchmarkDotNet.Attributes;
5+
6+
namespace Serilog.Sinks.MSSqlServer.PerformanceTests.Misc;
7+
8+
[MemoryDiagnoser]
9+
public class AuditSinkExtendedBenchmarks
10+
{
11+
private const string _connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Database=LogAuditExtPerfTest;Integrated Security=SSPI;Encrypt=False;";
12+
private const string _schemaName = "dbo";
13+
private const string _tableName = "LogEvents";
14+
private ILogger _log = null!;
15+
private DateTimeOffset _additionalColumn7;
16+
17+
18+
[Params("String One", "String Two")]
19+
public string AdditionalColumn1 { get; set; }
20+
21+
[Params(1, 2)]
22+
public int AdditionalColumn2 { get; set; }
23+
24+
25+
[GlobalSetup]
26+
public void Setup()
27+
{
28+
var options = new ColumnOptions
29+
{
30+
AdditionalColumns = new List<SqlColumn>
31+
{
32+
new() { DataType = SqlDbType.NVarChar, ColumnName = "AdditionalColumn1", DataLength = 40 },
33+
new() { DataType = SqlDbType.Int, ColumnName = "AdditionalColumn2" },
34+
new() { DataType = SqlDbType.Int, ColumnName = "AdditionalColumn3" },
35+
new() { DataType = SqlDbType.Int, ColumnName = "AdditionalColumn4" },
36+
new() { DataType = SqlDbType.Int, ColumnName = "AdditionalColumn5" },
37+
new() { DataType = SqlDbType.Int, ColumnName = "AdditionalColumn6" },
38+
new() { DataType = SqlDbType.DateTimeOffset, ColumnName = "AdditionalColumn7" }
39+
}
40+
};
41+
options.Store.Add(StandardColumn.LogEvent);
42+
_log = new LoggerConfiguration()
43+
.AuditTo.MSSqlServer(_connectionString,
44+
sinkOptions: new MSSqlServerSinkOptions
45+
{
46+
TableName = _tableName,
47+
SchemaName = _schemaName,
48+
AutoCreateSqlTable = true,
49+
AutoCreateSqlDatabase = true
50+
},
51+
appConfiguration: null,
52+
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Verbose,
53+
formatProvider: null,
54+
columnOptions: options,
55+
columnOptionsSection: null)
56+
.CreateLogger();
57+
58+
_additionalColumn7 = new DateTimeOffset(2024, 01, 01, 00, 00, 00, TimeSpan.FromHours(1));
59+
}
60+
61+
[Benchmark]
62+
public void EmitComplexLogEvent()
63+
{
64+
_log.Information("Hello, {AdditionalColumn1} {AdditionalColumn2} {AdditionalColumn3} {AdditionalColumn4} {AdditionalColumn5} {AdditionalColumn6} {AdditionalColumn7}!",
65+
AdditionalColumn1, AdditionalColumn2, 3, 4, 5, 6, _additionalColumn7);
66+
}
67+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using BenchmarkDotNet.Attributes;
2+
3+
namespace Serilog.Sinks.MSSqlServer.PerformanceTests.Misc;
4+
5+
[MemoryDiagnoser]
6+
public class AuditSinkQuickBenchmarks
7+
{
8+
private const string _connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Database=LogAuditQuickPerfTest;Integrated Security=SSPI;Encrypt=False;";
9+
private const string _schemaName = "dbo";
10+
private const string _tableName = "LogEvents";
11+
private ILogger _log = null!;
12+
13+
[GlobalSetup]
14+
public void Setup()
15+
{
16+
var options = new ColumnOptions();
17+
options.Store.Add(StandardColumn.LogEvent);
18+
_log = new LoggerConfiguration()
19+
.AuditTo.MSSqlServer(_connectionString,
20+
sinkOptions: new MSSqlServerSinkOptions
21+
{
22+
TableName = _tableName,
23+
SchemaName = _schemaName,
24+
AutoCreateSqlTable = true,
25+
AutoCreateSqlDatabase = true
26+
},
27+
appConfiguration: null,
28+
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Verbose,
29+
formatProvider: null,
30+
columnOptions: options,
31+
columnOptionsSection: null)
32+
.CreateLogger();
33+
}
34+
35+
[Benchmark]
36+
public void EmitLogEvent()
37+
{
38+
_log.Information("Hello, {Name}!", "World");
39+
}
40+
41+
[Benchmark]
42+
public void IntProperties()
43+
{
44+
_log.Information("Hello, {A} {B} {C}!", 1, 2, 3);
45+
}
46+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using BenchmarkDotNet.Attributes;
5+
6+
namespace Serilog.Sinks.MSSqlServer.PerformanceTests.Misc;
7+
8+
[MemoryDiagnoser]
9+
public class SinkExtendedBenchmarks
10+
{
11+
private const string _connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Database=LogExtPerfTest;Integrated Security=SSPI;Encrypt=False;";
12+
private const string _schemaName = "dbo";
13+
private const string _tableName = "LogEvents";
14+
private ILogger _log = null!;
15+
private DateTimeOffset _additionalColumn7;
16+
17+
18+
[Params("String One", "String Two")]
19+
public string AdditionalColumn1 { get; set; }
20+
21+
[Params(1, 2)]
22+
public int AdditionalColumn2 { get; set; }
23+
24+
25+
[GlobalSetup]
26+
public void Setup()
27+
{
28+
var options = new ColumnOptions
29+
{
30+
AdditionalColumns = new List<SqlColumn>
31+
{
32+
new() { DataType = SqlDbType.NVarChar, ColumnName = "AdditionalColumn1", DataLength = 40 },
33+
new() { DataType = SqlDbType.Int, ColumnName = "AdditionalColumn2" },
34+
new() { DataType = SqlDbType.Int, ColumnName = "AdditionalColumn3" },
35+
new() { DataType = SqlDbType.Int, ColumnName = "AdditionalColumn4" },
36+
new() { DataType = SqlDbType.Int, ColumnName = "AdditionalColumn5" },
37+
new() { DataType = SqlDbType.Int, ColumnName = "AdditionalColumn6" },
38+
new() { DataType = SqlDbType.DateTimeOffset, ColumnName = "AdditionalColumn7" }
39+
}
40+
};
41+
options.Store.Add(StandardColumn.LogEvent);
42+
_log = new LoggerConfiguration()
43+
.WriteTo.MSSqlServer(_connectionString,
44+
sinkOptions: new MSSqlServerSinkOptions
45+
{
46+
TableName = _tableName,
47+
SchemaName = _schemaName,
48+
AutoCreateSqlTable = true,
49+
AutoCreateSqlDatabase = true
50+
},
51+
appConfiguration: null,
52+
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Verbose,
53+
formatProvider: null,
54+
columnOptions: options,
55+
columnOptionsSection: null)
56+
.CreateLogger();
57+
58+
_additionalColumn7 = new DateTimeOffset(2024, 01, 01, 00, 00, 00, TimeSpan.FromHours(1));
59+
}
60+
61+
[Benchmark]
62+
public void EmitComplexLogEvent()
63+
{
64+
_log.Information("Hello, {AdditionalColumn1} {AdditionalColumn2} {AdditionalColumn3} {AdditionalColumn4} {AdditionalColumn5} {AdditionalColumn6} {AdditionalColumn7}!",
65+
AdditionalColumn1, AdditionalColumn2,3, 4, 5, 6, _additionalColumn7);
66+
}
67+
}

test/Serilog.Sinks.MSSqlServer.PerformanceTests/SinkBenchmarks.cs renamed to test/Serilog.Sinks.MSSqlServer.PerformanceTests/Misc/SinkQuickBenchmarks.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using BenchmarkDotNet.Attributes;
22

3-
namespace Serilog.Sinks.MSSqlServer.PerformanceTests;
3+
namespace Serilog.Sinks.MSSqlServer.PerformanceTests.Misc;
44

55
[MemoryDiagnoser]
6-
public class SinkBenchmarks
6+
public class SinkQuickBenchmarks
77
{
8-
private const string _connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Database=LogTest;Integrated Security=SSPI;Encrypt=False;";
8+
private const string _connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Database=LogQuickPerfTest;Integrated Security=SSPI;Encrypt=False;";
99
private const string _schemaName = "dbo";
1010
private const string _tableName = "LogEvents";
1111
private ILogger _log = null!;

test/Serilog.Sinks.MSSqlServer.PerformanceTests/Program.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22

33
namespace Serilog.Sinks.MSSqlServer.PerformanceTests;
44

5-
/// <summary>
6-
/// Wrappers that make it easy to run benchmark suites through the <c>dotnet test</c> runner.
7-
/// </summary>
8-
/// <example>
9-
/// <code>dotnet test -c Release --filter "FullyQualifiedName=Serilog.Sinks.MSSqlServer.PerformanceTests.Harness.Pipeline"</code>
10-
/// </example>
11-
public class Program
5+
public static class Program
126
{
13-
public static void Main()
7+
public static void Main(string[] args)
148
{
15-
BenchmarkRunner.Run<SinkBenchmarks>();
9+
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
1610
}
1711
}

test/Serilog.Sinks.MSSqlServer.PerformanceTests/Serilog.Sinks.MSSqlServer.PerformanceTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<ItemGroup>
1616
<ProjectReference Include="..\..\src\Serilog.Sinks.MSSqlServer\Serilog.Sinks.MSSqlServer.csproj"/>
1717
<PackageReference Include="BenchmarkDotNet" />
18+
<PackageReference Include="Moq" />
1819
</ItemGroup>
1920

2021
</Project>

0 commit comments

Comments
 (0)