Skip to content

Commit

Permalink
Merge branch 'main' into hkhalid/etag-impl
Browse files Browse the repository at this point in the history
  • Loading branch information
hamdaankhalidmsft committed Dec 16, 2024
2 parents 8861f75 + 635cd58 commit d7beeb6
Show file tree
Hide file tree
Showing 94 changed files with 3,105 additions and 1,017 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-bdnbenchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
os: [ ubuntu-latest, windows-latest ]
framework: [ 'net8.0' ]
configuration: [ 'Release' ]
test: [ 'Operations.BasicOperations', 'Operations.ObjectOperations', 'Cluster.ClusterMigrate', 'Cluster.ClusterOperations', 'Lua.LuaScripts' ]
test: [ 'Operations.BasicOperations', 'Operations.ObjectOperations', 'Operations.HashObjectOperations', 'Cluster.ClusterMigrate', 'Cluster.ClusterOperations', 'Lua.LuaScripts','Operations.RawStringOperations','Operations.ScriptOperations' ]
steps:
- name: Check out code
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![](https://img.shields.io/github/release/microsoft/garnet.svg?label=latest%20release&color=007edf)](https://github.com/microsoft/garnet/releases/latest)
[![](https://img.shields.io/nuget/dt/microsoft.garnet.svg?label=nuget%20library&color=007edf&logo=nuget)](https://www.nuget.org/packages/microsoft.garnet)
[![](https://img.shields.io/nuget/dt/garnet-server.svg?label=dotnet%20tool&color=007edf&logo=nuget)](https://www.nuget.org/packages/garnet-server)
[![BDN Charts](https://img.shields.io/badge/BDN%20Charts-8A2BE2)](https://microsoft.github.io/garnet/charts/)
[![Discord Shield](https://discordapp.com/api/guilds/1213937452272582676/widget.png?style=shield)](https://aka.ms/garnet-discord)

Garnet is a new remote cache-store from Microsoft Research, that offers several unique benefits:
Expand Down
2 changes: 1 addition & 1 deletion Version.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<!-- Versioning property for builds and packages -->
<PropertyGroup>
<VersionPrefix>1.0.47</VersionPrefix>
<VersionPrefix>1.0.48</VersionPrefix>
</PropertyGroup>
</Project>
189 changes: 189 additions & 0 deletions benchmark/BDN.benchmark/Operations/HashObjectOperations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using BenchmarkDotNet.Attributes;

namespace BDN.benchmark.Operations
{
/// <summary>
/// Benchmark for HashObjectOperations
/// </summary>
[MemoryDiagnoser]
public unsafe class HashObjectOperations : OperationsBase
{
static ReadOnlySpan<byte> HSETDEL => "*4\r\n$4\r\nHSET\r\n$1\r\nf\r\n$1\r\na\r\n$1\r\na\r\n*3\r\n$4\r\nHDEL\r\n$1\r\nf\r\n$1\r\na\r\n"u8;
byte[] hSetDelRequestBuffer;
byte* hSetDelRequestBufferPointer;

static ReadOnlySpan<byte> HEXISTS => "*3\r\n$7\r\nHEXISTS\r\n$1\r\nf\r\n$1\r\na\r\n"u8;
byte[] hExistsRequestBuffer;
byte* hExistsRequestBufferPointer;

static ReadOnlySpan<byte> HGET => "*3\r\n$4\r\nHGET\r\n$1\r\nf\r\n$1\r\na\r\n"u8;
byte[] hGetRequestBuffer;
byte* hGetRequestBufferPointer;

static ReadOnlySpan<byte> HGETALL => "*2\r\n$7\r\nHGETALL\r\n$1\r\nf\r\n"u8;
byte[] hGetAllRequestBuffer;
byte* hGetAllRequestBufferPointer;

static ReadOnlySpan<byte> HINCRBY => "*4\r\n$7\r\nHINCRBY\r\n$1\r\nf\r\n$1\r\nc\r\n$1\r\n1\r\n"u8;
byte[] hIncrbyRequestBuffer;
byte* hIncrbyRequestBufferPointer;

static ReadOnlySpan<byte> HINCRBYFLOAT => "*4\r\n$12\r\nHINCRBYFLOAT\r\n$1\r\nf\r\n$1\r\nd\r\n$3\r\n1.5\r\n"u8;
byte[] hIncrbyFloatRequestBuffer;
byte* hIncrbyFloatRequestBufferPointer;

static ReadOnlySpan<byte> HKEYS => "*2\r\n$5\r\nHKEYS\r\n$1\r\nf\r\n"u8;
byte[] hKeysRequestBuffer;
byte* hKeysRequestBufferPointer;

static ReadOnlySpan<byte> HLEN => "*2\r\n$4\r\nHLEN\r\n$1\r\nf\r\n"u8;
byte[] hLenRequestBuffer;
byte* hLenRequestBufferPointer;

static ReadOnlySpan<byte> HMGET => "*4\r\n$5\r\nHMGET\r\n$1\r\nf\r\n$1\r\na\r\n$1\r\nb\r\n"u8;
byte[] hMGetRequestBuffer;
byte* hMGetRequestBufferPointer;

static ReadOnlySpan<byte> HMSET => "*6\r\n$5\r\nHMSET\r\n$1\r\nf\r\n$1\r\na\r\n$1\r\n1\r\n$1\r\nb\r\n$1\r\n2\r\n"u8;
byte[] hMSetRequestBuffer;
byte* hMSetRequestBufferPointer;

static ReadOnlySpan<byte> HRANDFIELD => "*2\r\n$10\r\nHRANDFIELD\r\n$1\r\nf\r\n"u8;
byte[] hRandFieldRequestBuffer;
byte* hRandFieldRequestBufferPointer;

static ReadOnlySpan<byte> HSCAN => "*6\r\n$5\r\nHSCAN\r\n$1\r\nf\r\n$1\r\n0\r\n$5\r\nCOUNT\r\n$1\r\n5\r\n"u8;
byte[] hScanRequestBuffer;
byte* hScanRequestBufferPointer;

static ReadOnlySpan<byte> HSETNX => "*4\r\n$6\r\nHSETNX\r\n$1\r\nf\r\n$1\r\nx\r\n$1\r\n1\r\n"u8;
byte[] hSetNxRequestBuffer;
byte* hSetNxRequestBufferPointer;

static ReadOnlySpan<byte> HSTRLEN => "*3\r\n$7\r\nHSTRLEN\r\n$1\r\nf\r\n$1\r\na\r\n"u8;
byte[] hStrLenRequestBuffer;
byte* hStrLenRequestBufferPointer;

static ReadOnlySpan<byte> HVALS => "*2\r\n$5\r\nHVALS\r\n$1\r\nf\r\n"u8;
byte[] hValsRequestBuffer;
byte* hValsRequestBufferPointer;

public override void GlobalSetup()
{
base.GlobalSetup();
SetupOperation(ref hSetDelRequestBuffer, ref hSetDelRequestBufferPointer, HSETDEL);
SetupOperation(ref hExistsRequestBuffer, ref hExistsRequestBufferPointer, HEXISTS);
SetupOperation(ref hGetRequestBuffer, ref hGetRequestBufferPointer, HGET);
SetupOperation(ref hGetAllRequestBuffer, ref hGetAllRequestBufferPointer, HGETALL);
SetupOperation(ref hIncrbyRequestBuffer, ref hIncrbyRequestBufferPointer, HINCRBY);
SetupOperation(ref hIncrbyFloatRequestBuffer, ref hIncrbyFloatRequestBufferPointer, HINCRBYFLOAT);
SetupOperation(ref hKeysRequestBuffer, ref hKeysRequestBufferPointer, HKEYS);
SetupOperation(ref hLenRequestBuffer, ref hLenRequestBufferPointer, HLEN);
SetupOperation(ref hMGetRequestBuffer, ref hMGetRequestBufferPointer, HMGET);
SetupOperation(ref hMSetRequestBuffer, ref hMSetRequestBufferPointer, HMSET);
SetupOperation(ref hRandFieldRequestBuffer, ref hRandFieldRequestBufferPointer, HRANDFIELD);
SetupOperation(ref hScanRequestBuffer, ref hScanRequestBufferPointer, HSCAN);
SetupOperation(ref hSetNxRequestBuffer, ref hSetNxRequestBufferPointer, HSETNX);
SetupOperation(ref hStrLenRequestBuffer, ref hStrLenRequestBufferPointer, HSTRLEN);
SetupOperation(ref hValsRequestBuffer, ref hValsRequestBufferPointer, HVALS);

// Pre-populate data
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$4\r\nHSET\r\n$1\r\nf\r\n$1\r\nc\r\n$1\r\n5\r\n"u8);
SlowConsumeMessage("*4\r\n$4\r\nHSET\r\n$1\r\nf\r\n$1\r\nd\r\n$3\r\n5.5\r\n"u8);
}

[Benchmark]
public void HSetDel()
{
_ = session.TryConsumeMessages(hSetDelRequestBufferPointer, hSetDelRequestBuffer.Length);
}

[Benchmark]
public void HExists()
{
_ = session.TryConsumeMessages(hExistsRequestBufferPointer, hExistsRequestBuffer.Length);
}

[Benchmark]
public void HGet()
{
_ = session.TryConsumeMessages(hGetRequestBufferPointer, hGetRequestBuffer.Length);
}

[Benchmark]
public void HGetAll()
{
_ = session.TryConsumeMessages(hGetAllRequestBufferPointer, hGetAllRequestBuffer.Length);
}

[Benchmark]
public void HIncrby()
{
_ = session.TryConsumeMessages(hIncrbyRequestBufferPointer, hIncrbyRequestBuffer.Length);
}

[Benchmark]
public void HIncrbyFloat()
{
_ = session.TryConsumeMessages(hIncrbyFloatRequestBufferPointer, hIncrbyFloatRequestBuffer.Length);
}

[Benchmark]
public void HKeys()
{
_ = session.TryConsumeMessages(hKeysRequestBufferPointer, hKeysRequestBuffer.Length);
}

[Benchmark]
public void HLen()
{
_ = session.TryConsumeMessages(hLenRequestBufferPointer, hLenRequestBuffer.Length);
}

[Benchmark]
public void HMGet()
{
_ = session.TryConsumeMessages(hMGetRequestBufferPointer, hMGetRequestBuffer.Length);
}

[Benchmark]
public void HMSet()
{
_ = session.TryConsumeMessages(hMSetRequestBufferPointer, hMSetRequestBuffer.Length);
}

[Benchmark]
public void HRandField()
{
_ = session.TryConsumeMessages(hRandFieldRequestBufferPointer, hRandFieldRequestBuffer.Length);
}

[Benchmark]
public void HScan()
{
_ = session.TryConsumeMessages(hScanRequestBufferPointer, hScanRequestBuffer.Length);
}

[Benchmark]
public void HSetNx()
{
_ = session.TryConsumeMessages(hSetNxRequestBufferPointer, hSetNxRequestBuffer.Length);
}

[Benchmark]
public void HStrLen()
{
_ = session.TryConsumeMessages(hStrLenRequestBufferPointer, hStrLenRequestBuffer.Length);
}

[Benchmark]
public void HVals()
{
_ = session.TryConsumeMessages(hValsRequestBufferPointer, hValsRequestBuffer.Length);
}
}
}
12 changes: 0 additions & 12 deletions benchmark/BDN.benchmark/Operations/ObjectOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,17 @@ public unsafe class ObjectOperations : OperationsBase
byte[] sAddRemRequestBuffer;
byte* sAddRemRequestBufferPointer;

static ReadOnlySpan<byte> HSETDEL => "*4\r\n$4\r\nHSET\r\n$1\r\nf\r\n$1\r\na\r\n$1\r\na\r\n*3\r\n$4\r\nHDEL\r\n$1\r\nf\r\n$1\r\na\r\n"u8;
byte[] hSetDelRequestBuffer;
byte* hSetDelRequestBufferPointer;

public override void GlobalSetup()
{
base.GlobalSetup();
SetupOperation(ref zAddRemRequestBuffer, ref zAddRemRequestBufferPointer, ZADDREM);
SetupOperation(ref lPushPopRequestBuffer, ref lPushPopRequestBufferPointer, LPUSHPOP);
SetupOperation(ref sAddRemRequestBuffer, ref sAddRemRequestBufferPointer, SADDREM);
SetupOperation(ref hSetDelRequestBuffer, ref hSetDelRequestBufferPointer, HSETDEL);

// 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);
}

[Benchmark]
Expand All @@ -59,11 +53,5 @@ public void SAddRem()
{
_ = session.TryConsumeMessages(sAddRemRequestBufferPointer, sAddRemRequestBuffer.Length);
}

[Benchmark]
public void HSetDel()
{
_ = session.TryConsumeMessages(hSetDelRequestBufferPointer, hSetDelRequestBuffer.Length);
}
}
}
3 changes: 2 additions & 1 deletion benchmark/BDN.benchmark/Operations/OperationsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public virtual void GlobalSetup()
{
var opts = new GarnetServerOptions
{
QuietMode = true
QuietMode = true,
EnableLua = true,
};
if (Params.useAof)
{
Expand Down
85 changes: 85 additions & 0 deletions benchmark/BDN.benchmark/Operations/ScriptOperations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using BenchmarkDotNet.Attributes;

namespace BDN.benchmark.Operations
{
/// <summary>
/// Benchmark for SCRIPT LOAD, SCRIPT EXISTS, EVAL, and EVALSHA
/// </summary>
[MemoryDiagnoser]
public unsafe class ScriptOperations : OperationsBase
{
static ReadOnlySpan<byte> SCRIPT_LOAD => "*3\r\n$6\r\nSCRIPT\r\n$4\r\nLOAD\r\n$8\r\nreturn 1\r\n"u8;
byte[] scriptLoadRequestBuffer;
byte* scriptLoadRequestBufferPointer;

static ReadOnlySpan<byte> SCRIPT_EXISTS_LOADED => "*3\r\n$6\r\nSCRIPT\r\n$4\r\nLOAD\r\n$10\r\nreturn nil\r\n"u8;

static ReadOnlySpan<byte> SCRIPT_EXISTS_TRUE => "*3\r\n$6\r\nSCRIPT\r\n$6\r\nEXISTS\r\n$40\r\n79cefb99366d8809d2e903c5f36f50c2b731913f\r\n"u8;
byte[] scriptExistsTrueRequestBuffer;
byte* scriptExistsTrueRequestBufferPointer;

static ReadOnlySpan<byte> SCRIPT_EXISTS_FALSE => "*3\r\n$6\r\nSCRIPT\r\n$6\r\nEXISTS\r\n$40\r\n0000000000000000000000000000000000000000\r\n"u8;
byte[] scriptExistsFalseRequestBuffer;
byte* scriptExistsFalseRequestBufferPointer;

static ReadOnlySpan<byte> EVAL => "*3\r\n$4\r\nEVAL\r\n$10\r\nreturn nil\r\n$1\r\n0\r\n"u8;
byte[] evalRequestBuffer;
byte* evalRequestBufferPointer;

static ReadOnlySpan<byte> EVALSHA => "*3\r\n$7\r\nEVALSHA\r\n$40\r\n79cefb99366d8809d2e903c5f36f50c2b731913f\r\n$1\r\n0\r\n"u8;
byte[] evalShaRequestBuffer;
byte* evalShaRequestBufferPointer;

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

SetupOperation(ref scriptLoadRequestBuffer, ref scriptLoadRequestBufferPointer, SCRIPT_LOAD);

byte[] scriptExistsLoadedBuffer = null;
byte* scriptExistsLoadedPointer = null;
SetupOperation(ref scriptExistsLoadedBuffer, ref scriptExistsLoadedPointer, SCRIPT_EXISTS_LOADED);
_ = session.TryConsumeMessages(scriptExistsLoadedPointer, scriptExistsLoadedBuffer.Length);
SetupOperation(ref scriptExistsTrueRequestBuffer, ref scriptExistsTrueRequestBufferPointer, SCRIPT_EXISTS_TRUE);

SetupOperation(ref scriptExistsFalseRequestBuffer, ref scriptExistsFalseRequestBufferPointer, SCRIPT_EXISTS_FALSE);

SetupOperation(ref evalRequestBuffer, ref evalRequestBufferPointer, EVAL);

SetupOperation(ref evalShaRequestBuffer, ref evalShaRequestBufferPointer, EVALSHA);
}

[Benchmark]
public void ScriptLoad()
{
_ = session.TryConsumeMessages(scriptLoadRequestBufferPointer, scriptLoadRequestBuffer.Length);
}

[Benchmark]
public void ScriptExistsTrue()
{
_ = session.TryConsumeMessages(scriptExistsTrueRequestBufferPointer, scriptExistsTrueRequestBuffer.Length);
}

[Benchmark]
public void ScriptExistsFalse()
{
_ = session.TryConsumeMessages(scriptExistsFalseRequestBufferPointer, scriptExistsFalseRequestBuffer.Length);
}

[Benchmark]
public void Eval()
{
_ = session.TryConsumeMessages(evalRequestBufferPointer, evalRequestBuffer.Length);
}

[Benchmark]
public void EvalSha()
{
_ = session.TryConsumeMessages(evalShaRequestBufferPointer, evalShaRequestBuffer.Length);
}
}
}
4 changes: 2 additions & 2 deletions libs/cluster/Session/SlotVerification/ClusterSlotVerify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ ClusterSlotVerificationResult MultiKeySlotVerify(ClusterConfig config, ref Sessi
ref var key = ref parseState.GetArgSliceByRef(csvi.firstKey);
var slot = ArgSliceUtils.HashSlot(ref key);
var verifyResult = SingleKeySlotVerify(ref config, ref key, csvi.readOnly, csvi.sessionAsking, slot);
var stride = csvi.firstKey + csvi.step;
var secondKey = csvi.firstKey + csvi.step;

for (var i = stride; i < csvi.lastKey; i += stride)
for (var i = secondKey; i < csvi.lastKey; i += csvi.step)
{
if (csvi.keyNumOffset == i)
continue;
Expand Down
8 changes: 8 additions & 0 deletions libs/common/AsciiUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ public static void ToUpperInPlace(Span<byte> command)
Ascii.ToUpperInPlace(command, out _);
}

/// <summary>
/// Convert ASCII Span to lower case
/// </summary>
public static void ToLowerInPlace(Span<byte> command)
{
Ascii.ToLowerInPlace(command, out _);
}

/// <inheritdoc cref="EqualsUpperCaseSpanIgnoringCase(ReadOnlySpan{byte}, ReadOnlySpan{byte})"/>
public static bool EqualsUpperCaseSpanIgnoringCase(this Span<byte> left, ReadOnlySpan<byte> right)
=> EqualsUpperCaseSpanIgnoringCase((ReadOnlySpan<byte>)left, right);
Expand Down
Loading

0 comments on commit d7beeb6

Please sign in to comment.