Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement generic host #934

Draft
wants to merge 45 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
857389b
initial garnet generic host setup
s3w3nofficial Jan 23, 2025
a82cbc8
make some test use the generic host
s3w3nofficial Jan 23, 2025
85fc2f8
fix disposing
s3w3nofficial Jan 23, 2025
f912b9f
update ctor
s3w3nofficial Jan 23, 2025
cf3c67e
add garnet server using di as transient
s3w3nofficial Jan 23, 2025
41bea02
add garnert server tcp to di
s3w3nofficial Jan 23, 2025
70c9edc
add new garnet di constructor
s3w3nofficial Jan 23, 2025
e41983e
fix logo
s3w3nofficial Jan 23, 2025
17b1926
fix logging
s3w3nofficial Jan 23, 2025
8e932a0
add store factory
s3w3nofficial Jan 23, 2025
8c503e2
remove unused constructor
s3w3nofficial Jan 23, 2025
edc10be
add store wrapper factory
s3w3nofficial Jan 23, 2025
6a67bef
refactor store wrapper factory
s3w3nofficial Jan 23, 2025
83d4d6c
make HyperLogLogTests work with garnet application builder
s3w3nofficial Jan 23, 2025
6a8165c
add main store and object store wrappers to di
s3w3nofficial Jan 23, 2025
3af0379
add aof wrapper
s3w3nofficial Jan 23, 2025
58becd1
refator
s3w3nofficial Jan 23, 2025
05cb522
register provider, metrics, registration and store api to di
s3w3nofficial Jan 23, 2025
c9f752a
exposes metrics, registration and store apis in GarnetApplication
s3w3nofficial Jan 23, 2025
24a075f
make more test use the GarnetApplication
s3w3nofficial Jan 23, 2025
1eb3d38
refactor and reformat
s3w3nofficial Jan 23, 2025
5147595
add garnet application to more tests
s3w3nofficial Jan 23, 2025
b984d20
convert more tests to GarnetApplication
s3w3nofficial Jan 23, 2025
1ab35ab
fix formating
s3w3nofficial Jan 23, 2025
7e20bae
remove refactor TestUtils and fix cluster tests
s3w3nofficial Jan 23, 2025
f1e0896
refactor and await teardown
s3w3nofficial Jan 23, 2025
80592ff
fix more cluster tests
s3w3nofficial Jan 23, 2025
ec2859c
start removing unused code
s3w3nofficial Jan 23, 2025
0cafb89
Merge branch 'main' into s3w3nofficial/implement-generic-host
s3w3nofficial Jan 23, 2025
3ebc8b6
refactor
s3w3nofficial Jan 23, 2025
496c731
fix some disposing issues
s3w3nofficial Jan 24, 2025
075959f
fix typo
s3w3nofficial Jan 24, 2025
0007744
fix tests
s3w3nofficial Jan 24, 2025
1b4dcae
refactor
s3w3nofficial Jan 24, 2025
0ef801b
move code from GarnetServer to GarnetServerHostedService
s3w3nofficial Jan 24, 2025
17711c3
fix Embedded.perftest
s3w3nofficial Jan 24, 2025
49dd859
fix build
s3w3nofficial Jan 24, 2025
4152230
fix formating
s3w3nofficial Jan 24, 2025
1cc0153
fix linking
s3w3nofficial Jan 24, 2025
b5eb325
refactor
s3w3nofficial Jan 24, 2025
c496dd0
refactor
s3w3nofficial Jan 24, 2025
c79d894
remove server dispose
s3w3nofficial Jan 25, 2025
c5525df
also dispose server after stopping it
s3w3nofficial Jan 25, 2025
f9235c0
Merge branch 'main' into s3w3nofficial/implement-generic-host
s3w3nofficial Jan 25, 2025
7e30533
Merge branch 'main' into s3w3nofficial/implement-generic-host
s3w3nofficial Jan 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
<PackageVersion Include="JsonPath.Net" Version="1.1.6" />
<PackageVersion Include="KeraLua" Version="1.4.1" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
<PackageVersion Include="NUnit" Version="4.1.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageVersion Include="Microsoft.CodeAnalysis" Version="4.11.0" />
Expand Down
4 changes: 4 additions & 0 deletions benchmark/BDN.benchmark/BDN.benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@
<Compile Include="..\..\main\GarnetServer\Extensions\SetIfPM.cs" Link="Custom\SetIfPM.cs" />
</ItemGroup>

<ItemGroup>
<Folder Include="BenchmarkDotNet.Artifacts\" />
</ItemGroup>

</Project>
25 changes: 16 additions & 9 deletions benchmark/BDN.benchmark/Cluster/ClusterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

namespace BDN.benchmark.Cluster
{
unsafe class ClusterContext
class ClusterContext
{
EmbeddedRespServer server;
GarnetEmbeddedApplication server;
RespServerSession session;
readonly BenchUtils benchUtils = new();
readonly int port = 7000;
Expand All @@ -22,9 +22,11 @@ unsafe class ClusterContext
public Request[] singleMGetMSet;
public Request singleCTXNSET;

public void Dispose()
public async Task Dispose()
{
session.Dispose();
await server.StopAsync();
server.Dispose();
server.Dispose();
}

Expand All @@ -39,12 +41,17 @@ public void SetupSingleInstance(bool disableSlotVerification = false)
};
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
opt.CheckpointDir = "/tmp";
server = new EmbeddedRespServer(opt);

var builder = GarnetEmbeddedApplication.CreateHostBuilder([], opt);

server = builder.Build();

session = server.GetRespSession();

_ = server.Register.NewTransactionProc(CustomTxnSet.CommandName, () => new CustomTxnSet(), new RespCommandsInfo { Arity = CustomTxnSet.Arity });
}

public void AddSlotRange(List<(int, int)> slotRanges)
public unsafe void AddSlotRange(List<(int, int)> slotRanges)
{
foreach (var slotRange in slotRanges)
{
Expand All @@ -56,7 +63,7 @@ public void AddSlotRange(List<(int, int)> slotRanges)
}
}

public void CreateGetSet(int keySize = 8, int valueSize = 32, int batchSize = 100)
public unsafe void CreateGetSet(int keySize = 8, int valueSize = 32, int batchSize = 100)
{
var pairs = new (byte[], byte[])[batchSize];
for (var i = 0; i < batchSize; i++)
Expand Down Expand Up @@ -93,7 +100,7 @@ public void CreateGetSet(int keySize = 8, int valueSize = 32, int batchSize = 10
singleGetSet = [getReq, setReq];
}

public void CreateMGetMSet(int keySize = 8, int valueSize = 32, int batchSize = 100)
public unsafe void CreateMGetMSet(int keySize = 8, int valueSize = 32, int batchSize = 100)
{
var pairs = new (byte[], byte[])[batchSize];
for (var i = 0; i < batchSize; i++)
Expand Down Expand Up @@ -134,7 +141,7 @@ public void CreateMGetMSet(int keySize = 8, int valueSize = 32, int batchSize =
singleMGetMSet = [mGetReq, mSetReq];
}

public void CreateCTXNSET(int keySize = 8, int batchSize = 100)
public unsafe void CreateCTXNSET(int keySize = 8, int batchSize = 100)
{
var keys = new byte[8][];
for (var i = 0; i < 8; i++)
Expand Down Expand Up @@ -163,7 +170,7 @@ public void CreateCTXNSET(int keySize = 8, int batchSize = 100)
singleCTXNSET = ctxnsetReq;
}

public void Consume(byte* ptr, int length)
public unsafe void Consume(byte* ptr, int length)
=> session.TryConsumeMessages(ptr, length);
}

Expand Down
59 changes: 0 additions & 59 deletions benchmark/BDN.benchmark/Embedded/EmbeddedRespServer.cs

This file was deleted.

77 changes: 77 additions & 0 deletions benchmark/BDN.benchmark/Embedded/GarnetEmbeddedApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Garnet;
using Garnet.common;
using Garnet.server;
using Microsoft.Extensions.DependencyInjection;
using Tsavorite.core;

namespace Embedded.server;

internal sealed class GarnetEmbeddedApplication
{
public RegisterApi Register => app.Register;

readonly StoreWrapper store;
readonly SubscribeBroker<SpanByte, SpanByte, IKeySerializer<SpanByte>> subscriberBroker;
readonly GarnetApplication app;

public GarnetEmbeddedApplication(GarnetApplication app)
{
this.app = app;
this.store = app.Services.GetRequiredService<StoreWrapper>();
this.subscriberBroker =
app.Services.GetRequiredService<SubscribeBroker<SpanByte, SpanByte, IKeySerializer<SpanByte>>>();
}

public static GarnetEmbeddedApplicationBuilder CreateHostBuilder(string[] args, GarnetServerOptions options)
{
return new(new GarnetApplicationOptions
{
Args = args,
}, options);
}

public async Task StopAsync(CancellationToken cancellationToken = default)
{
await app.StopAsync(cancellationToken);
}

/// <summary>
/// Dispose server
/// </summary>
public void Dispose() => app.Dispose();

public StoreWrapper StoreWrapper => store;

/// <summary>
/// Return a direct RESP session to this server
/// </summary>
/// <returns>A new RESP server session</returns>
internal RespServerSession GetRespSession()
{
return new RespServerSession(0,
new EmbeddedNetworkSender(),
store,
subscribeBroker: this.subscriberBroker,
null,
true);
}

internal EmbeddedNetworkHandler GetNetworkHandler()
{
var server = app.Services
.GetServices<IGarnetServer>()
.OfType<GarnetServerEmbedded>()
.FirstOrDefault();

Console.WriteLine(server);

return server?.CreateNetworkHandler();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System.Linq;
using Garnet;
using Garnet.server;
using Microsoft.Extensions.DependencyInjection;

namespace Embedded.server;

internal class GarnetEmbeddedApplicationBuilder : GarnetApplicationBuilder
{
internal GarnetEmbeddedApplicationBuilder(GarnetApplicationOptions options, GarnetServerOptions garnetServerOptions)
: base(options, garnetServerOptions)
{
}

public new GarnetEmbeddedApplication Build()
{
{
var serviceDescriptor = base.Services
.FirstOrDefault(descriptor => descriptor.ServiceType == typeof(StoreWrapper));

base.Services.Remove(serviceDescriptor);
}

{
var serviceDescriptor = base.Services
.FirstOrDefault(descriptor => descriptor.ServiceType == typeof(IGarnetServer));

base.Services.Remove(serviceDescriptor);

base.Services.AddSingleton<IGarnetServer, GarnetServerEmbedded>();
}

var app = base.Build();

return new GarnetEmbeddedApplication(app);
}
}
Loading
Loading