Skip to content

Commit

Permalink
Added benchmark.
Browse files Browse the repository at this point in the history
Resolved PR comments.
  • Loading branch information
Yoganand Rajasekaran authored and yrajas committed Apr 20, 2024
1 parent bc39938 commit 88ceb33
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 10 deletions.
69 changes: 69 additions & 0 deletions benchmark/BDN.benchmark/RecoveryBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using Embedded.perftest;
using Garnet.server;

namespace BDN.benchmark
{
public class CustomConfig : ManualConfig
{
public CustomConfig()
{
AddColumn(StatisticColumn.Mean);
AddColumn(StatisticColumn.StdDev);
AddColumn(StatisticColumn.Median);
AddColumn(StatisticColumn.P90);
AddColumn(StatisticColumn.P95);
}
}

[Config(typeof(CustomConfig))]
public class RecoveryBenchmark
{
[ParamsSource(nameof(CommandLineArgsProvider))]
public string LogDir { get; set; }

public IEnumerable<string> CommandLineArgsProvider()
{
// Return the command line arguments as an enumerable
return Environment.GetCommandLineArgs().Skip(1);
}

[Params("100m")]
public string MemorySize { get; set; }

EmbeddedRespServer server;

[IterationSetup]
public void Setup()
{
Console.WriteLine($"LogDir: {LogDir}");
server = new EmbeddedRespServer(new GarnetServerOptions()
{
EnableStorageTier = true,
LogDir = LogDir,
CheckpointDir = LogDir,
IndexSize = "1m",
DisableObjects = true,
MemorySize = MemorySize,
PageSize = "32k",
});
}

[IterationCleanup]
public void Cleanup()
{
server.Dispose();
}

[Benchmark]
public void Recover()
{
server.StoreWrapper.RecoverCheckpoint();
}
}
}
2 changes: 2 additions & 0 deletions playground/Embedded.perftest/EmbeddedRespServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public EmbeddedRespServer(GarnetServerOptions opts, ILoggerFactory loggerFactory
/// </summary>
public new void Dispose() => base.Dispose();

public StoreWrapper StoreWrapper => storeWrapper;

/// <summary>
/// Return a RESP session to this server
/// </summary>
Expand Down
16 changes: 6 additions & 10 deletions test/Garnet.test/RespAdminCommandsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,9 @@ public void SeSaveRecoverObjectTest()
public void SeSaveRecoverMultipleObjectsTest(int memorySize, int recoveryMemorySize, int pageSize)
{
string sizeToString(int size) => size + "k";
bool useAzure = false;
if (useAzure)
TestUtils.IgnoreIfNotRunningAzureTests();

server.Dispose();
server = TestUtils.CreateGarnetServer(TestUtils.MethodTestDir, UseAzureStorage: useAzure, lowMemory: true, MemorySize: sizeToString(memorySize), PageSize: sizeToString(pageSize));
server = TestUtils.CreateGarnetServer(TestUtils.MethodTestDir, lowMemory: true, MemorySize: sizeToString(memorySize), PageSize: sizeToString(pageSize));
server.Start();

var ldata = new RedisValue[] { "a", "b", "c", "d" };
Expand All @@ -252,7 +250,7 @@ public void SeSaveRecoverMultipleObjectsTest(int memorySize, int recoveryMemoryS
}

server.Dispose(false);
server = TestUtils.CreateGarnetServer(TestUtils.MethodTestDir, tryRecover: true, UseAzureStorage: useAzure, lowMemory: true, MemorySize: sizeToString(recoveryMemorySize), PageSize: sizeToString(pageSize));
server = TestUtils.CreateGarnetServer(TestUtils.MethodTestDir, tryRecover: true, lowMemory: true, MemorySize: sizeToString(recoveryMemorySize), PageSize: sizeToString(pageSize));
server.Start();

Assert.LessOrEqual(server.Provider.StoreWrapper.objectStore.MaxAllocatedPageCount, (recoveryMemorySize / pageSize) + 1);
Expand All @@ -279,11 +277,9 @@ public void SeSaveRecoverMultipleObjectsTest(int memorySize, int recoveryMemoryS
public void SeSaveRecoverMultipleKeysTest(string memorySize, string recoveryMemorySize)
{
bool disableObj = true;
bool useAzure = false;
if (useAzure)
TestUtils.IgnoreIfNotRunningAzureTests();

server.Dispose();
server = TestUtils.CreateGarnetServer(TestUtils.MethodTestDir, DisableObjects: disableObj, UseAzureStorage: useAzure, lowMemory: true, MemorySize: memorySize, PageSize: "1k", enableAOF: true);
server = TestUtils.CreateGarnetServer(TestUtils.MethodTestDir, DisableObjects: disableObj, lowMemory: true, MemorySize: memorySize, PageSize: "1k", enableAOF: true);
server.Start();

using (var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig(allowAdmin: true)))
Expand Down Expand Up @@ -322,7 +318,7 @@ public void SeSaveRecoverMultipleKeysTest(string memorySize, string recoveryMemo
}

server.Dispose(false);
server = TestUtils.CreateGarnetServer(TestUtils.MethodTestDir, DisableObjects: disableObj, tryRecover: true, UseAzureStorage: useAzure, lowMemory: true, MemorySize: recoveryMemorySize, PageSize: "1k", enableAOF: true);
server = TestUtils.CreateGarnetServer(TestUtils.MethodTestDir, DisableObjects: disableObj, tryRecover: true, lowMemory: true, MemorySize: recoveryMemorySize, PageSize: "1k", enableAOF: true);
server.Start();

using (var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig(allowAdmin: true)))
Expand Down

0 comments on commit 88ceb33

Please sign in to comment.