From d335d7adb094a2f20f3476840a9c841cd04f08ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20N=C3=A4geli?= Date: Mon, 27 Jan 2025 10:31:42 +0100 Subject: [PATCH 1/3] Update to GenHTTP 9.6 and use a regular handler for JSON --- .../genhttp/Benchmarks/Benchmarks.csproj | 14 +++---- .../CSharp/genhttp/Benchmarks/Program.cs | 6 ++- .../genhttp/Benchmarks/Tests/JsonHandler.cs | 39 +++++++++++++++++++ .../genhttp/Benchmarks/Tests/JsonResource.cs | 20 ---------- 4 files changed, 50 insertions(+), 29 deletions(-) create mode 100644 frameworks/CSharp/genhttp/Benchmarks/Tests/JsonHandler.cs delete mode 100644 frameworks/CSharp/genhttp/Benchmarks/Tests/JsonResource.cs diff --git a/frameworks/CSharp/genhttp/Benchmarks/Benchmarks.csproj b/frameworks/CSharp/genhttp/Benchmarks/Benchmarks.csproj index b96158a711b..3d8e0c38837 100644 --- a/frameworks/CSharp/genhttp/Benchmarks/Benchmarks.csproj +++ b/frameworks/CSharp/genhttp/Benchmarks/Benchmarks.csproj @@ -16,22 +16,22 @@ - - + + - + - + - + - - + + diff --git a/frameworks/CSharp/genhttp/Benchmarks/Program.cs b/frameworks/CSharp/genhttp/Benchmarks/Program.cs index aa2eb68938a..dd55ad6b782 100644 --- a/frameworks/CSharp/genhttp/Benchmarks/Program.cs +++ b/frameworks/CSharp/genhttp/Benchmarks/Program.cs @@ -1,14 +1,16 @@ using Benchmarks.Tests; using Benchmarks.Utilities; -using GenHTTP.Engine.Kestrel; + +using GenHTTP.Engine.Internal; + using GenHTTP.Modules.IO; using GenHTTP.Modules.Layouting; using GenHTTP.Modules.Webservices; var tests = Layout.Create() .Add("plaintext", Content.From(Resource.FromString("Hello, World!"))) + .Add("json", new JsonHandler()) .Add("fortunes", new FortuneHandler()) - .AddService("json") .AddService("db") .AddService("queries") .AddService("updates") diff --git a/frameworks/CSharp/genhttp/Benchmarks/Tests/JsonHandler.cs b/frameworks/CSharp/genhttp/Benchmarks/Tests/JsonHandler.cs new file mode 100644 index 00000000000..4944c669198 --- /dev/null +++ b/frameworks/CSharp/genhttp/Benchmarks/Tests/JsonHandler.cs @@ -0,0 +1,39 @@ +using System.Text.Json; + +using GenHTTP.Api.Content; +using GenHTTP.Api.Protocol; + +using GenHTTP.Modules.Conversion.Serializers.Json; + +namespace Benchmarks.Tests; + +public sealed class JsonResult +{ + + public string Message { get; set; } +} + +public sealed class JsonHandler : IHandler +{ + private static readonly FlexibleContentType _ContentType = new(ContentType.ApplicationJson, "utf-8"); + + private static readonly JsonSerializerOptions _Options = new(); + + public ValueTask PrepareAsync() => new(); + + public ValueTask HandleAsync(IRequest request) + { + var result = new JsonResult() + { + Message = "Hello, World!" + }; + + var response = request.Respond() + .Content(new JsonContent(result, _Options)) + .Type(_ContentType) + .Build(); + + return new(response); + } + +} diff --git a/frameworks/CSharp/genhttp/Benchmarks/Tests/JsonResource.cs b/frameworks/CSharp/genhttp/Benchmarks/Tests/JsonResource.cs deleted file mode 100644 index 1fae7c88922..00000000000 --- a/frameworks/CSharp/genhttp/Benchmarks/Tests/JsonResource.cs +++ /dev/null @@ -1,20 +0,0 @@ -using GenHTTP.Modules.Webservices; - -namespace Benchmarks.Tests; - -public sealed class JsonResult -{ - - public string Message { get; set; } -} - -public sealed class JsonResource -{ - - [ResourceMethod] - public JsonResult GetMessage() => new() - { - Message = "Hello, World!" - }; - -} From 6a87a1b560e1e3bfdaadc3db21639677443cd3d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20N=C3=A4geli?= Date: Mon, 27 Jan 2025 10:37:30 +0100 Subject: [PATCH 2/3] Use the same .NET optimizations as everyone elese --- frameworks/CSharp/genhttp/genhttp.dockerfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frameworks/CSharp/genhttp/genhttp.dockerfile b/frameworks/CSharp/genhttp/genhttp.dockerfile index 202df7ddedf..8c473477a61 100644 --- a/frameworks/CSharp/genhttp/genhttp.dockerfile +++ b/frameworks/CSharp/genhttp/genhttp.dockerfile @@ -11,6 +11,11 @@ RUN dotnet publish -c release -o /app -r linux-musl-x64 --no-restore --self-cont # final stage/image FROM mcr.microsoft.com/dotnet/runtime-deps:9.0-alpine + +ENV DOTNET_GCDynamicAdaptationMode=0 +ENV DOTNET_ReadyToRun=0 +ENV DOTNET_HillClimbing_Disable=1 + WORKDIR /app COPY --from=build /app . From 23569e6e5ab5758a81a33f15d27fcd50471b0a17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20N=C3=A4geli?= Date: Fri, 31 Jan 2025 13:43:51 +0100 Subject: [PATCH 3/3] Update to 9.6.2 --- frameworks/CSharp/genhttp/Benchmarks/Benchmarks.csproj | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/frameworks/CSharp/genhttp/Benchmarks/Benchmarks.csproj b/frameworks/CSharp/genhttp/Benchmarks/Benchmarks.csproj index 3d8e0c38837..529f7add6ca 100644 --- a/frameworks/CSharp/genhttp/Benchmarks/Benchmarks.csproj +++ b/frameworks/CSharp/genhttp/Benchmarks/Benchmarks.csproj @@ -26,9 +26,8 @@ - - - + +