Skip to content

Commit

Permalink
Add StoreFunctions and Allocator wrapper to TsavoriteKV (#542)
Browse files Browse the repository at this point in the history
* WIP StoreFunctions and allocator wrapper

* More WIP on StoreFunctions and Allocator wrapper

* Still more WIP on StoreFunctions and Allocator wrapper

* More test-conversion WIP for StoreFunctions

* More StoreFunctions test-conversion WIP

* More StoreFunctions test-conversion WIP

* Test conversion to StoreFunctions complete; BasicTests run

* Fix StoreFunctions serializers

* Most tests succeed

* All tests pass

* Ensure kvSettings sizes are 'long'

* AggressiveInline GetTailAddress()

* Fix YCSB hash table size setting and add more AggressiveInlining

* Convert Garnet to use StoreFunctions

* formatting nits

* update new ListOpsMultiple routine to StoreFunctions

* Convert ISessionFunctions.Dispose* to StoreFunctions.DisposeRecord
Add StoreFunctions.OnCheckpointComplete
Fix allocator on UT

* Streamline TAllocator in *AllocatorImpl; add some AggressiveInlining

* Update StoreFunctions doc
Add BDN.Benchmark RespGetSetStress
Move ReadCacheSettings to its own file

* Add a BDN.benchmark to Tsavorite; so far only for InliningDiagnoser tests
Rename Tsavorite.benchmark.exe to YCSB.benchmark.exe and move this to be with BDN.benchmark under the benchmark directory
Add some AggressiveInlining for some things shown by the diagnoser

* More cleanup suggested by InliningDiagnoser: convert some set_<Property> to Set/Clear pairs, add some AggressiveInlining, and move clientSession.InPlaceUpdater into SessionFunctionsWrapper.InPlaceUpdater as it was only called once.
Rename TsavoriteKVSettings to KVSettings for brevity

* YCSB - fix Uniform initialization for small-data out-of-range key handling

* Rename to BDN-Tsavorite.benchmark as BDN requires unique project names

* Ensure BlittableAllocator k,v types are blittable

* dotnet format cleanup

* Modify BDN RespTsavoriteStress to be batched and avoid "fixed"

* Add 'using' for MainStoreAllocator for symmetry
  • Loading branch information
TedHartMS committed Aug 2, 2024
1 parent 98772c0 commit d156731
Show file tree
Hide file tree
Showing 257 changed files with 8,985 additions and 7,604 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<ItemGroup>
<PackageVersion Include="Azure.Storage.Blobs" Version="12.14.1" />
<PackageVersion Include="BenchmarkDotNet" Version="0.13.12" />
<PackageVersion Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.12" />
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NUnit" Version="3.13.3" />
Expand Down
81 changes: 81 additions & 0 deletions benchmark/BDN.benchmark/Resp/RespTsavoriteStress.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using Embedded.perftest;
using Garnet.server;

namespace BDN.benchmark.Resp
{
public unsafe class RespTsavoriteStress
{
EmbeddedRespServer server;
RespServerSession session;

const int batchSize = 128;

static ReadOnlySpan<byte> GET => "*2\r\n$3\r\nGET\r\n$1\r\nx\r\n"u8;
byte[] getRequestBuffer;
byte* getRequestBufferPointer;

static ReadOnlySpan<byte> SET => "*3\r\n$3\r\nSET\r\n$1\r\nx\r\n$1\r\n1\r\n"u8;
byte[] setRequestBuffer;
byte* setRequestBufferPointer;

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

[GlobalSetup]
public void GlobalSetup()
{
var opt = new GarnetServerOptions
{
QuietMode = true
};
server = new EmbeddedRespServer(opt);
session = server.GetRespSession();

CreateBuffer(GET, out getRequestBuffer, out getRequestBufferPointer);
CreateBuffer(SET, out setRequestBuffer, out setRequestBufferPointer);
CreateBuffer(INCR, out incrRequestBuffer, out incrRequestBufferPointer);

// Set the initial value (needed for GET)
_ = session.TryConsumeMessages(setRequestBufferPointer, setRequestBuffer.Length);
}

unsafe void CreateBuffer(ReadOnlySpan<byte> cmd, out byte[] buffer, out byte* bufferPointer)
{
buffer = GC.AllocateArray<byte>(cmd.Length * batchSize, pinned: true);
bufferPointer = (byte*)Unsafe.AsPointer(ref buffer[0]);
for (int i = 0; i < batchSize; i++)
cmd.CopyTo(new Span<byte>(buffer).Slice(i * cmd.Length));
}

[GlobalCleanup]
public void GlobalCleanup()
{
session.Dispose();
server.Dispose();
}

[Benchmark]
public void Get()
{
_ = session.TryConsumeMessages(getRequestBufferPointer, getRequestBuffer.Length);
}

[Benchmark]
public void Set()
{
_ = session.TryConsumeMessages(setRequestBufferPointer, setRequestBuffer.Length);
}

[Benchmark]
public void Incr()
{
_ = session.TryConsumeMessages(incrRequestBufferPointer, incrRequestBuffer.Length);
}
}
}
7 changes: 6 additions & 1 deletion libs/cluster/Server/ClusterManagerSlotState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@

namespace Garnet.cluster
{
using BasicGarnetApi = GarnetApi<BasicContext<SpanByte, SpanByte, SpanByte, SpanByteAndMemory, long, MainStoreFunctions>, BasicContext<byte[], IGarnetObject, ObjectInput, GarnetObjectStoreOutput, long, ObjectStoreFunctions>>;
using BasicGarnetApi = GarnetApi<BasicContext<SpanByte, SpanByte, SpanByte, SpanByteAndMemory, long, MainSessionFunctions,
/* MainStoreFunctions */ StoreFunctions<SpanByte, SpanByte, SpanByteComparer, SpanByteRecordDisposer>,
SpanByteAllocator<StoreFunctions<SpanByte, SpanByte, SpanByteComparer, SpanByteRecordDisposer>>>,
BasicContext<byte[], IGarnetObject, ObjectInput, GarnetObjectStoreOutput, long, ObjectSessionFunctions,
/* ObjectStoreFunctions */ StoreFunctions<byte[], IGarnetObject, ByteArrayKeyComparer, DefaultRecordDisposer<byte[], IGarnetObject>>,
GenericAllocator<byte[], IGarnetObject, StoreFunctions<byte[], IGarnetObject, ByteArrayKeyComparer, DefaultRecordDisposer<byte[], IGarnetObject>>>>>;

/// <summary>
/// Cluster manager
Expand Down
7 changes: 6 additions & 1 deletion libs/cluster/Server/ClusterProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@

namespace Garnet.cluster
{
using BasicGarnetApi = GarnetApi<BasicContext<SpanByte, SpanByte, SpanByte, SpanByteAndMemory, long, MainStoreFunctions>, BasicContext<byte[], IGarnetObject, ObjectInput, GarnetObjectStoreOutput, long, ObjectStoreFunctions>>;
using BasicGarnetApi = GarnetApi<BasicContext<SpanByte, SpanByte, SpanByte, SpanByteAndMemory, long, MainSessionFunctions,
/* MainStoreFunctions */ StoreFunctions<SpanByte, SpanByte, SpanByteComparer, SpanByteRecordDisposer>,
SpanByteAllocator<StoreFunctions<SpanByte, SpanByte, SpanByteComparer, SpanByteRecordDisposer>>>,
BasicContext<byte[], IGarnetObject, ObjectInput, GarnetObjectStoreOutput, long, ObjectSessionFunctions,
/* ObjectStoreFunctions */ StoreFunctions<byte[], IGarnetObject, ByteArrayKeyComparer, DefaultRecordDisposer<byte[], IGarnetObject>>,
GenericAllocator<byte[], IGarnetObject, StoreFunctions<byte[], IGarnetObject, ByteArrayKeyComparer, DefaultRecordDisposer<byte[], IGarnetObject>>>>>;

/// <summary>
/// Cluster provider
Expand Down
7 changes: 6 additions & 1 deletion libs/cluster/Session/ClusterSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@

namespace Garnet.cluster
{
using BasicGarnetApi = GarnetApi<BasicContext<SpanByte, SpanByte, SpanByte, SpanByteAndMemory, long, MainStoreFunctions>, BasicContext<byte[], IGarnetObject, ObjectInput, GarnetObjectStoreOutput, long, ObjectStoreFunctions>>;
using BasicGarnetApi = GarnetApi<BasicContext<SpanByte, SpanByte, SpanByte, SpanByteAndMemory, long, MainSessionFunctions,
/* MainStoreFunctions */ StoreFunctions<SpanByte, SpanByte, SpanByteComparer, SpanByteRecordDisposer>,
SpanByteAllocator<StoreFunctions<SpanByte, SpanByte, SpanByteComparer, SpanByteRecordDisposer>>>,
BasicContext<byte[], IGarnetObject, ObjectInput, GarnetObjectStoreOutput, long, ObjectSessionFunctions,
/* ObjectStoreFunctions */ StoreFunctions<byte[], IGarnetObject, ByteArrayKeyComparer, DefaultRecordDisposer<byte[], IGarnetObject>>,
GenericAllocator<byte[], IGarnetObject, StoreFunctions<byte[], IGarnetObject, ByteArrayKeyComparer, DefaultRecordDisposer<byte[], IGarnetObject>>>>>;

internal sealed unsafe partial class ClusterSession : IClusterSession
{
Expand Down
Loading

0 comments on commit d156731

Please sign in to comment.