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

Added Benchmark.NET Performance Tests #578

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/perftests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Performance Tests

on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build-and-perftest:
runs-on: windows-latest # Build on Windows to ensure .NET Framework targets
steps:
- uses: actions/checkout@v4

- name: Run build
run: ./Build.ps1 -SkipTests
shell: pwsh

- name: Run performance tests
run: ./RunPerfTests.ps1
shell: pwsh
20 changes: 11 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
workflow_dispatch:

jobs:
build-and-release:
build-perftest-and-release:
runs-on: windows-latest # Build on Windows to ensure .NET Framework targets
steps:
- uses: actions/checkout@v4
Expand All @@ -35,6 +35,10 @@ jobs:
run: ./Build.ps1 -SkipTests
shell: pwsh

- name: Run performance tests
run: ./RunPerfTests.ps1
shell: pwsh

- name: Get last commit message
id: last_commit
if: success() && github.ref == 'refs/heads/main'
Expand All @@ -47,29 +51,27 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Der Basisname der Dateien basierend auf der Versionsnummer
$baseFileName = "Serilog.Sinks.MSSqlServer.${{ env.VERSION }}"

# Suche die exakten Dateipfade für .nupkg und .snupkg
$nupkgFile = Get-ChildItem -Path "artifacts/$baseFileName*.nupkg" | Select-Object -First 1
$snupkgFile = Get-ChildItem -Path "artifacts/$baseFileName*.snupkg" | Select-Object -First 1
$perfReportSinkFile = Get-ChildItem -Path "artifacts/perftests/Serilog.Sinks.MSSqlServer.PerformanceTests.SinkBenchmarks-report.csv" `
| Select-Object -First 1

# Überprüfe, ob beide Dateien gefunden wurden
if (-not $nupkgFile) { Write-Error "nupkg file not found" ; exit 1 }
if (-not $snupkgFile) { Write-Error "snupkg file not found" ; exit 1 }
if (-not $perfReportSinkFile) { Write-Error "Benchmark report for sink file not found" ; exit 1 }

# Ersetze Backslashes durch Forward Slashes für GitHub CLI-Kompatibilität
$nupkgFilePath = $nupkgFile.FullName -replace '\\', '/'
$snupkgFilePath = $snupkgFile.FullName -replace '\\', '/'
$perfReportSinkFilePath = $perfReportSinkFile.FullName -replace '\\', '/'

# Ausgabe der Dateipfade zu Debugging-Zwecken
Write-Host "Uploading files: $nupkgFilePath, $snupkgFilePath"
Write-Host "Uploading files: $nupkgFilePath, $snupkgFilePath $perfReportPipelineFilePath"

# Erstelle das Release mit den genauen Dateipfaden
gh release create v${{ env.VERSION }} `
--title "v${{ env.VERSION }}" `
--notes "$(Get-Content last_commit_message.txt)" `
$nupkgFilePath $snupkgFilePath
$nupkgFilePath $snupkgFilePath $perfReportSinkFilePath
shell: pwsh

- name: Publish to nuget.org
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ build/
bld/
[Bb]in/
[Oo]bj/
artifacts/
BenchmarkDotNet.Artifacts/

# Roslyn cache directories
*.ide/
Expand Down Expand Up @@ -125,7 +127,7 @@ publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
Expand Down
11 changes: 0 additions & 11 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,6 @@ foreach ($src in Get-ChildItem "$PSScriptRoot/src" -Directory) {
}

if ($SkipTests -eq $false) {
foreach ($test in Get-ChildItem "$PSScriptRoot/test" -Filter "*.PerformanceTests" -Directory) {
Push-Location $test.FullName

echo "build: Building performance test project in $($test.FullName)"

& dotnet build -c Release
if ($LASTEXITCODE -ne 0) { exit 2 }

Pop-Location
}

foreach ($test in Get-ChildItem "$PSScriptRoot/test" -Filter "*.Tests" -Directory) {
Push-Location $test.FullName

Expand Down
51 changes: 26 additions & 25 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="6.0.1" />
<PackageVersion Include="System.Formats.Asn1" Version="8.0.1" />
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.6" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="coverlet.collector" Version="3.2.0" />
<PackageVersion Include="FluentAssertions" Version="6.7.0" />
<PackageVersion Include="Dapper.StrongName" Version="2.0.123" />
<PackageVersion Include="Moq" Version="4.18.2" />
<PackageVersion Include="xunit" Version="2.9.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="Serilog" Version="4.0.0" />
<PackageVersion Include="Serilog.Extensions.Hosting" Version="5.0.1" />
<PackageVersion Include="Serilog.Settings.Configuration" Version="3.4.0" />
</ItemGroup>
</Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="6.0.1" />
<PackageVersion Include="System.Formats.Asn1" Version="8.0.1" />
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.6" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="coverlet.collector" Version="3.2.0" />
<PackageVersion Include="FluentAssertions" Version="6.7.0" />
<PackageVersion Include="Dapper.StrongName" Version="2.0.123" />
<PackageVersion Include="Moq" Version="4.18.2" />
<PackageVersion Include="xunit" Version="2.9.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="Serilog" Version="4.0.0" />
<PackageVersion Include="Serilog.Extensions.Hosting" Version="5.0.1" />
<PackageVersion Include="Serilog.Settings.Configuration" Version="3.4.0" />
</ItemGroup>
</Project>
21 changes: 21 additions & 0 deletions RunPerfTests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Push-Location $PSScriptRoot

$artifactsPath = "$PSScriptRoot\artifacts\perftests"

if (Test-Path "$artifactsPath") {
echo "perf: Cleaning $artifactsPath"
Remove-Item "$artifactsPath" -Force -Recurse
}

New-Item -Path "$artifactsPath" -ItemType Directory

$perfTestProjectPath = "$PSScriptRoot/test/Serilog.Sinks.MSSqlServer.PerformanceTests"
Push-Location "$perfTestProjectPath"

echo "perf: Running performance test project in $perfTestProjectPath"
& dotnet run -c Release

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

Pop-Location
9 changes: 9 additions & 0 deletions serilog-sinks-mssqlserver.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.github\workflows\pr-validation.yml = .github\workflows\pr-validation.yml
README.md = README.md
.github\workflows\release.yml = .github\workflows\release.yml
RunPerfTests.ps1 = RunPerfTests.ps1
.github\workflows\perftests.yml = .github\workflows\perftests.yml
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetStandardDemoLib", "sample\NetStandardDemo\NetStandardDemoLib\NetStandardDemoLib.csproj", "{8E69E31B-61C7-4175-B886-9C2078FCA477}"
Expand All @@ -43,6 +45,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NetStandardDemo", "NetStand
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppConfigDemo", "sample\AppConfigDemo\AppConfigDemo.csproj", "{6BFE1D21-1442-4375-AB69-14160B906A64}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Sinks.MSSqlServer.PerformanceTests", "test\Serilog.Sinks.MSSqlServer.PerformanceTests\Serilog.Sinks.MSSqlServer.PerformanceTests.csproj", "{106A6BAF-F8E4-408B-BB09-391330DA87F2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -81,6 +85,10 @@ Global
{6BFE1D21-1442-4375-AB69-14160B906A64}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BFE1D21-1442-4375-AB69-14160B906A64}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BFE1D21-1442-4375-AB69-14160B906A64}.Release|Any CPU.Build.0 = Release|Any CPU
{106A6BAF-F8E4-408B-BB09-391330DA87F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{106A6BAF-F8E4-408B-BB09-391330DA87F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{106A6BAF-F8E4-408B-BB09-391330DA87F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{106A6BAF-F8E4-408B-BB09-391330DA87F2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -95,6 +103,7 @@ Global
{F908C46D-E72E-41E4-975D-73733294F93F} = {7B2B80DE-427A-4FEC-A7CE-7AD81FED73DE}
{7B2B80DE-427A-4FEC-A7CE-7AD81FED73DE} = {AA346332-5BAF-47F1-B8FB-7600ED61265D}
{6BFE1D21-1442-4375-AB69-14160B906A64} = {AA346332-5BAF-47F1-B8FB-7600ED61265D}
{106A6BAF-F8E4-408B-BB09-391330DA87F2} = {F02D6513-6F45-452E-85A0-41A872A2C1F8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AAA6BF8D-7B53-4A5F-A79A-D1B306383B45}
Expand Down
17 changes: 17 additions & 0 deletions test/Serilog.Sinks.MSSqlServer.PerformanceTests/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using BenchmarkDotNet.Running;

namespace Serilog.Sinks.MSSqlServer.PerformanceTests;

/// <summary>
/// Wrappers that make it easy to run benchmark suites through the <c>dotnet test</c> runner.
/// </summary>
/// <example>
/// <code>dotnet test -c Release --filter "FullyQualifiedName=Serilog.Sinks.MSSqlServer.PerformanceTests.Harness.Pipeline"</code>
/// </example>
public class Program
{
public static void Main()
{
BenchmarkRunner.Run<SinkBenchmarks>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AssemblyName>Serilog.Sinks.MSSqlServer.PerformanceTests</AssemblyName>
<OutputType>Exe</OutputType>
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<RuntimeIdentifiers>win</RuntimeIdentifiers>
<PlatformTarget>AnyCPU</PlatformTarget>
<AnalysisLevel>6.0-recommended</AnalysisLevel>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Serilog.Sinks.MSSqlServer\Serilog.Sinks.MSSqlServer.csproj"/>
<PackageReference Include="BenchmarkDotNet" />
</ItemGroup>

</Project>
46 changes: 46 additions & 0 deletions test/Serilog.Sinks.MSSqlServer.PerformanceTests/SinkBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using BenchmarkDotNet.Attributes;

namespace Serilog.Sinks.MSSqlServer.PerformanceTests;

[MemoryDiagnoser]
public class SinkBenchmarks
{
private const string _connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Database=LogTest;Integrated Security=SSPI;Encrypt=False;";
private const string _schemaName = "dbo";
private const string _tableName = "LogEvents";
private ILogger _log = null!;

[GlobalSetup]
public void Setup()
{
var options = new ColumnOptions();
options.Store.Add(StandardColumn.LogEvent);
_log = new LoggerConfiguration()
.WriteTo.MSSqlServer(_connectionString,
sinkOptions: new MSSqlServerSinkOptions
{
TableName = _tableName,
SchemaName = _schemaName,
AutoCreateSqlTable = true,
AutoCreateSqlDatabase = true
},
appConfiguration: null,
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Verbose,
formatProvider: null,
columnOptions: options,
columnOptionsSection: null)
.CreateLogger();
}

[Benchmark]
public void EmitLogEvent()
{
_log.Information("Hello, {Name}!", "World");
}

[Benchmark]
public void IntProperties()
{
_log.Information("Hello, {A} {B} {C}!", 1, 2, 3);
}
}
Loading