Skip to content

Commit d156731

Browse files
authored
Add StoreFunctions and Allocator wrapper to TsavoriteKV (#542)
* 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
1 parent 98772c0 commit d156731

File tree

257 files changed

+8985
-7604
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

257 files changed

+8985
-7604
lines changed

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<ItemGroup>
66
<PackageVersion Include="Azure.Storage.Blobs" Version="12.14.1" />
77
<PackageVersion Include="BenchmarkDotNet" Version="0.13.12" />
8+
<PackageVersion Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.12" />
89
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
910
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
1011
<PackageVersion Include="NUnit" Version="3.13.3" />
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
using System.Runtime.CompilerServices;
5+
using BenchmarkDotNet.Attributes;
6+
using Embedded.perftest;
7+
using Garnet.server;
8+
9+
namespace BDN.benchmark.Resp
10+
{
11+
public unsafe class RespTsavoriteStress
12+
{
13+
EmbeddedRespServer server;
14+
RespServerSession session;
15+
16+
const int batchSize = 128;
17+
18+
static ReadOnlySpan<byte> GET => "*2\r\n$3\r\nGET\r\n$1\r\nx\r\n"u8;
19+
byte[] getRequestBuffer;
20+
byte* getRequestBufferPointer;
21+
22+
static ReadOnlySpan<byte> SET => "*3\r\n$3\r\nSET\r\n$1\r\nx\r\n$1\r\n1\r\n"u8;
23+
byte[] setRequestBuffer;
24+
byte* setRequestBufferPointer;
25+
26+
static ReadOnlySpan<byte> INCR => "*2\r\n$4\r\nINCR\r\n$1\r\nx\r\n"u8;
27+
byte[] incrRequestBuffer;
28+
byte* incrRequestBufferPointer;
29+
30+
[GlobalSetup]
31+
public void GlobalSetup()
32+
{
33+
var opt = new GarnetServerOptions
34+
{
35+
QuietMode = true
36+
};
37+
server = new EmbeddedRespServer(opt);
38+
session = server.GetRespSession();
39+
40+
CreateBuffer(GET, out getRequestBuffer, out getRequestBufferPointer);
41+
CreateBuffer(SET, out setRequestBuffer, out setRequestBufferPointer);
42+
CreateBuffer(INCR, out incrRequestBuffer, out incrRequestBufferPointer);
43+
44+
// Set the initial value (needed for GET)
45+
_ = session.TryConsumeMessages(setRequestBufferPointer, setRequestBuffer.Length);
46+
}
47+
48+
unsafe void CreateBuffer(ReadOnlySpan<byte> cmd, out byte[] buffer, out byte* bufferPointer)
49+
{
50+
buffer = GC.AllocateArray<byte>(cmd.Length * batchSize, pinned: true);
51+
bufferPointer = (byte*)Unsafe.AsPointer(ref buffer[0]);
52+
for (int i = 0; i < batchSize; i++)
53+
cmd.CopyTo(new Span<byte>(buffer).Slice(i * cmd.Length));
54+
}
55+
56+
[GlobalCleanup]
57+
public void GlobalCleanup()
58+
{
59+
session.Dispose();
60+
server.Dispose();
61+
}
62+
63+
[Benchmark]
64+
public void Get()
65+
{
66+
_ = session.TryConsumeMessages(getRequestBufferPointer, getRequestBuffer.Length);
67+
}
68+
69+
[Benchmark]
70+
public void Set()
71+
{
72+
_ = session.TryConsumeMessages(setRequestBufferPointer, setRequestBuffer.Length);
73+
}
74+
75+
[Benchmark]
76+
public void Incr()
77+
{
78+
_ = session.TryConsumeMessages(incrRequestBufferPointer, incrRequestBuffer.Length);
79+
}
80+
}
81+
}

libs/cluster/Server/ClusterManagerSlotState.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313

1414
namespace Garnet.cluster
1515
{
16-
using BasicGarnetApi = GarnetApi<BasicContext<SpanByte, SpanByte, SpanByte, SpanByteAndMemory, long, MainStoreFunctions>, BasicContext<byte[], IGarnetObject, ObjectInput, GarnetObjectStoreOutput, long, ObjectStoreFunctions>>;
16+
using BasicGarnetApi = GarnetApi<BasicContext<SpanByte, SpanByte, SpanByte, SpanByteAndMemory, long, MainSessionFunctions,
17+
/* MainStoreFunctions */ StoreFunctions<SpanByte, SpanByte, SpanByteComparer, SpanByteRecordDisposer>,
18+
SpanByteAllocator<StoreFunctions<SpanByte, SpanByte, SpanByteComparer, SpanByteRecordDisposer>>>,
19+
BasicContext<byte[], IGarnetObject, ObjectInput, GarnetObjectStoreOutput, long, ObjectSessionFunctions,
20+
/* ObjectStoreFunctions */ StoreFunctions<byte[], IGarnetObject, ByteArrayKeyComparer, DefaultRecordDisposer<byte[], IGarnetObject>>,
21+
GenericAllocator<byte[], IGarnetObject, StoreFunctions<byte[], IGarnetObject, ByteArrayKeyComparer, DefaultRecordDisposer<byte[], IGarnetObject>>>>>;
1722

1823
/// <summary>
1924
/// Cluster manager

libs/cluster/Server/ClusterProvider.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515

1616
namespace Garnet.cluster
1717
{
18-
using BasicGarnetApi = GarnetApi<BasicContext<SpanByte, SpanByte, SpanByte, SpanByteAndMemory, long, MainStoreFunctions>, BasicContext<byte[], IGarnetObject, ObjectInput, GarnetObjectStoreOutput, long, ObjectStoreFunctions>>;
18+
using BasicGarnetApi = GarnetApi<BasicContext<SpanByte, SpanByte, SpanByte, SpanByteAndMemory, long, MainSessionFunctions,
19+
/* MainStoreFunctions */ StoreFunctions<SpanByte, SpanByte, SpanByteComparer, SpanByteRecordDisposer>,
20+
SpanByteAllocator<StoreFunctions<SpanByte, SpanByte, SpanByteComparer, SpanByteRecordDisposer>>>,
21+
BasicContext<byte[], IGarnetObject, ObjectInput, GarnetObjectStoreOutput, long, ObjectSessionFunctions,
22+
/* ObjectStoreFunctions */ StoreFunctions<byte[], IGarnetObject, ByteArrayKeyComparer, DefaultRecordDisposer<byte[], IGarnetObject>>,
23+
GenericAllocator<byte[], IGarnetObject, StoreFunctions<byte[], IGarnetObject, ByteArrayKeyComparer, DefaultRecordDisposer<byte[], IGarnetObject>>>>>;
1924

2025
/// <summary>
2126
/// Cluster provider

libs/cluster/Session/ClusterSession.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414

1515
namespace Garnet.cluster
1616
{
17-
using BasicGarnetApi = GarnetApi<BasicContext<SpanByte, SpanByte, SpanByte, SpanByteAndMemory, long, MainStoreFunctions>, BasicContext<byte[], IGarnetObject, ObjectInput, GarnetObjectStoreOutput, long, ObjectStoreFunctions>>;
17+
using BasicGarnetApi = GarnetApi<BasicContext<SpanByte, SpanByte, SpanByte, SpanByteAndMemory, long, MainSessionFunctions,
18+
/* MainStoreFunctions */ StoreFunctions<SpanByte, SpanByte, SpanByteComparer, SpanByteRecordDisposer>,
19+
SpanByteAllocator<StoreFunctions<SpanByte, SpanByte, SpanByteComparer, SpanByteRecordDisposer>>>,
20+
BasicContext<byte[], IGarnetObject, ObjectInput, GarnetObjectStoreOutput, long, ObjectSessionFunctions,
21+
/* ObjectStoreFunctions */ StoreFunctions<byte[], IGarnetObject, ByteArrayKeyComparer, DefaultRecordDisposer<byte[], IGarnetObject>>,
22+
GenericAllocator<byte[], IGarnetObject, StoreFunctions<byte[], IGarnetObject, ByteArrayKeyComparer, DefaultRecordDisposer<byte[], IGarnetObject>>>>>;
1823

1924
internal sealed unsafe partial class ClusterSession : IClusterSession
2025
{

0 commit comments

Comments
 (0)