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
8 changes: 7 additions & 1 deletion src/RESPite.Benchmark/BenchmarkBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public enum PipelineStrategy
public bool Loop { get; }
public bool Quiet { get; }
public int ClientCount { get; } = 50;

// the number of connections in use; implementations that create their connections eagerly override
// this with the number they ACTUALLY created, rather than the number the flags asked for -- so that
// a banner cannot report a connection topology that the implementation did not actually deliver
public virtual int ConnectionCount => Multiplexed ? 1 : ClientCount;

private int _operationsPerClient;
public int OperationsPerClient(int divisor = 1) => _operationsPerClient / divisor;

Expand Down Expand Up @@ -486,7 +492,7 @@ private async Task RunAsyncCore<T>(
else
{
Console.Write(
$"====== {name}{description}{auxReason} ====== (clients: {ClientCount:#,##0}, ops: {TotalOperations(divisor):#,##0}");
$"====== {name}{description}{auxReason} ====== (clients: {ClientCount:#,##0}, conns: {ConnectionCount:#,##0}, ops: {TotalOperations(divisor):#,##0}");
if (Multiplexed)
{
Console.Write(", mux");
Expand Down
32 changes: 25 additions & 7 deletions src/RESPite.Benchmark/OldCoreBenchmarkBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,28 @@ namespace RESPite.Benchmark;

public abstract class OldCoreBenchmarkBase : BenchmarkBase<IDatabaseAsync>
{
private readonly IConnectionMultiplexer _connectionMultiplexer;
private readonly IDatabase _client;
private readonly IConnectionMultiplexer[] _connectionMultiplexers;
private readonly IDatabase[] _clients;
private readonly KeyValuePair<RedisKey, RedisValue>[] _pairs;

public OldCoreBenchmarkBase(string[] args) : base(args)
{
// ReSharper disable once VirtualMemberCallInConstructor
_connectionMultiplexer = Create(Port);
_client = _connectionMultiplexer.GetDatabase();
// a multiplexer is one connection per endpoint by design, so "each client has a separate
// connection" means a multiplexer each; +m is the documented opt-out, sharing a single one
var connectionCount = Multiplexed ? 1 : ClientCount;
_connectionMultiplexers = new IConnectionMultiplexer[connectionCount];
for (var i = 0; i < connectionCount; i++)
{
// ReSharper disable once VirtualMemberCallInConstructor
_connectionMultiplexers[i] = Create(Port);
}

_clients = new IDatabase[ClientCount];
for (var i = 0; i < ClientCount; i++)
{
_clients[i] = _connectionMultiplexers[i % connectionCount].GetDatabase();
}

_pairs = new KeyValuePair<RedisKey, RedisValue>[10];

for (var i = 0; i < 10; i++)
Expand All @@ -26,6 +39,8 @@ public OldCoreBenchmarkBase(string[] args) : base(args)
}
}

public override int ConnectionCount => _connectionMultiplexers.Length;

protected abstract IConnectionMultiplexer Create(int port);

protected override async Task OnCleanupAsync(IDatabaseAsync client)
Expand All @@ -40,10 +55,13 @@ protected override async Task OnCleanupAsync(IDatabaseAsync client)

public override void Dispose()
{
_connectionMultiplexer.Dispose();
foreach (var connectionMultiplexer in _connectionMultiplexers)
{
connectionMultiplexer.Dispose();
}
}

protected override IDatabaseAsync GetClient(int index) => _client;
protected override IDatabaseAsync GetClient(int index) => _clients[index];
protected override Task DeleteAsync(IDatabaseAsync client, string key) => client.KeyDeleteAsync(key);

public override async Task RunAll()
Expand Down
3 changes: 2 additions & 1 deletion src/RESPite.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ private static async Task<int> Main(string[] args)
{
if (benchmarks.Count > 1 || isFirst)
{
Console.WriteLine($"### {bench} ###");
Console.WriteLine(
$"### {bench} (clients: {bench.ClientCount:#,##0}, conns: {bench.ConnectionCount:#,##0}) ###");
isFirst = false;
}

Expand Down
Loading