Reformat / cleanup
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using System.Text;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Configs;
|
||||
using BenchmarkDotNet.Jobs;
|
||||
using ZB.MOM.WW.CBDD.Bson;
|
||||
using ZB.MOM.WW.CBDD.Core.Collections;
|
||||
using ZB.MOM.WW.CBDD.Core.Compression;
|
||||
@@ -16,28 +16,29 @@ namespace ZB.MOM.WW.CBDD.Tests.Benchmark;
|
||||
[JsonExporterAttribute.Full]
|
||||
public class MixedWorkloadBenchmarks
|
||||
{
|
||||
private readonly List<ObjectId> _activeIds = [];
|
||||
private DocumentCollection<Person> _collection = null!;
|
||||
|
||||
private string _dbPath = string.Empty;
|
||||
private int _nextValueSeed;
|
||||
private StorageEngine _storage = null!;
|
||||
private BenchmarkTransactionHolder _transactionHolder = null!;
|
||||
private string _walPath = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether periodic online compaction is enabled.
|
||||
/// Gets or sets whether periodic online compaction is enabled.
|
||||
/// </summary>
|
||||
[Params(false, true)]
|
||||
public bool PeriodicCompaction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of operations per benchmark iteration.
|
||||
/// Gets or sets the number of operations per benchmark iteration.
|
||||
/// </summary>
|
||||
[Params(800)]
|
||||
public int Operations { get; set; }
|
||||
|
||||
private string _dbPath = string.Empty;
|
||||
private string _walPath = string.Empty;
|
||||
private StorageEngine _storage = null!;
|
||||
private BenchmarkTransactionHolder _transactionHolder = null!;
|
||||
private DocumentCollection<Person> _collection = null!;
|
||||
private readonly List<ObjectId> _activeIds = [];
|
||||
private int _nextValueSeed;
|
||||
|
||||
/// <summary>
|
||||
/// Prepares benchmark storage and seed data for each iteration.
|
||||
/// Prepares benchmark storage and seed data for each iteration.
|
||||
/// </summary>
|
||||
[IterationSetup]
|
||||
public void Setup()
|
||||
@@ -71,7 +72,7 @@ public class MixedWorkloadBenchmarks
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cleans up benchmark resources for each iteration.
|
||||
/// Cleans up benchmark resources for each iteration.
|
||||
/// </summary>
|
||||
[IterationCleanup]
|
||||
public void Cleanup()
|
||||
@@ -84,7 +85,7 @@ public class MixedWorkloadBenchmarks
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Benchmarks a mixed insert/update/delete workload.
|
||||
/// Benchmarks a mixed insert/update/delete workload.
|
||||
/// </summary>
|
||||
[Benchmark(Baseline = true)]
|
||||
[BenchmarkCategory("MixedWorkload")]
|
||||
@@ -94,7 +95,7 @@ public class MixedWorkloadBenchmarks
|
||||
|
||||
for (var i = 1; i <= Operations; i++)
|
||||
{
|
||||
var mode = i % 5;
|
||||
int mode = i % 5;
|
||||
if (mode is 0 or 1)
|
||||
{
|
||||
var id = _collection.Insert(CreatePerson(_nextValueSeed++));
|
||||
@@ -104,7 +105,7 @@ public class MixedWorkloadBenchmarks
|
||||
{
|
||||
if (_activeIds.Count > 0)
|
||||
{
|
||||
var idx = random.Next(_activeIds.Count);
|
||||
int idx = random.Next(_activeIds.Count);
|
||||
var id = _activeIds[idx];
|
||||
var current = _collection.FindById(id);
|
||||
if (current != null)
|
||||
@@ -119,20 +120,16 @@ public class MixedWorkloadBenchmarks
|
||||
{
|
||||
if (_activeIds.Count > 100)
|
||||
{
|
||||
var idx = random.Next(_activeIds.Count);
|
||||
int idx = random.Next(_activeIds.Count);
|
||||
var id = _activeIds[idx];
|
||||
_collection.Delete(id);
|
||||
_activeIds.RemoveAt(idx);
|
||||
}
|
||||
}
|
||||
|
||||
if (i % 50 == 0)
|
||||
{
|
||||
_transactionHolder.CommitAndReset();
|
||||
}
|
||||
if (i % 50 == 0) _transactionHolder.CommitAndReset();
|
||||
|
||||
if (PeriodicCompaction && i % 200 == 0)
|
||||
{
|
||||
_storage.RunOnlineCompactionPass(new CompactionOptions
|
||||
{
|
||||
OnlineMode = true,
|
||||
@@ -141,7 +138,6 @@ public class MixedWorkloadBenchmarks
|
||||
MaxOnlineDuration = TimeSpan.FromMilliseconds(120),
|
||||
EnableTailTruncation = true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_transactionHolder.CommitAndReset();
|
||||
@@ -155,7 +151,7 @@ public class MixedWorkloadBenchmarks
|
||||
Id = ObjectId.NewObjectId(),
|
||||
FirstName = $"First_{seed}",
|
||||
LastName = $"Last_{seed}",
|
||||
Age = 18 + (seed % 60),
|
||||
Age = 18 + seed % 60,
|
||||
Bio = BuildPayload(seed),
|
||||
CreatedAt = DateTime.UnixEpoch.AddSeconds(seed),
|
||||
Balance = seed,
|
||||
@@ -170,7 +166,7 @@ public class MixedWorkloadBenchmarks
|
||||
|
||||
private static string BuildPayload(int seed)
|
||||
{
|
||||
var builder = new System.Text.StringBuilder(1800);
|
||||
var builder = new StringBuilder(1800);
|
||||
for (var i = 0; i < 64; i++)
|
||||
{
|
||||
builder.Append("mixed-");
|
||||
@@ -182,4 +178,4 @@ public class MixedWorkloadBenchmarks
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user