Skip to content

Commit

Permalink
merge from fork
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenge committed Oct 9, 2024
2 parents 499decb + dd89054 commit 7f1cba9
Show file tree
Hide file tree
Showing 229 changed files with 19,060 additions and 5,558 deletions.
4 changes: 2 additions & 2 deletions .azure/pipelines/azure-pipelines-external-release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
######################################
# NOTE: Before running this pipeline to generate a new nuget package, update the version string in two places
# 1) update the name: string below (line 6) -- this is the version for the nuget package (e.g. 1.0.0)
# 2) update \libs\host\GarnetServer.cs readonly string version (~line 45) -- NOTE - these two values need to be the same
# 2) update \libs\host\GarnetServer.cs readonly string version (~line 53) -- NOTE - these two values need to be the same
######################################
name: 1.0.19
name: 1.0.30
trigger:
branches:
include:
Expand Down
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.0.1" />
<PackageVersion Include="System.Interactive.Async" Version="6.0.1" />
<PackageVersion Include="System.Text.Json" Version="8.0.4" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.0" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions Garnet.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<file src="libs\server\bin\Release\net8.0\Garnet.server.dll" target="lib\net8.0" />
<file src="libs\server\bin\Release\net8.0\Garnet.server.pdb" target="lib\net8.0" />
<file src="libs\server\bin\Release\net8.0\Garnet.server.xml" target="lib\net8.0" />
<file src="libs\resources\bin\Release\net8.0\Garnet.resources.dll" target="lib\net8.0" />
<file src="libs\resources\bin\Release\net8.0\Garnet.resources.pdb" target="lib\net8.0" />
<file src="libs\resources\bin\Release\net8.0\Garnet.resources.xml" target="lib\net8.0" />
<file src="libs\common\bin\Release\net8.0\Garnet.common.dll" target="lib\net8.0" />
<file src="libs\common\bin\Release\net8.0\Garnet.common.pdb" target="lib\net8.0" />
<file src="libs\common\bin\Release\net8.0\Garnet.common.xml" target="lib\net8.0" />
Expand Down
28 changes: 28 additions & 0 deletions Garnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,17 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleModule", "playground\SampleModule\SampleModule.csproj", "{A8CA619E-8F13-4EF8-943F-2D5E3FEBFB3F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GarnetJSON", "playground\GarnetJSON\GarnetJSON.csproj", "{2C8F1F5D-31E5-4D00-A46E-F3B1D9BC098F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MigrateBench", "playground\MigrateBench\MigrateBench.csproj", "{6B66B394-E410-4B61-9A5A-1595FF6F5E08}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "hosting", "hosting", "{01823EA4-4446-4D66-B268-DFEE55951964}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Windows", "Windows", "{697766CD-2046-46D9-958A-0FD3B46C98D4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Garnet.worker", "hosting\Windows\Garnet.worker\Garnet.worker.csproj", "{DF2DD03E-87EE-482A-9FBA-6C8FBC23BDC5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Garnet.resources", "libs\resources\Garnet.resources.csproj", "{A48412B4-FD60-467E-A5D9-F155CAB4F907}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -299,6 +308,22 @@ Global
{6B66B394-E410-4B61-9A5A-1595FF6F5E08}.Release|Any CPU.Build.0 = Release|Any CPU
{6B66B394-E410-4B61-9A5A-1595FF6F5E08}.Release|x64.ActiveCfg = Release|Any CPU
{6B66B394-E410-4B61-9A5A-1595FF6F5E08}.Release|x64.Build.0 = Release|Any CPU
{DF2DD03E-87EE-482A-9FBA-6C8FBC23BDC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DF2DD03E-87EE-482A-9FBA-6C8FBC23BDC5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DF2DD03E-87EE-482A-9FBA-6C8FBC23BDC5}.Debug|x64.ActiveCfg = Debug|Any CPU
{DF2DD03E-87EE-482A-9FBA-6C8FBC23BDC5}.Debug|x64.Build.0 = Debug|Any CPU
{DF2DD03E-87EE-482A-9FBA-6C8FBC23BDC5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DF2DD03E-87EE-482A-9FBA-6C8FBC23BDC5}.Release|Any CPU.Build.0 = Release|Any CPU
{DF2DD03E-87EE-482A-9FBA-6C8FBC23BDC5}.Release|x64.ActiveCfg = Release|Any CPU
{DF2DD03E-87EE-482A-9FBA-6C8FBC23BDC5}.Release|x64.Build.0 = Release|Any CPU
{A48412B4-FD60-467E-A5D9-F155CAB4F907}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A48412B4-FD60-467E-A5D9-F155CAB4F907}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A48412B4-FD60-467E-A5D9-F155CAB4F907}.Debug|x64.ActiveCfg = Debug|Any CPU
{A48412B4-FD60-467E-A5D9-F155CAB4F907}.Debug|x64.Build.0 = Debug|Any CPU
{A48412B4-FD60-467E-A5D9-F155CAB4F907}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A48412B4-FD60-467E-A5D9-F155CAB4F907}.Release|Any CPU.Build.0 = Release|Any CPU
{A48412B4-FD60-467E-A5D9-F155CAB4F907}.Release|x64.ActiveCfg = Release|Any CPU
{A48412B4-FD60-467E-A5D9-F155CAB4F907}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -330,6 +355,9 @@ Global
{A8CA619E-8F13-4EF8-943F-2D5E3FEBFB3F} = {69A71E2C-00E3-42F3-854E-BE157A24834E}
{2C8F1F5D-31E5-4D00-A46E-F3B1D9BC098F} = {69A71E2C-00E3-42F3-854E-BE157A24834E}
{6B66B394-E410-4B61-9A5A-1595FF6F5E08} = {69A71E2C-00E3-42F3-854E-BE157A24834E}
{697766CD-2046-46D9-958A-0FD3B46C98D4} = {01823EA4-4446-4D66-B268-DFEE55951964}
{DF2DD03E-87EE-482A-9FBA-6C8FBC23BDC5} = {697766CD-2046-46D9-958A-0FD3B46C98D4}
{A48412B4-FD60-467E-A5D9-F155CAB4F907} = {147FCE31-EC09-4C90-8E4D-37CA87ED18C3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2C02C405-4798-41CA-AF98-61EDFEF6772E}
Expand Down
103 changes: 103 additions & 0 deletions benchmark/BDN.benchmark/Resp/RespAofStress.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// 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
{
[MemoryDiagnoser]
public unsafe class RespAofStress
{
EmbeddedRespServer server;
RespServerSession session;
const int batchSize = 128;

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;

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

static ReadOnlySpan<byte> LPUSHPOP => "*3\r\n$5\r\nLPUSH\r\n$1\r\nd\r\n$1\r\ne\r\n*2\r\n$4\r\nLPOP\r\n$1\r\nd\r\n"u8;
byte[] lPushPopRequestBuffer;
byte* lPushPopRequestBufferPointer;

[GlobalSetup]
public void GlobalSetup()
{
var opt = new GarnetServerOptions
{
QuietMode = true,
EnableAOF = true,
UseAofNullDevice = true,
MainMemoryReplication = true,
CommitFrequencyMs = -1,
AofPageSize = "128m",
AofMemorySize = "256m",
};
server = new EmbeddedRespServer(opt);

session = server.GetRespSession();

setRequestBuffer = GC.AllocateArray<byte>(SET.Length * batchSize, pinned: true);
setRequestBufferPointer = (byte*)Unsafe.AsPointer(ref setRequestBuffer[0]);
for (int i = 0; i < batchSize; i++)
SET.CopyTo(new Span<byte>(setRequestBuffer).Slice(i * SET.Length));

_ = session.TryConsumeMessages(setRequestBufferPointer, setRequestBuffer.Length);

incrRequestBuffer = GC.AllocateArray<byte>(INCR.Length * batchSize, pinned: true);
incrRequestBufferPointer = (byte*)Unsafe.AsPointer(ref incrRequestBuffer[0]);
for (int i = 0; i < batchSize; i++)
INCR.CopyTo(new Span<byte>(incrRequestBuffer).Slice(i * INCR.Length));

_ = session.TryConsumeMessages(incrRequestBufferPointer, incrRequestBuffer.Length);

lPushPopRequestBuffer = GC.AllocateArray<byte>(LPUSHPOP.Length * batchSize, pinned: true);
lPushPopRequestBufferPointer = (byte*)Unsafe.AsPointer(ref lPushPopRequestBuffer[0]);
for (int i = 0; i < batchSize; i++)
LPUSHPOP.CopyTo(new Span<byte>(lPushPopRequestBuffer).Slice(i * LPUSHPOP.Length));

// Pre-populate list with a single element to avoid repeatedly emptying it during the benchmark
SlowConsumeMessage("*3\r\n$5\r\nLPUSH\r\n$1\r\nd\r\n$1\r\nf\r\n"u8);
}

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

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

[Benchmark]
public void Increment()
{
_ = session.TryConsumeMessages(incrRequestBufferPointer, incrRequestBuffer.Length);
}

[Benchmark]
public void LPushPop()
{
_ = session.TryConsumeMessages(lPushPopRequestBufferPointer, lPushPopRequestBuffer.Length);
}

private 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));
_ = session.TryConsumeMessages(bufferPointer, buffer.Length);
}
}
}
17 changes: 16 additions & 1 deletion benchmark/BDN.benchmark/Resp/RespParseStress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public unsafe class RespParseStress
byte[] getRequestBuffer;
byte* getRequestBufferPointer;

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

static ReadOnlySpan<byte> ZADDREM => "*4\r\n$4\r\nZADD\r\n$1\r\nc\r\n$1\r\n1\r\n$1\r\nc\r\n*3\r\n$4\r\nZREM\r\n$1\r\nc\r\n$1\r\nc\r\n"u8;
byte[] zAddRemRequestBuffer;
byte* zAddRemRequestBufferPointer;
Expand Down Expand Up @@ -92,6 +96,11 @@ public void GlobalSetup()
for (int i = 0; i < batchSize; i++)
GET.CopyTo(new Span<byte>(getRequestBuffer).Slice(i * GET.Length));

incrRequestBuffer = GC.AllocateArray<byte>(INCR.Length * batchSize, pinned: true);
incrRequestBufferPointer = (byte*)Unsafe.AsPointer(ref incrRequestBuffer[0]);
for (int i = 0; i < batchSize; i++)
INCR.CopyTo(new Span<byte>(incrRequestBuffer).Slice(i * INCR.Length));

zAddRemRequestBuffer = GC.AllocateArray<byte>(ZADDREM.Length * batchSize, pinned: true);
zAddRemRequestBufferPointer = (byte*)Unsafe.AsPointer(ref zAddRemRequestBuffer[0]);
for (int i = 0; i < batchSize; i++)
Expand All @@ -116,7 +125,7 @@ public void GlobalSetup()
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);

// Pre-populate list with a single element to avoid repeatedly emptying it during the benchmark
SlowConsumeMessage("*3\r\n$4\r\nLPUSH\r\n$1\r\nd\r\n$1\r\nf\r\n"u8);
SlowConsumeMessage("*3\r\n$5\r\nLPUSH\r\n$1\r\nd\r\n$1\r\nf\r\n"u8);

// Pre-populate set with a single element to avoid repeatedly emptying it during the benchmark
SlowConsumeMessage("*3\r\n$4\r\nSADD\r\n$1\r\ne\r\n$1\r\nb\r\n"u8);
Expand Down Expand Up @@ -164,6 +173,12 @@ public void Get()
_ = session.TryConsumeMessages(getRequestBufferPointer, getRequestBuffer.Length);
}

[Benchmark]
public void Increment()
{
_ = session.TryConsumeMessages(incrRequestBufferPointer, incrRequestBuffer.Length);
}

[Benchmark]
public void ZAddRem()
{
Expand Down
2 changes: 1 addition & 1 deletion benchmark/Resp.benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static void Main(string[] args)

static void WaitForServer(Options opts)
{
using var client = new GarnetClientSession(opts.Address, opts.Port, opts.EnableTLS ? BenchUtils.GetTlsOptions(opts.TlsHost, opts.CertFileName, opts.CertPassword) : null);
using var client = new GarnetClientSession(opts.Address, opts.Port, new(), tlsOptions: opts.EnableTLS ? BenchUtils.GetTlsOptions(opts.TlsHost, opts.CertFileName, opts.CertPassword) : null);
while (true)
{
try
Expand Down
12 changes: 8 additions & 4 deletions benchmark/Resp.benchmark/RespOnlineBench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private void InitializeClients()
{
gcsPool = new AsyncPool<GarnetClientSession>(opts.NumThreads.First(), () =>
{
var c = new GarnetClientSession(address, port, opts.EnableTLS ? BenchUtils.GetTlsOptions(opts.TlsHost, opts.CertFileName, opts.CertPassword) : null);
var c = new GarnetClientSession(address, port, new(), tlsOptions: opts.EnableTLS ? BenchUtils.GetTlsOptions(opts.TlsHost, opts.CertFileName, opts.CertPassword) : null);
c.Connect();
if (auth != null)
{
Expand Down Expand Up @@ -573,8 +573,8 @@ public async void OpRunnerGarnetClientSession(int thread_id)
client = new GarnetClientSession(
address,
port,
opts.EnableTLS ? BenchUtils.GetTlsOptions(opts.TlsHost, opts.CertFileName, opts.CertPassword) : null,
bufferSize: Math.Max(bufferSizeValue, opts.ValueLength * opts.IntraThreadParallelism));
new(Math.Max(bufferSizeValue, opts.ValueLength * opts.IntraThreadParallelism)),
tlsOptions: opts.EnableTLS ? BenchUtils.GetTlsOptions(opts.TlsHost, opts.CertFileName, opts.CertPassword) : null);
client.Connect();
if (auth != null)
{
Expand Down Expand Up @@ -669,7 +669,11 @@ public async void OpRunnerGarnetClientSessionParallel(int thread_id, int paralle
GarnetClientSession client = null;
if (!opts.Pool)
{
client = new GarnetClientSession(address, port, opts.EnableTLS ? BenchUtils.GetTlsOptions(opts.TlsHost, opts.CertFileName, opts.CertPassword) : null, null, null, Math.Max(131072, opts.IntraThreadParallelism * opts.ValueLength));
client = new GarnetClientSession(
address,
port,
new NetworkBufferSettings(Math.Max(131072, opts.IntraThreadParallelism * opts.ValueLength)),
tlsOptions: opts.EnableTLS ? BenchUtils.GetTlsOptions(opts.TlsHost, opts.CertFileName, opts.CertPassword) : null);
client.Connect();
if (auth != null)
{
Expand Down
2 changes: 1 addition & 1 deletion benchmark/Resp.benchmark/RespPerfBench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ private void GarnetClientSessionOperateThreadRunner(int NumOps, OpType opType, R
default:
throw new Exception($"opType: {opType} benchmark not supported with GarnetClientSession!");
}
var c = new GarnetClientSession(opts.Address, opts.Port, opts.EnableTLS ? BenchUtils.GetTlsOptions(opts.TlsHost, opts.CertFileName, opts.CertPassword) : null);
var c = new GarnetClientSession(opts.Address, opts.Port, new(), tlsOptions: opts.EnableTLS ? BenchUtils.GetTlsOptions(opts.TlsHost, opts.CertFileName, opts.CertPassword) : null);
c.Connect();
if (opts.Auth != null)
{
Expand Down
4 changes: 2 additions & 2 deletions benchmark/Resp.benchmark/TxnPerfBench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void Run()
{
gcsPool = new AsyncPool<GarnetClientSession>(opts.NumThreads.First(), () =>
{
var c = new GarnetClientSession(address, port, opts.EnableTLS ? BenchUtils.GetTlsOptions(opts.TlsHost, opts.CertFileName, opts.CertPassword) : null);
var c = new GarnetClientSession(address, port, new(), tlsOptions: opts.EnableTLS ? BenchUtils.GetTlsOptions(opts.TlsHost, opts.CertFileName, opts.CertPassword) : null);
c.Connect();
if (auth != null)
{
Expand Down Expand Up @@ -325,7 +325,7 @@ public void OpRunnerSERedis(int thread_id)
public void LoadData()
{
var req = new OnlineReqGen(0, opts.DbSize, true, opts.Zipf, opts.KeyLength, opts.ValueLength);
GarnetClientSession client = new(address, port, opts.EnableTLS ? BenchUtils.GetTlsOptions(opts.TlsHost, opts.CertFileName, opts.CertPassword) : null);
GarnetClientSession client = new(address, port, new(), tlsOptions: opts.EnableTLS ? BenchUtils.GetTlsOptions(opts.TlsHost, opts.CertFileName, opts.CertPassword) : null);
client.Connect();
if (auth != null)
{
Expand Down
16 changes: 16 additions & 0 deletions hosting/Windows/Garnet.worker/Garnet.worker.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\libs\host\Garnet.host.csproj" />
</ItemGroup>

</Project>
23 changes: 23 additions & 0 deletions hosting/Windows/Garnet.worker/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using Garnet;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

class Program
{
static void Main(string[] args)
{
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService(_ => new Worker(args));

builder.Services.AddWindowsService(options =>
{
options.ServiceName = "Microsoft Garnet Server";
});

var host = builder.Build();
host.Run();
}
}
Loading

0 comments on commit 7f1cba9

Please sign in to comment.