Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

using DataArc.Core;
using DataArc.EntityFrameworkCore.Demo.Persistence;
using DataArc.EntityFrameworkCore.Demo.Persistence.Database.Creator;
using DataArc.EntityFrameworkCore.Demo.Persistence.Database.DBContexts;
using DataArc.EntityFrameworkCore.Demo.Persistence.Database.DBModels;
using DataArc.EntityFrameworkCore.Demo.Persistence.Utils;
Expand All @@ -28,16 +29,16 @@ public class RawEmployeeBulkDataBenchmark
private const int MaxRecordCount = 1_000_000;

private IServiceProvider? _serviceProvider;
private IDatabaseCreator? _databaseCreator;
private IReadOnlyCollection<IDatabaseCreator> _databaseCreators = [];
private ICommandFactory? _commandFactory;

private List<Employee> _allEmployees = [];
private List<Employee> _benchmarkEmployees = [];

[Params(250_000, 500_000, 1_000_000)]
[Params(62_500, 125_000, 250_000)]
public int RecordCount { get; set; }

[Params(250_000)]
[Params(62_500)]
public int BulkBatchSize { get; set; }

[GlobalSetup]
Expand All @@ -47,7 +48,14 @@ public void GlobalSetup()
.AddPersistence()
.BuildServiceProvider();

_databaseCreator = _serviceProvider.GetRequiredService<IDatabaseCreator>();
_databaseCreators =
[
_serviceProvider.GetRequiredService<IFinanceDbCreator>(),
_serviceProvider.GetRequiredService<IHrDbCreator>(),
_serviceProvider.GetRequiredService<IItDbCreator>(),
_serviceProvider.GetRequiredService<IOperationsDbCreator>()
];

_commandFactory = _serviceProvider.GetRequiredService<ICommandFactory>();

_allEmployees = SeedDataGenerator
Expand All @@ -58,14 +66,22 @@ public void GlobalSetup()
[IterationSetup]
public void IterationSetup()
{
if (_databaseCreator == null)
throw new InvalidOperationException($"{nameof(IDatabaseCreator)} was not resolved.");
if (_databaseCreators.Count == 0)
throw new InvalidOperationException("Benchmark database creators were not resolved.");

if (!_databaseCreator.EnsureDeleted())
throw new InvalidOperationException("Failed to delete benchmark databases.");
foreach (var databaseCreator in _databaseCreators)
{
if (!databaseCreator.EnsureDeleted())
throw new InvalidOperationException(
$"Failed to delete benchmark database using {databaseCreator.GetType().Name}.");
}

if (!_databaseCreator.EnsureCreated())
throw new InvalidOperationException("Failed to create benchmark databases.");
foreach (var databaseCreator in _databaseCreators)
{
if (!databaseCreator.EnsureCreated())
throw new InvalidOperationException(
$"Failed to create benchmark database using {databaseCreator.GetType().Name}.");
}

_benchmarkEmployees = _allEmployees
.Take(RecordCount)
Expand Down Expand Up @@ -117,10 +133,12 @@ public async Task<int> ExecuteParallelBulkInsertAsync()
[GlobalCleanup]
public void GlobalCleanup()
{
//_databaseCreator?.EnsureDeleted();
// Keep benchmark databases for inspection after the run.
}
}

#region BenchMarkDotnetSetup

public sealed class BenchmarkConfig : ManualConfig
{
public BenchmarkConfig()
Expand All @@ -132,28 +150,18 @@ public BenchmarkConfig()
public sealed class TotalInsertedRecordsColumn : IColumn
{
private readonly int _destinationContextCount;

public TotalInsertedRecordsColumn(int destinationContextCount)
{
_destinationContextCount = destinationContextCount;
}

public string Id => nameof(TotalInsertedRecordsColumn);

public string ColumnName => "Total Inserted Records";

public bool AlwaysShow => true;

public ColumnCategory Category => ColumnCategory.Params;

public int PriorityInCategory => 0;

public bool IsNumeric => true;

public UnitType UnitType => UnitType.Dimensionless;

public string Legend => "Total records inserted across all participating DbContexts.";

public string GetValue(Summary summary, BenchmarkCase benchmarkCase)
{
var recordCountParameter = benchmarkCase.Parameters.Items
Expand All @@ -164,23 +172,22 @@ public string GetValue(Summary summary, BenchmarkCase benchmarkCase)

return totalInsertedRecords.ToString("N0");
}

public string GetValue(
Summary summary,
BenchmarkCase benchmarkCase,
SummaryStyle style)
{
return GetValue(summary, benchmarkCase);
}

public bool IsAvailable(Summary summary)
{
return true;
}

public bool IsDefault(Summary summary, BenchmarkCase benchmarkCase)
{
return false;
}
}

#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using DataArc.Core;
using Microsoft.EntityFrameworkCore.Storage;
using DataArc.EntityFrameworkCore.Demo.Persistence.Database.DBContexts;

namespace DataArc.EntityFrameworkCore.Demo.Persistence.Database.Creator
{
public interface IFinanceDbCreator : IDatabaseCreator
{

}

internal class FinanceDbCreator : IFinanceDbCreator
{
private readonly IDatabaseFactory _databaseFactory;

public FinanceDbCreator(IDatabaseFactory databaseFactory)
{
_databaseFactory = databaseFactory;
}

public bool CanConnect()
{
throw new NotImplementedException();
}

public Task<bool> CanConnectAsync(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}

public bool EnsureCreated()
{
var dbBuilder = _databaseFactory.CreateDatabaseBuilder();

var db = dbBuilder
.IncludeDbContext<FinanceDbContext>()
.Build(generateScripts: true, applyChanges: true);

db.ExecuteCreate();
return true;
}

public Task<bool> EnsureCreatedAsync(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}

public bool EnsureDeleted()
{
var dbBuilder = _databaseFactory.CreateDatabaseBuilder();

var db = dbBuilder
.IncludeDbContext<FinanceDbContext>()
.Build(generateScripts: true, applyChanges: true);

db.ExecuteDrop();
return true;
}

public Task<bool> EnsureDeletedAsync(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using DataArc.Core;
using Microsoft.EntityFrameworkCore.Storage;
using DataArc.EntityFrameworkCore.Demo.Persistence.Database.DBContexts;

namespace DataArc.EntityFrameworkCore.Demo.Persistence.Database.Creator
{
public interface IHrDbCreator : IDatabaseCreator
{

}

internal class HrDbCreator : IHrDbCreator
{
private readonly IDatabaseFactory _databaseFactory;

public HrDbCreator(IDatabaseFactory databaseFactory)
{
_databaseFactory = databaseFactory;
}

public bool CanConnect()
{
throw new NotImplementedException();
}

public Task<bool> CanConnectAsync(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}

public bool EnsureCreated()
{
var dbBuilder = _databaseFactory.CreateDatabaseBuilder();

var db = dbBuilder
.IncludeDbContext<HrDbContext>()
.Build(generateScripts: true, applyChanges: true);

db.ExecuteCreate();
return true;
}

public Task<bool> EnsureCreatedAsync(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}

public bool EnsureDeleted()
{
var dbBuilder = _databaseFactory.CreateDatabaseBuilder();

var db = dbBuilder
.IncludeDbContext<HrDbContext>()
.Build(generateScripts: true, applyChanges: true);

db.ExecuteDrop();
return true;
}

public Task<bool> EnsureDeletedAsync(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using DataArc.Core;
using Microsoft.EntityFrameworkCore.Storage;
using DataArc.EntityFrameworkCore.Demo.Persistence.Database.DBContexts;

namespace DataArc.EntityFrameworkCore.Demo.Persistence.Database.Creator
{
public interface IItDbCreator : IDatabaseCreator
{

}

public class ItDbCreator : IItDbCreator
{
private readonly IDatabaseFactory _databaseFactory;

public ItDbCreator(IDatabaseFactory databaseFactory)
{
_databaseFactory = databaseFactory;
}

public bool CanConnect()
{
throw new NotImplementedException();
}

public Task<bool> CanConnectAsync(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}

public bool EnsureCreated()
{
var dbBuilder = _databaseFactory.CreateDatabaseBuilder();

var db = dbBuilder
.IncludeDbContext<ItDbContext>()
.Build(generateScripts: true, applyChanges: true);

db.ExecuteCreate();
return true;
}

public Task<bool> EnsureCreatedAsync(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}

public bool EnsureDeleted()
{
var dbBuilder = _databaseFactory.CreateDatabaseBuilder();

var db = dbBuilder
.IncludeDbContext<ItDbContext>()
.Build(generateScripts: true, applyChanges: true);

db.ExecuteDrop();
return true;
}

public Task<bool> EnsureDeletedAsync(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
}
}
Loading
Loading