Skip to content

Commit

Permalink
Merge branch 'microsoft:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenge authored Oct 28, 2024
2 parents a061a0d + 6d489c6 commit 84b90a6
Show file tree
Hide file tree
Showing 92 changed files with 1,933 additions and 687 deletions.
2 changes: 1 addition & 1 deletion .azure/pipelines/azure-pipelines-external-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# 1) update the name: string below (line 6) -- this is the version for the nuget package (e.g. 1.0.0)
# 2) update \libs\host\GarnetServer.cs readonly string version (~line 32) -- NOTE - these two values need to be the same
######################################
name: 1.0.33
name: 1.0.34
trigger:
branches:
include:
Expand Down
7 changes: 5 additions & 2 deletions .azure/pipelines/azure-pipelines-mirror.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ jobs:
# Reset the main branch to match the origin/main branch
# git reset --hard origin/main
# Push the updated main branch to Azure DevOps
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" push https://dev.azure.com/msresearch/_git/Garnet main
# Push the updated main branch to Azure DevOps - make sure to get the config files each push so compliant with security policy
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" remote add vso https://dev.azure.com/msresearch/_git/Garnet
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" fetch vso cfs-remediation
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" cherry-pick 0bae2b8a7d3dc9bfc59d25acf30b470ff97f6a7f
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" push --force https://dev.azure.com/msresearch/_git/Garnet main
displayName: 'Mirror GitHub main to Azure DevOps main'
env:
Expand Down
9 changes: 5 additions & 4 deletions benchmark/BDN.benchmark/BDN.benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
<ItemGroup>
<Compile Include="..\..\playground\Embedded.perftest\EmbeddedRespServer.cs" Link="Utils\EmbeddedRespServer.cs" />
<Compile Include="..\..\playground\Embedded.perftest\DummyNetworkSender.cs" Link="Utils\DummyNetworkSender.cs" />
<Compile Include="..\..\main\GarnetServer\Extensions\MyDictObject.cs" Link="CustomProcs\MyDictObject.cs" />
<Compile Include="..\..\main\GarnetServer\Extensions\MyDictSet.cs" Link="CustomProcs\MyDictSet.cs" />
<Compile Include="..\..\main\GarnetServer\Extensions\MyDictGet.cs" Link="CustomProcs\MyDictGet.cs" />
</ItemGroup>
<Compile Include="..\..\main\GarnetServer\Extensions\MyDictObject.cs" Link="Custom\MyDictObject.cs" />
<Compile Include="..\..\main\GarnetServer\Extensions\MyDictSet.cs" Link="Custom\MyDictSet.cs" />
<Compile Include="..\..\main\GarnetServer\Extensions\MyDictGet.cs" Link="Custom\MyDictGet.cs" />
<Compile Include="..\..\main\GarnetServer\Extensions\SetIfPM.cs" Link="Custom\SetIfPM.cs" />
</ItemGroup>

</Project>
18 changes: 9 additions & 9 deletions benchmark/BDN.benchmark/Cluster/ClusterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ unsafe class ClusterContext
public static ReadOnlySpan<byte> keyTag => "{0}"u8;
public Request[] singleGetSet;
public Request[] singleMGetMSet;
public Request singleCPBSET;
public Request singleCTXNSET;

public void Dispose()
{
Expand All @@ -41,7 +41,7 @@ public void SetupSingleInstance(bool disableSlotVerification = false)
opt.CheckpointDir = "/tmp";
server = new EmbeddedRespServer(opt);
session = server.GetRespSession();
_ = server.Register.NewTransactionProc(CustomProcSet.CommandName, () => new CustomProcSet(), new RespCommandsInfo { Arity = CustomProcSet.Arity });
_ = server.Register.NewTransactionProc(CustomTxnSet.CommandName, () => new CustomTxnSet(), new RespCommandsInfo { Arity = CustomTxnSet.Arity });
}

public void AddSlotRange(List<(int, int)> slotRanges)
Expand Down Expand Up @@ -134,7 +134,7 @@ public void CreateMGetMSet(int keySize = 8, int valueSize = 32, int batchSize =
singleMGetMSet = [mGetReq, mSetReq];
}

public void CreateCPBSET(int keySize = 8, int batchSize = 100)
public void CreateCTXNSET(int keySize = 8, int batchSize = 100)
{
var keys = new byte[8][];
for (var i = 0; i < 8; i++)
Expand All @@ -145,22 +145,22 @@ public void CreateCPBSET(int keySize = 8, int batchSize = 100)
benchUtils.RandomBytes(ref keys[i], startOffset: keyTag.Length);
}

var cpbsetByteCount = "*9\r\n$6\r\nCPBSET\r\n"u8.Length + (8 * (1 + NumUtils.NumDigits(keySize) + 2 + keySize + 2));
var cpbsetReq = new Request(batchSize * cpbsetByteCount);
var curr = cpbsetReq.ptr;
var end = curr + cpbsetReq.buffer.Length;
var ctxnsetByteCount = "*9\r\n$7\r\nCTXNSET\r\n"u8.Length + (8 * (1 + NumUtils.NumDigits(keySize) + 2 + keySize + 2));
var ctxnsetReq = new Request(batchSize * ctxnsetByteCount);
var curr = ctxnsetReq.ptr;
var end = curr + ctxnsetReq.buffer.Length;

for (var i = 0; i < batchSize; i++)
{
_ = RespWriteUtils.WriteArrayLength(9, ref curr, end);
_ = RespWriteUtils.WriteBulkString("CPBSET"u8, ref curr, end);
_ = RespWriteUtils.WriteBulkString("CTXNSET"u8, ref curr, end);
for (var j = 0; j < 8; j++)
{
_ = RespWriteUtils.WriteBulkString(keys[j], ref curr, end);
}
}

singleCPBSET = cpbsetReq;
singleCTXNSET = ctxnsetReq;
}

public void Consume(byte* ptr, int length)
Expand Down
8 changes: 4 additions & 4 deletions benchmark/BDN.benchmark/Cluster/ClusterOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public virtual void GlobalSetup()
cc.AddSlotRange([(0, 16383)]);
cc.CreateGetSet();
cc.CreateMGetMSet();
cc.CreateCPBSET();
cc.CreateCTXNSET();

// Warmup/Prepopulate stage
cc.Consume(cc.singleGetSet[1].ptr, cc.singleGetSet[1].buffer.Length);
// Warmup/Prepopulate stage
cc.Consume(cc.singleMGetMSet[1].ptr, cc.singleMGetMSet[1].buffer.Length);
// Warmup/Prepopulate stage
cc.Consume(cc.singleCPBSET.ptr, cc.singleCPBSET.buffer.Length);
cc.Consume(cc.singleCTXNSET.ptr, cc.singleCTXNSET.buffer.Length);
}

[GlobalCleanup]
Expand Down Expand Up @@ -77,9 +77,9 @@ public void MSet()
}

[Benchmark]
public void CPBSET()
public void CTXNSET()
{
cc.Consume(cc.singleCPBSET.ptr, cc.singleCPBSET.buffer.Length);
cc.Consume(cc.singleCTXNSET.ptr, cc.singleCTXNSET.buffer.Length);
}
}
}
50 changes: 50 additions & 0 deletions benchmark/BDN.benchmark/Custom/CustomProcSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using Garnet.common;
using Garnet.server;

namespace BDN.benchmark.CustomProcs
{
class CustomProcSet : CustomProcedure
{
/// <summary>
/// Parameters including command
/// </summary>
public const int Arity = 9;

/// <summary>
/// Command name
/// </summary>
public const string CommandName = "CPROCSET";

/// <summary>
/// CPROCSET key1 key2 key3 key4 value1 value2 value3 value4
/// </summary>
/// <typeparam name="TGarnetApi"></typeparam>
/// <param name="api"></param>
/// <param name="procInput"></param>
/// <param name="output"></param>
/// <returns></returns>
public override bool Execute<TGarnetApi>(TGarnetApi api, ref CustomProcedureInput procInput, ref MemoryResult<byte> output)
{
var offset = 0;
var setA = GetNextArg(ref procInput, ref offset);
var setB = GetNextArg(ref procInput, ref offset);
var setC = GetNextArg(ref procInput, ref offset);
var setD = GetNextArg(ref procInput, ref offset);

var valueA = GetNextArg(ref procInput, ref offset);
var valueB = GetNextArg(ref procInput, ref offset);
var valueC = GetNextArg(ref procInput, ref offset);
var valueD = GetNextArg(ref procInput, ref offset);

_ = api.SET(setA, valueA);
_ = api.SET(setB, valueB);
_ = api.SET(setC, valueC);
_ = api.SET(setD, valueD);

return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
namespace BDN.benchmark.CustomProcs
{
/// <summary>
/// Custom procedure to set values
/// Custom transaction to set values
/// </summary>
sealed class CustomProcSet : CustomTransactionProcedure
sealed class CustomTxnSet : CustomTransactionProcedure
{
/// <summary>
/// Parameters including command
Expand All @@ -20,7 +20,7 @@ sealed class CustomProcSet : CustomTransactionProcedure
/// <summary>
/// Command name
/// </summary>
public const string CommandName = "CPBSET";
public const string CommandName = "CTXNSET";

ArgSlice setA;
ArgSlice setB;
Expand All @@ -33,7 +33,7 @@ sealed class CustomProcSet : CustomTransactionProcedure
ArgSlice valueD;

/// <summary>
/// CPBSET key1 key2 key3 key4 value1 value2 value3 value4
/// CTXNSET key1 key2 key3 key4 value1 value2 value3 value4
/// </summary>
/// <typeparam name="TGarnetReadApi"></typeparam>
/// <param name="api"></param>
Expand Down
93 changes: 93 additions & 0 deletions benchmark/BDN.benchmark/Operations/CustomOperations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using BDN.benchmark.CustomProcs;
using BenchmarkDotNet.Attributes;
using Garnet;
using Garnet.server;

namespace BDN.benchmark.Operations
{
/// <summary>
/// Benchmark for ObjectOperations
/// </summary>
[MemoryDiagnoser]
public unsafe class CustomOperations : OperationsBase
{
static ReadOnlySpan<byte> SETIFPM => "*4\r\n$7\r\nSETIFPM\r\n$1\r\nk\r\n$3\r\nval\r\n$1\r\nv\r\n"u8;
byte[] setIfPmRequestBuffer;
byte* setIfPmRequestBufferPointer;

static ReadOnlySpan<byte> MYDICTSETGET => "*4\r\n$9\r\nMYDICTSET\r\n$2\r\nck\r\n$1\r\nf\r\n$1\r\nv\r\n*3\r\n$9\r\nMYDICTGET\r\n$2\r\nck\r\n$1\r\nf\r\n"u8;
byte[] myDictSetGetRequestBuffer;
byte* myDictSetGetRequestBufferPointer;

static ReadOnlySpan<byte> CTXNSET => "*9\r\n$7\r\nCTXNSET\r\n$6\r\n{0}000\r\n$6\r\n{0}001\r\n$6\r\n{0}002\r\n$6\r\n{0}003\r\n$6\r\n{0}000\r\n$6\r\n{0}001\r\n$6\r\n{0}002\r\n$6\r\n{0}003\r\n"u8;
byte[] ctxnsetBuffer;
byte* ctxnsetBufferPointer;

static ReadOnlySpan<byte> CPROCSET => "*9\r\n$8\r\nCPROCSET\r\n$6\r\n{0}000\r\n$6\r\n{0}001\r\n$6\r\n{0}002\r\n$6\r\n{0}003\r\n$6\r\n{0}000\r\n$6\r\n{0}001\r\n$6\r\n{0}002\r\n$6\r\n{0}003\r\n"u8;
byte[] cprocsetBuffer;
byte* cprocsetBufferPointer;

void CreateExtensions()
{
// Register custom raw string command
server.Register.NewCommand("SETIFPM", CommandType.ReadModifyWrite, new SetIfPMCustomCommand(), new RespCommandsInfo { Arity = 4 });

// Register custom object type and commands
var factory = new MyDictFactory();
server.Register.NewType(factory);
server.Register.NewCommand("MYDICTSET", CommandType.ReadModifyWrite, factory, new MyDictSet(), new RespCommandsInfo { Arity = 4 });
server.Register.NewCommand("MYDICTGET", CommandType.Read, factory, new MyDictGet(), new RespCommandsInfo { Arity = 3 });

// Register custom transaction
server.Register.NewTransactionProc(CustomProcs.CustomTxnSet.CommandName, () => new CustomTxnSet(),
new RespCommandsInfo { Arity = CustomProcs.CustomTxnSet.Arity });

// Register custom procedure
server.Register.NewProcedure(CustomProcs.CustomProcSet.CommandName, new CustomProcSet(),
new RespCommandsInfo { Arity = CustomProcs.CustomProcSet.Arity });
}

public override void GlobalSetup()
{
base.GlobalSetup();
CreateExtensions();

SetupOperation(ref setIfPmRequestBuffer, ref setIfPmRequestBufferPointer, SETIFPM);
SetupOperation(ref myDictSetGetRequestBuffer, ref myDictSetGetRequestBufferPointer, MYDICTSETGET);
SetupOperation(ref ctxnsetBuffer, ref ctxnsetBufferPointer, CTXNSET);
SetupOperation(ref cprocsetBuffer, ref cprocsetBufferPointer, CPROCSET);

SlowConsumeMessage("*4\r\n$7\r\nSETIFPM\r\n$1\r\nk\r\n$3\r\nval\r\n$1\r\nv\r\n"u8);
SlowConsumeMessage("*4\r\n$9\r\nMYDICTSET\r\n$2\r\nck\r\n$1\r\nf\r\n$1\r\nv\r\n"u8);
SlowConsumeMessage(ctxnsetBuffer);
SlowConsumeMessage(cprocsetBuffer);
}

[Benchmark]
public void CustomRawStringCommand()
{
_ = session.TryConsumeMessages(setIfPmRequestBufferPointer, setIfPmRequestBuffer.Length);
}

[Benchmark]
public void CustomObjectCommand()
{
_ = session.TryConsumeMessages(myDictSetGetRequestBufferPointer, myDictSetGetRequestBuffer.Length);
}

[Benchmark]
public void CustomTransaction()
{
_ = session.TryConsumeMessages(ctxnsetBufferPointer, ctxnsetBuffer.Length);
}

[Benchmark]
public void CustomProcedure()
{
_ = session.TryConsumeMessages(cprocsetBufferPointer, cprocsetBuffer.Length);
}
}
}
37 changes: 0 additions & 37 deletions benchmark/BDN.benchmark/Operations/ObjectOperations.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using BDN.benchmark.CustomProcs;
using BenchmarkDotNet.Attributes;
using Garnet;
using Garnet.server;

namespace BDN.benchmark.Operations
{
Expand All @@ -30,41 +27,19 @@ public unsafe class ObjectOperations : OperationsBase
byte[] hSetDelRequestBuffer;
byte* hSetDelRequestBufferPointer;

static ReadOnlySpan<byte> MYDICTSETGET => "*4\r\n$9\r\nMYDICTSET\r\n$2\r\nck\r\n$1\r\nf\r\n$1\r\nv\r\n*3\r\n$9\r\nMYDICTGET\r\n$2\r\nck\r\n$1\r\nf\r\n"u8;
byte[] myDictSetGetRequestBuffer;
byte* myDictSetGetRequestBufferPointer;

static ReadOnlySpan<byte> CPBSET => "*9\r\n$6\r\nCPBSET\r\n$6\r\n{0}000\r\n$6\r\n{0}001\r\n$6\r\n{0}002\r\n$6\r\n{0}003\r\n$6\r\n{0}000\r\n$6\r\n{0}001\r\n$6\r\n{0}002\r\n$6\r\n{0}003\r\n"u8;
byte[] cpbsetBuffer;
byte* cpbsetBufferPointer;

void CreateExtensions()
{
var factory = new MyDictFactory();
server.Register.NewType(factory);
server.Register.NewCommand("MYDICTSET", CommandType.ReadModifyWrite, factory, new MyDictSet(), new RespCommandsInfo { Arity = 4 });
server.Register.NewCommand("MYDICTGET", CommandType.Read, factory, new MyDictGet(), new RespCommandsInfo { Arity = 3 });
server.Register.NewTransactionProc(CustomProcs.CustomProcSet.CommandName, () => new CustomProcSet(), new RespCommandsInfo { Arity = CustomProcs.CustomProcSet.Arity });
}

public override void GlobalSetup()
{
base.GlobalSetup();
CreateExtensions();
SetupOperation(ref zAddRemRequestBuffer, ref zAddRemRequestBufferPointer, ZADDREM);
SetupOperation(ref lPushPopRequestBuffer, ref lPushPopRequestBufferPointer, LPUSHPOP);
SetupOperation(ref sAddRemRequestBuffer, ref sAddRemRequestBufferPointer, SADDREM);
SetupOperation(ref hSetDelRequestBuffer, ref hSetDelRequestBufferPointer, HSETDEL);
SetupOperation(ref myDictSetGetRequestBuffer, ref myDictSetGetRequestBufferPointer, MYDICTSETGET);
SetupOperation(ref cpbsetBuffer, ref cpbsetBufferPointer, CPBSET);

// Pre-populate data
SlowConsumeMessage("*4\r\n$4\r\nZADD\r\n$1\r\nc\r\n$1\r\n1\r\n$1\r\nd\r\n"u8);
SlowConsumeMessage("*3\r\n$5\r\nLPUSH\r\n$1\r\nd\r\n$1\r\nf\r\n"u8);
SlowConsumeMessage("*3\r\n$4\r\nSADD\r\n$1\r\ne\r\n$1\r\nb\r\n"u8);
SlowConsumeMessage("*3\r\n$4\r\nHSET\r\n$1\r\nf\r\n$1\r\nb\r\n$1\r\nb\r\n"u8);
SlowConsumeMessage("*4\r\n$9\r\nMYDICTSET\r\n$2\r\nck\r\n$1\r\nf\r\n$1\r\nv\r\n"u8);
SlowConsumeMessage(cpbsetBuffer);
}

[Benchmark]
Expand All @@ -90,17 +65,5 @@ public void HSetDel()
{
_ = session.TryConsumeMessages(hSetDelRequestBufferPointer, hSetDelRequestBuffer.Length);
}

[Benchmark]
public void MyDictSetGet()
{
_ = session.TryConsumeMessages(myDictSetGetRequestBufferPointer, myDictSetGetRequestBuffer.Length);
}

[Benchmark]
public void CustomProcSet()
{
_ = session.TryConsumeMessages(cpbsetBufferPointer, cpbsetBuffer.Length);
}
}
}
Loading

0 comments on commit 84b90a6

Please sign in to comment.