Skip to content

Commit

Permalink
Merged latest
Browse files Browse the repository at this point in the history
  • Loading branch information
Vijay-Nirmal committed Jan 11, 2025
2 parents b900b5d + 9f90803 commit 436052f
Show file tree
Hide file tree
Showing 78 changed files with 5,391 additions and 693 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-bdnbenchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ jobs:
gh-pages-branch: 'continuousbenchmark'
benchmark-data-dir-path: 'website/static/charts'
max-items-in-chart: 50
alert-threshold: '10%'
alert-threshold: '110%'
comment-always: true
fail-on-alert: false
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set workaround for libaio on Ubuntu 24.04 (see https://askubuntu.com/questions/1512196/libaio1-on-noble/1512197#1512197)
run: |
sudo ln -s /usr/lib/x86_64-linux-gnu/libaio.so.1t64 /usr/lib/x86_64-linux-gnu/libaio.so.1
if: ${{ matrix.os == 'ubuntu-latest' }}
- name: Set environment variable for Linux
run: echo "RunAzureTests=yes" >> $GITHUB_ENV
if: ${{ matrix.os == 'ubuntu-latest' }}
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.48</VersionPrefix>
<VersionPrefix>1.0.50</VersionPrefix>
</PropertyGroup>
</Project>
17 changes: 12 additions & 5 deletions benchmark/BDN.benchmark/Embedded/EmbeddedNetworkHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Garnet.common;
using Garnet.networking;
using Microsoft.Extensions.Logging;
Expand All @@ -11,8 +12,11 @@ namespace Embedded.server
{
internal class EmbeddedNetworkHandler : NetworkHandler<GarnetServerEmbedded, EmbeddedNetworkSender>
{
readonly bool useTLS;

public EmbeddedNetworkHandler(GarnetServerEmbedded serverHook, EmbeddedNetworkSender networkSender, NetworkBufferSettings networkBufferSettings, LimitedFixedBufferPool networkPool, bool useTLS, IMessageConsumer messageConsumer = null, ILogger logger = null) : base(serverHook, networkSender, networkBufferSettings, networkPool, useTLS, messageConsumer, logger)
{
this.useTLS = useTLS;
}

public override string RemoteEndpointName => throw new NotImplementedException();
Expand All @@ -24,13 +28,16 @@ public override void Dispose()

public override bool TryClose() => throw new NotImplementedException();

public unsafe void Send(byte[] buffer, byte* bufferPtr, int length)
public async ValueTask Send(Request request)
{
networkReceiveBuffer = buffer;
networkReceiveBufferPtr = bufferPtr;
OnNetworkReceive(length);
networkReceiveBuffer = request.buffer;
unsafe { networkReceiveBufferPtr = request.bufferPtr; }

if (useTLS)
await OnNetworkReceiveWithTLSAsync(request.buffer.Length);
else
OnNetworkReceiveWithoutTLS(request.buffer.Length);

// We should have consumed the entire buffer
Debug.Assert(networkBytesRead == 0);
Debug.Assert(networkReadHead == 0);
}
Expand Down
11 changes: 11 additions & 0 deletions benchmark/BDN.benchmark/Embedded/Request.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

namespace Embedded.server
{
public struct Request
{
public byte[] buffer;
public unsafe byte* bufferPtr;
}
}
12 changes: 6 additions & 6 deletions benchmark/BDN.benchmark/Network/BasicOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
// Licensed under the MIT license.

using BenchmarkDotNet.Attributes;
using Embedded.server;

namespace BDN.benchmark.Network
{
/// <summary>
/// Benchmark for BasicOperations
/// </summary>
[MemoryDiagnoser]
public unsafe class BasicOperations : NetworkBase
public class BasicOperations : NetworkBase
{
static ReadOnlySpan<byte> INLINE_PING => "PING\r\n"u8;
byte[] pingRequestBuffer;
byte* pingRequestBufferPointer;
Request ping;

public override void GlobalSetup()
{
base.GlobalSetup();
SetupOperation(ref pingRequestBuffer, ref pingRequestBufferPointer, INLINE_PING);
SetupOperation(ref ping, INLINE_PING);
}

[Benchmark]
public void InlinePing()
public async ValueTask InlinePing()
{
Send(pingRequestBuffer, pingRequestBufferPointer, pingRequestBuffer.Length);
await Send(ping);
}
}
}
31 changes: 11 additions & 20 deletions benchmark/BDN.benchmark/Network/NetworkBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,10 @@ public IEnumerable<NetworkParams> NetworkParamsProvider()
}

/// <summary>
/// Batch size per method invocation
/// With a batchSize of 100, we have a convenient conversion of latency to throughput:
/// 5 us = 20 Mops/sec
/// 10 us = 10 Mops/sec
/// 20 us = 5 Mops/sec
/// 25 us = 4 Mops/sec
/// 100 us = 1 Mops/sec
/// Batch size per method invocation - we use a batch size of 1 for network BDNs
/// in order to stress the network layer.
/// </summary>
const int batchSize = 100;
const int batchSize = 1;
EmbeddedRespServer server;
EmbeddedNetworkHandler networkHandler;

Expand Down Expand Up @@ -69,25 +64,21 @@ public virtual void GlobalCleanup()
server.Dispose();
}

protected void Send(byte[] requestBuffer, byte* requestBufferPointer, int length)
{
networkHandler.Send(requestBuffer, requestBufferPointer, length);
}
protected ValueTask Send(Request request) => networkHandler.Send(request);

protected void SetupOperation(ref byte[] requestBuffer, ref byte* requestBufferPointer, ReadOnlySpan<byte> operation)
protected unsafe void SetupOperation(ref Request request, ReadOnlySpan<byte> operation, int batchSize = batchSize)
{
requestBuffer = GC.AllocateArray<byte>(operation.Length * batchSize, pinned: true);
requestBufferPointer = (byte*)Unsafe.AsPointer(ref requestBuffer[0]);
request.buffer = GC.AllocateArray<byte>(operation.Length * batchSize, pinned: true);
request.bufferPtr = (byte*)Unsafe.AsPointer(ref request.buffer[0]);
for (int i = 0; i < batchSize; i++)
operation.CopyTo(new Span<byte>(requestBuffer).Slice(i * operation.Length));
operation.CopyTo(new Span<byte>(request.buffer).Slice(i * operation.Length));
}

protected void SlowConsumeMessage(ReadOnlySpan<byte> message)
{
var buffer = GC.AllocateArray<byte>(message.Length, pinned: true);
var bufferPointer = (byte*)Unsafe.AsPointer(ref buffer[0]);
message.CopyTo(new Span<byte>(buffer));
Send(buffer, bufferPointer, buffer.Length);
Request request = default;
SetupOperation(ref request, message, 1);
Send(request);
}
}
}
93 changes: 42 additions & 51 deletions benchmark/BDN.benchmark/Network/RawStringOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,59 @@
// Licensed under the MIT license.

using BenchmarkDotNet.Attributes;
using Embedded.server;

namespace BDN.benchmark.Network
{
/// <summary>
/// Benchmark for RawStringOperations
/// </summary>
[MemoryDiagnoser]
public unsafe class RawStringOperations : NetworkBase
public class RawStringOperations : NetworkBase
{
static ReadOnlySpan<byte> SET => "*3\r\n$3\r\nSET\r\n$1\r\na\r\n$1\r\na\r\n"u8;
byte[] setRequestBuffer;
byte* setRequestBufferPointer;
Request set;

static ReadOnlySpan<byte> SETEX => "*4\r\n$5\r\nSETEX\r\n$1\r\nd\r\n$1\r\n9\r\n$1\r\nd\r\n"u8;
byte[] setexRequestBuffer;
byte* setexRequestBufferPointer;
Request setex;

static ReadOnlySpan<byte> SETNX => "*4\r\n$3\r\nSET\r\n$1\r\na\r\n$1\r\na\r\n$2\r\nNX\r\n"u8;
byte[] setnxRequestBuffer;
byte* setnxRequestBufferPointer;
Request setnx;

static ReadOnlySpan<byte> SETXX => "*4\r\n$3\r\nSET\r\n$1\r\na\r\n$1\r\na\r\n$2\r\nXX\r\n"u8;
byte[] setxxRequestBuffer;
byte* setxxRequestBufferPointer;
Request setxx;

static ReadOnlySpan<byte> GETNF => "*2\r\n$3\r\nGET\r\n$1\r\nb\r\n"u8;
byte[] getnfRequestBuffer;
byte* getnfRequestBufferPointer;
Request getnf;

static ReadOnlySpan<byte> GETF => "*2\r\n$3\r\nGET\r\n$1\r\na\r\n"u8;
byte[] getfRequestBuffer;
byte* getfRequestBufferPointer;
Request getf;

static ReadOnlySpan<byte> INCR => "*2\r\n$4\r\nINCR\r\n$1\r\ni\r\n"u8;
byte[] incrRequestBuffer;
byte* incrRequestBufferPointer;
Request incr;

static ReadOnlySpan<byte> DECR => "*2\r\n$4\r\nDECR\r\n$1\r\nj\r\n"u8;
byte[] decrRequestBuffer;
byte* decrRequestBufferPointer;
Request decr;

static ReadOnlySpan<byte> INCRBY => "*3\r\n$6\r\nINCRBY\r\n$1\r\nk\r\n$10\r\n1234567890\r\n"u8;
byte[] incrbyRequestBuffer;
byte* incrbyRequestBufferPointer;
Request incrby;

static ReadOnlySpan<byte> DECRBY => "*3\r\n$6\r\nDECRBY\r\n$1\r\nl\r\n$10\r\n1234567890\r\n"u8;
byte[] decrbyRequestBuffer;
byte* decrbyRequestBufferPointer;
Request decrby;

public override void GlobalSetup()
{
base.GlobalSetup();
SetupOperation(ref setRequestBuffer, ref setRequestBufferPointer, SET);
SetupOperation(ref setexRequestBuffer, ref setexRequestBufferPointer, SETEX);
SetupOperation(ref setnxRequestBuffer, ref setnxRequestBufferPointer, SETNX);
SetupOperation(ref setxxRequestBuffer, ref setxxRequestBufferPointer, SETXX);
SetupOperation(ref getfRequestBuffer, ref getfRequestBufferPointer, GETF);
SetupOperation(ref getnfRequestBuffer, ref getnfRequestBufferPointer, GETNF);
SetupOperation(ref incrRequestBuffer, ref incrRequestBufferPointer, INCR);
SetupOperation(ref decrRequestBuffer, ref decrRequestBufferPointer, DECR);
SetupOperation(ref incrbyRequestBuffer, ref incrbyRequestBufferPointer, INCRBY);
SetupOperation(ref decrbyRequestBuffer, ref decrbyRequestBufferPointer, DECRBY);
SetupOperation(ref set, SET);
SetupOperation(ref setex, SETEX);
SetupOperation(ref setnx, SETNX);
SetupOperation(ref setxx, SETXX);
SetupOperation(ref getf, GETF);
SetupOperation(ref getnf, GETNF);
SetupOperation(ref incr, INCR);
SetupOperation(ref decr, DECR);
SetupOperation(ref incrby, INCRBY);
SetupOperation(ref decrby, DECRBY);

// Pre-populate data
SlowConsumeMessage("*3\r\n$3\r\nSET\r\n$1\r\na\r\n$1\r\na\r\n"u8);
Expand All @@ -74,63 +65,63 @@ public override void GlobalSetup()
}

[Benchmark]
public void Set()
public async ValueTask Set()
{
Send(setRequestBuffer, setRequestBufferPointer, setRequestBuffer.Length);
await Send(set);
}

[Benchmark]
public void SetEx()
public async ValueTask SetEx()
{
Send(setexRequestBuffer, setexRequestBufferPointer, setexRequestBuffer.Length);
await Send(setex);
}

[Benchmark]
public void SetNx()
public async ValueTask SetNx()
{
Send(setnxRequestBuffer, setnxRequestBufferPointer, setnxRequestBuffer.Length);
await Send(setnx);
}

[Benchmark]
public void SetXx()
public async ValueTask SetXx()
{
Send(setxxRequestBuffer, setxxRequestBufferPointer, setxxRequestBuffer.Length);
await Send(setxx);
}

[Benchmark]
public void GetFound()
public async ValueTask GetFound()
{
Send(getfRequestBuffer, getfRequestBufferPointer, getfRequestBuffer.Length);
await Send(getf);
}

[Benchmark]
public void GetNotFound()
public async ValueTask GetNotFound()
{
Send(getnfRequestBuffer, getnfRequestBufferPointer, getnfRequestBuffer.Length);
await Send(getnf);
}

[Benchmark]
public void Increment()
public async ValueTask Increment()
{
Send(incrRequestBuffer, incrRequestBufferPointer, incrRequestBuffer.Length);
await Send(incr);
}

[Benchmark]
public void Decrement()
public async ValueTask Decrement()
{
Send(decrRequestBuffer, decrRequestBufferPointer, decrRequestBuffer.Length);
await Send(decr);
}

[Benchmark]
public void IncrementBy()
public async ValueTask IncrementBy()
{
Send(incrbyRequestBuffer, incrbyRequestBufferPointer, incrbyRequestBuffer.Length);
await Send(incrby);
}

[Benchmark]
public void DecrementBy()
public async ValueTask DecrementBy()
{
Send(decrbyRequestBuffer, decrbyRequestBufferPointer, decrbyRequestBuffer.Length);
await Send(decrby);
}
}
}
8 changes: 4 additions & 4 deletions benchmark/BDN.benchmark/Operations/BasicOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

using BenchmarkDotNet.Attributes;
using Embedded.server;

namespace BDN.benchmark.Operations
{
Expand All @@ -12,19 +13,18 @@ namespace BDN.benchmark.Operations
public unsafe class BasicOperations : OperationsBase
{
static ReadOnlySpan<byte> INLINE_PING => "PING\r\n"u8;
byte[] pingRequestBuffer;
byte* pingRequestBufferPointer;
Request ping;

public override void GlobalSetup()
{
base.GlobalSetup();
SetupOperation(ref pingRequestBuffer, ref pingRequestBufferPointer, INLINE_PING);
SetupOperation(ref ping, INLINE_PING);
}

[Benchmark]
public void InlinePing()
{
Send(pingRequestBuffer, pingRequestBufferPointer, pingRequestBuffer.Length);
Send(ping);
}
}
}
Loading

0 comments on commit 436052f

Please sign in to comment.