Browse Source

Add Reaper benchmark (#8554)

Rudi Visser 1 year ago
parent
commit
cd97923b51

+ 17 - 0
frameworks/CSharp/reaper/README.md

@@ -0,0 +1,17 @@
+# Reaper Benchmarking Test
+
+[Reaper](https://github.com/Reaper-Net/Reaper) is a .NET 8+ Source Generator-based REPR pattern API endpoint library.
+
+### Test Type Implementation Source Code
+
+* [JSON](src/Benchmark/JsonEndpoint.cs)
+* [PLAINTEXT](src/Benchmark/PlainTextEndpoint.cs)
+
+## Test URLs
+### JSON
+
+http://localhost:8080/json
+
+### PLAINTEXT
+
+http://localhost:8080/plaintext

+ 16 - 0
frameworks/CSharp/reaper/ReaperTechEmpower.sln

@@ -0,0 +1,16 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmark", "src\Benchmark\Benchmark.csproj", "{F7BCAEA7-516A-4D65-915C-F9A43C6E875D}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{F7BCAEA7-516A-4D65-915C-F9A43C6E875D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{F7BCAEA7-516A-4D65-915C-F9A43C6E875D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{F7BCAEA7-516A-4D65-915C-F9A43C6E875D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{F7BCAEA7-516A-4D65-915C-F9A43C6E875D}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+EndGlobal

+ 26 - 0
frameworks/CSharp/reaper/benchmark_config.json

@@ -0,0 +1,26 @@
+{
+  "framework": "reaper",
+  "tests": [
+    {
+      "default": {
+        "json_url": "/json",
+        "plaintext_url": "/plaintext",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Micro",
+        "database": "None",
+        "framework": "Reaper",
+        "language": "C#",
+        "flavor": "CoreCLR",
+        "orm": "None",
+        "platform": ".NET",
+        "webserver": "Kestrel",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "Reaper [aot,slim]",
+        "notes": "",
+        "versus": "aspnetcore-minimal"
+      }
+    }
+  ]
+}

+ 14 - 0
frameworks/CSharp/reaper/reaper.dockerfile

@@ -0,0 +1,14 @@
+FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
+WORKDIR /src
+COPY src .
+RUN apt-get update \
+    && apt-get install -y --no-install-recommends \
+       clang zlib1g-dev
+WORKDIR "/src/Benchmark"
+RUN dotnet publish "Benchmark.csproj" -c Release -o /app/publish
+
+FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
+WORKDIR /app
+EXPOSE 8080
+COPY --from=build /app/publish .
+ENTRYPOINT ["./Benchmark"]

+ 25 - 0
frameworks/CSharp/reaper/src/Benchmark/Benchmark.csproj

@@ -0,0 +1,25 @@
+<Project Sdk="Microsoft.NET.Sdk.Web">
+
+    <PropertyGroup>
+        <TargetFramework>net8.0</TargetFramework>
+        <Nullable>enable</Nullable>
+        <ImplicitUsings>enable</ImplicitUsings>
+        <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
+        <EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>
+        <InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);Reaper.Generated</InterceptorsPreviewNamespaces>
+        <PublishAot>true</PublishAot>
+        <OptimizationPreference>Speed</OptimizationPreference>
+    </PropertyGroup>
+
+    <ItemGroup>
+      <Content Include="..\.dockerignore">
+        <Link>.dockerignore</Link>
+      </Content>
+    </ItemGroup>
+    
+    <ItemGroup>
+        <PackageReference Include="Reaper.Core" Version="0.1.0-alpha.0.6" />
+        <PackageReference Include="Reaper.SourceGenerator" Version="0.1.0-alpha.0.6" />
+    </ItemGroup>
+
+</Project>

+ 19 - 0
frameworks/CSharp/reaper/src/Benchmark/JsonEndpoint.cs

@@ -0,0 +1,19 @@
+using Reaper;
+using Reaper.Attributes;
+
+namespace Benchmark;
+
+public class JsonResponse
+{
+    public string Message { get; set; } = default!;
+}
+
+[ReaperRoute(HttpVerbs.Get, "/json")]
+public class JsonEndpoint : ReaperEndpointXR<JsonResponse>
+{
+    public override Task<JsonResponse> HandleAsync()
+    {
+        Context.Response.ContentLength = 27;
+        return Task.FromResult(new JsonResponse { Message = "Hello, World!" });
+    }
+}

+ 16 - 0
frameworks/CSharp/reaper/src/Benchmark/PlainTextEndpoint.cs

@@ -0,0 +1,16 @@
+using Reaper;
+using Reaper.Attributes;
+
+namespace Benchmark;
+
+[ReaperRoute(HttpVerbs.Get, "/plaintext")]
+public class PlainTextEndpoint : ReaperEndpointXR<string>
+{
+    public override Task<string> HandleAsync()
+    {
+        Context.Response.StatusCode = 200;
+        Context.Response.ContentType = "text/plain";
+        Context.Response.ContentLength = 13;
+        return Task.FromResult("Hello, World!");
+    }
+}

+ 22 - 0
frameworks/CSharp/reaper/src/Benchmark/Program.cs

@@ -0,0 +1,22 @@
+using System.Text.Json.Serialization;
+using Benchmark;
+using Reaper;
+
+var builder = WebApplication.CreateSlimBuilder(args);
+builder.Logging.ClearProviders();
+builder.Logging.Configure(o => o.ActivityTrackingOptions = ActivityTrackingOptions.None);
+builder.Services.ConfigureHttpJsonOptions(o =>
+{
+    o.SerializerOptions.TypeInfoResolverChain.Insert(0, SourceGenerationContext.Default);
+});
+builder.UseReaper();
+
+var app = builder.Build();
+
+app.UseReaperMiddleware();
+app.MapReaperEndpoints();
+
+app.Run();
+
+[JsonSerializable(typeof(JsonResponse))]
+internal partial class SourceGenerationContext : JsonSerializerContext { }

+ 38 - 0
frameworks/CSharp/reaper/src/Benchmark/Properties/launchSettings.json

@@ -0,0 +1,38 @@
+{
+  "$schema": "http://json.schemastore.org/launchsettings.json",
+  "iisSettings": {
+    "windowsAuthentication": false,
+    "anonymousAuthentication": true,
+    "iisExpress": {
+      "applicationUrl": "http://localhost:55625",
+      "sslPort": 44373
+    }
+  },
+  "profiles": {
+    "http": {
+      "commandName": "Project",
+      "dotnetRunMessages": true,
+      "launchBrowser": true,
+      "applicationUrl": "http://localhost:5286",
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      }
+    },
+    "https": {
+      "commandName": "Project",
+      "dotnetRunMessages": true,
+      "launchBrowser": true,
+      "applicationUrl": "https://localhost:7035;http://localhost:5286",
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      }
+    },
+    "IIS Express": {
+      "commandName": "IISExpress",
+      "launchBrowser": true,
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      }
+    }
+  }
+}

+ 8 - 0
frameworks/CSharp/reaper/src/Benchmark/appsettings.Development.json

@@ -0,0 +1,8 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Information",
+      "Microsoft.AspNetCore": "Warning"
+    }
+  }
+}

+ 9 - 0
frameworks/CSharp/reaper/src/Benchmark/appsettings.json

@@ -0,0 +1,9 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Information",
+      "Microsoft.AspNetCore": "Warning"
+    }
+  },
+  "AllowedHosts": "*"
+}