From 9f21c56662b259fb63ba6e7298739d3ce823eda7 Mon Sep 17 00:00:00 2001 From: cypherpotato Date: Wed, 29 Jan 2025 00:58:25 -0300 Subject: [PATCH 1/7] update sisk cadente --- frameworks/CSharp/sisk/benchmark_config.json | 18 ++++++++ frameworks/CSharp/sisk/config.toml | 13 ++++++ .../CSharp/sisk/sisk-cadente-aot.dockerfile | 19 +++++++++ .../CSharp/sisk/sisk-cadente-aot/Program.cs | 42 +++++++++++++++++++ .../CSharp/sisk/sisk-cadente-aot/sisk.csproj | 16 +++++++ .../CSharp/sisk/sisk-cadente.dockerfile | 4 +- .../CSharp/sisk/sisk-cadente/Program.cs | 26 +++++++----- .../CSharp/sisk/sisk-cadente/sisk.csproj | 22 +++++----- 8 files changed, 137 insertions(+), 23 deletions(-) create mode 100644 frameworks/CSharp/sisk/sisk-cadente-aot.dockerfile create mode 100644 frameworks/CSharp/sisk/sisk-cadente-aot/Program.cs create mode 100644 frameworks/CSharp/sisk/sisk-cadente-aot/sisk.csproj diff --git a/frameworks/CSharp/sisk/benchmark_config.json b/frameworks/CSharp/sisk/benchmark_config.json index 1e8fdc046b0..7239513749f 100644 --- a/frameworks/CSharp/sisk/benchmark_config.json +++ b/frameworks/CSharp/sisk/benchmark_config.json @@ -36,6 +36,24 @@ "database_os": "Linux", "display_name": "Sisk Framework (Cadente)" } + }, + { + "cadente-aot": { + "plaintext_url": "/plaintext", + "json_url": "/json", + "port": 8080, + "approach": "Realistic", + "classification": "Platform", + "database": "None", + "framework": "Sisk", + "language": "C#", + "orm": "Raw", + "platform": ".NET", + "webserver": "Cadente", + "os": "Linux", + "database_os": "Linux", + "display_name": "Sisk Framework (Cadente, Aot)" + } } ] } \ No newline at end of file diff --git a/frameworks/CSharp/sisk/config.toml b/frameworks/CSharp/sisk/config.toml index af787b73130..a413138e231 100644 --- a/frameworks/CSharp/sisk/config.toml +++ b/frameworks/CSharp/sisk/config.toml @@ -26,3 +26,16 @@ orm = "Raw" platform = ".NET" webserver = "Cadente" versus = "None" + +[cadente-aot] +urls.plaintext = "/plaintext" +urls.json = "/json" +approach = "Realistic" +classification = "Platform" +database = "None" +database_os = "Linux" +os = "Linux" +orm = "Raw" +platform = ".NET" +webserver = "Cadente" +versus = "None" diff --git a/frameworks/CSharp/sisk/sisk-cadente-aot.dockerfile b/frameworks/CSharp/sisk/sisk-cadente-aot.dockerfile new file mode 100644 index 00000000000..0d0f970abe4 --- /dev/null +++ b/frameworks/CSharp/sisk/sisk-cadente-aot.dockerfile @@ -0,0 +1,19 @@ +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build +WORKDIR /source + +# copy csproj and restore as distinct layers +COPY sisk-cadente/*.csproj . +RUN dotnet restore -r linux-musl-x64 + +# copy and publish app and libraries +COPY sisk-cadente/ . +RUN dotnet publish -c release -o /app -r linux-musl-x64 /p:PublishAot=true /p:OptimizationPreference=Speed /p:GarbageCollectionAdaptationMode=0 + +# final stage/image +FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime +WORKDIR /app +COPY --from=build /app . + +ENTRYPOINT ["./sisk"] + +EXPOSE 8080 \ No newline at end of file diff --git a/frameworks/CSharp/sisk/sisk-cadente-aot/Program.cs b/frameworks/CSharp/sisk/sisk-cadente-aot/Program.cs new file mode 100644 index 00000000000..ae586a056de --- /dev/null +++ b/frameworks/CSharp/sisk/sisk-cadente-aot/Program.cs @@ -0,0 +1,42 @@ +using System.Net; +using System.Text; +using System.Text.Json; +using Sisk.Cadente; + +var host = new HttpHost ( new IPEndPoint ( IPAddress.Any, 8080 ) ); +host.ContextCreated += Host_ContextCreated; + +host.Start (); +Thread.Sleep ( Timeout.Infinite ); + +void Host_ContextCreated ( HttpHost sender, HttpHostContext session ) { + var request = session.Request; + + if (request.Path == "/plaintext") { + SerializePlainTextResponse ( session.Response ); + } + else if (request.Path == "/json") { + SerializeJsonResponse ( session.Response ); + } + else { + session.Response.StatusCode = 404; + } +} + +static void SerializePlainTextResponse ( HttpHostContext.HttpResponse response ) { + + var messageBytes = Encoding.UTF8.GetBytes ( "Hello, world!" ); + + response.Headers.Add ( new HttpHeader ( "Content-Type", "text/plain" ) ); + response.ResponseStream = new MemoryStream ( messageBytes ); +} + +static void SerializeJsonResponse ( HttpHostContext.HttpResponse response ) { + + var contentBytes = JsonSerializer.SerializeToUtf8Bytes ( new { + message = "Hello, world!" + } ); + + response.Headers.Add ( new HttpHeader ( "Content-Type", "application/json" ) ); + response.ResponseStream = new MemoryStream ( contentBytes ); +} \ No newline at end of file diff --git a/frameworks/CSharp/sisk/sisk-cadente-aot/sisk.csproj b/frameworks/CSharp/sisk/sisk-cadente-aot/sisk.csproj new file mode 100644 index 00000000000..ff4bed69dc4 --- /dev/null +++ b/frameworks/CSharp/sisk/sisk-cadente-aot/sisk.csproj @@ -0,0 +1,16 @@ + + + + Exe + net9.0 + enable + enable + true + true + + + + + + + \ No newline at end of file diff --git a/frameworks/CSharp/sisk/sisk-cadente.dockerfile b/frameworks/CSharp/sisk/sisk-cadente.dockerfile index 87f45780338..c5eb7a36aa6 100644 --- a/frameworks/CSharp/sisk/sisk-cadente.dockerfile +++ b/frameworks/CSharp/sisk/sisk-cadente.dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build WORKDIR /source # copy csproj and restore as distinct layers @@ -10,7 +10,7 @@ COPY sisk-cadente/ . RUN dotnet publish -c release -o /app -r linux-musl-x64 # final stage/image -FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime +FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime WORKDIR /app COPY --from=build /app . diff --git a/frameworks/CSharp/sisk/sisk-cadente/Program.cs b/frameworks/CSharp/sisk/sisk-cadente/Program.cs index ba19a480d16..ae586a056de 100644 --- a/frameworks/CSharp/sisk/sisk-cadente/Program.cs +++ b/frameworks/CSharp/sisk/sisk-cadente/Program.cs @@ -1,8 +1,15 @@ -using System.Text; +using System.Net; +using System.Text; using System.Text.Json; using Sisk.Cadente; -var host = new HttpHost ( 8080, session => { +var host = new HttpHost ( new IPEndPoint ( IPAddress.Any, 8080 ) ); +host.ContextCreated += Host_ContextCreated; + +host.Start (); +Thread.Sleep ( Timeout.Infinite ); + +void Host_ContextCreated ( HttpHost sender, HttpHostContext session ) { var request = session.Request; if (request.Path == "/plaintext") { @@ -14,23 +21,22 @@ else { session.Response.StatusCode = 404; } -} ); +} -host.Start (); -Thread.Sleep ( Timeout.Infinite ); +static void SerializePlainTextResponse ( HttpHostContext.HttpResponse response ) { -static void SerializePlainTextResponse ( HttpResponse response ) { - var contentBytes = Encoding.UTF8.GetBytes ( "Hello, world!" ); + var messageBytes = Encoding.UTF8.GetBytes ( "Hello, world!" ); response.Headers.Add ( new HttpHeader ( "Content-Type", "text/plain" ) ); - response.ResponseStream = new MemoryStream ( contentBytes ); + response.ResponseStream = new MemoryStream ( messageBytes ); } -static void SerializeJsonResponse ( HttpResponse response ) { +static void SerializeJsonResponse ( HttpHostContext.HttpResponse response ) { + var contentBytes = JsonSerializer.SerializeToUtf8Bytes ( new { message = "Hello, world!" } ); - response.Headers.Add ( new HttpHeader ( "Content-Type", "application/json; charset=utf-8" ) ); + response.Headers.Add ( new HttpHeader ( "Content-Type", "application/json" ) ); response.ResponseStream = new MemoryStream ( contentBytes ); } \ No newline at end of file diff --git a/frameworks/CSharp/sisk/sisk-cadente/sisk.csproj b/frameworks/CSharp/sisk/sisk-cadente/sisk.csproj index 4d284054c2b..6393f4b3ed8 100644 --- a/frameworks/CSharp/sisk/sisk-cadente/sisk.csproj +++ b/frameworks/CSharp/sisk/sisk-cadente/sisk.csproj @@ -1,15 +1,15 @@  - - Exe - net8.0 - enable - enable - true - + + Exe + net9.0 + enable + enable + true + - - - + + + - + \ No newline at end of file From 55495759b7c6b1162bad279c75a2bae049ac895c Mon Sep 17 00:00:00 2001 From: cypherpotato Date: Wed, 29 Jan 2025 01:03:29 -0300 Subject: [PATCH 2/7] add missing dependencies to aot test --- frameworks/CSharp/sisk/sisk-cadente-aot.dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frameworks/CSharp/sisk/sisk-cadente-aot.dockerfile b/frameworks/CSharp/sisk/sisk-cadente-aot.dockerfile index 0d0f970abe4..bcb6b935be6 100644 --- a/frameworks/CSharp/sisk/sisk-cadente-aot.dockerfile +++ b/frameworks/CSharp/sisk/sisk-cadente-aot.dockerfile @@ -1,4 +1,6 @@ FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build +RUN apt-get update +RUN apt-get -yqq install clang zlib1g-dev WORKDIR /source # copy csproj and restore as distinct layers From b2860b9f9db6275b4aa114f03039e8d1539d273e Mon Sep 17 00:00:00 2001 From: cypherpotato Date: Wed, 29 Jan 2025 01:14:49 -0300 Subject: [PATCH 3/7] remove aot test --- frameworks/CSharp/sisk/benchmark_config.json | 18 -------- frameworks/CSharp/sisk/config.toml | 15 +------ .../CSharp/sisk/sisk-cadente-aot.dockerfile | 21 ---------- .../CSharp/sisk/sisk-cadente-aot/Program.cs | 42 ------------------- .../CSharp/sisk/sisk-cadente-aot/sisk.csproj | 16 ------- .../CSharp/sisk/sisk-cadente.dockerfile | 6 ++- 6 files changed, 6 insertions(+), 112 deletions(-) delete mode 100644 frameworks/CSharp/sisk/sisk-cadente-aot.dockerfile delete mode 100644 frameworks/CSharp/sisk/sisk-cadente-aot/Program.cs delete mode 100644 frameworks/CSharp/sisk/sisk-cadente-aot/sisk.csproj diff --git a/frameworks/CSharp/sisk/benchmark_config.json b/frameworks/CSharp/sisk/benchmark_config.json index 7239513749f..1e8fdc046b0 100644 --- a/frameworks/CSharp/sisk/benchmark_config.json +++ b/frameworks/CSharp/sisk/benchmark_config.json @@ -36,24 +36,6 @@ "database_os": "Linux", "display_name": "Sisk Framework (Cadente)" } - }, - { - "cadente-aot": { - "plaintext_url": "/plaintext", - "json_url": "/json", - "port": 8080, - "approach": "Realistic", - "classification": "Platform", - "database": "None", - "framework": "Sisk", - "language": "C#", - "orm": "Raw", - "platform": ".NET", - "webserver": "Cadente", - "os": "Linux", - "database_os": "Linux", - "display_name": "Sisk Framework (Cadente, Aot)" - } } ] } \ No newline at end of file diff --git a/frameworks/CSharp/sisk/config.toml b/frameworks/CSharp/sisk/config.toml index a413138e231..ac39e86d851 100644 --- a/frameworks/CSharp/sisk/config.toml +++ b/frameworks/CSharp/sisk/config.toml @@ -25,17 +25,4 @@ os = "Linux" orm = "Raw" platform = ".NET" webserver = "Cadente" -versus = "None" - -[cadente-aot] -urls.plaintext = "/plaintext" -urls.json = "/json" -approach = "Realistic" -classification = "Platform" -database = "None" -database_os = "Linux" -os = "Linux" -orm = "Raw" -platform = ".NET" -webserver = "Cadente" -versus = "None" +versus = "None" \ No newline at end of file diff --git a/frameworks/CSharp/sisk/sisk-cadente-aot.dockerfile b/frameworks/CSharp/sisk/sisk-cadente-aot.dockerfile deleted file mode 100644 index bcb6b935be6..00000000000 --- a/frameworks/CSharp/sisk/sisk-cadente-aot.dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build -RUN apt-get update -RUN apt-get -yqq install clang zlib1g-dev -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY sisk-cadente/*.csproj . -RUN dotnet restore -r linux-musl-x64 - -# copy and publish app and libraries -COPY sisk-cadente/ . -RUN dotnet publish -c release -o /app -r linux-musl-x64 /p:PublishAot=true /p:OptimizationPreference=Speed /p:GarbageCollectionAdaptationMode=0 - -# final stage/image -FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime -WORKDIR /app -COPY --from=build /app . - -ENTRYPOINT ["./sisk"] - -EXPOSE 8080 \ No newline at end of file diff --git a/frameworks/CSharp/sisk/sisk-cadente-aot/Program.cs b/frameworks/CSharp/sisk/sisk-cadente-aot/Program.cs deleted file mode 100644 index ae586a056de..00000000000 --- a/frameworks/CSharp/sisk/sisk-cadente-aot/Program.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Net; -using System.Text; -using System.Text.Json; -using Sisk.Cadente; - -var host = new HttpHost ( new IPEndPoint ( IPAddress.Any, 8080 ) ); -host.ContextCreated += Host_ContextCreated; - -host.Start (); -Thread.Sleep ( Timeout.Infinite ); - -void Host_ContextCreated ( HttpHost sender, HttpHostContext session ) { - var request = session.Request; - - if (request.Path == "/plaintext") { - SerializePlainTextResponse ( session.Response ); - } - else if (request.Path == "/json") { - SerializeJsonResponse ( session.Response ); - } - else { - session.Response.StatusCode = 404; - } -} - -static void SerializePlainTextResponse ( HttpHostContext.HttpResponse response ) { - - var messageBytes = Encoding.UTF8.GetBytes ( "Hello, world!" ); - - response.Headers.Add ( new HttpHeader ( "Content-Type", "text/plain" ) ); - response.ResponseStream = new MemoryStream ( messageBytes ); -} - -static void SerializeJsonResponse ( HttpHostContext.HttpResponse response ) { - - var contentBytes = JsonSerializer.SerializeToUtf8Bytes ( new { - message = "Hello, world!" - } ); - - response.Headers.Add ( new HttpHeader ( "Content-Type", "application/json" ) ); - response.ResponseStream = new MemoryStream ( contentBytes ); -} \ No newline at end of file diff --git a/frameworks/CSharp/sisk/sisk-cadente-aot/sisk.csproj b/frameworks/CSharp/sisk/sisk-cadente-aot/sisk.csproj deleted file mode 100644 index ff4bed69dc4..00000000000 --- a/frameworks/CSharp/sisk/sisk-cadente-aot/sisk.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - net9.0 - enable - enable - true - true - - - - - - - \ No newline at end of file diff --git a/frameworks/CSharp/sisk/sisk-cadente.dockerfile b/frameworks/CSharp/sisk/sisk-cadente.dockerfile index c5eb7a36aa6..34092a0e15c 100644 --- a/frameworks/CSharp/sisk/sisk-cadente.dockerfile +++ b/frameworks/CSharp/sisk/sisk-cadente.dockerfile @@ -7,7 +7,11 @@ RUN dotnet restore -r linux-musl-x64 # copy and publish app and libraries COPY sisk-cadente/ . -RUN dotnet publish -c release -o /app -r linux-musl-x64 +RUN dotnet publish -c release -o /app + +ENV DOTNET_GCDynamicAdaptationMode=0 +ENV DOTNET_ReadyToRun=0 +ENV DOTNET_HillClimbing_Disable=1 # final stage/image FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime From 4350a8238e6634e09377d8a9e833bc0ad2a50803 Mon Sep 17 00:00:00 2001 From: cypherpotato Date: Sat, 1 Feb 2025 17:09:34 -0300 Subject: [PATCH 4/7] fix: plaintext strings --- frameworks/CSharp/sisk/sisk-cadente/Program.cs | 6 +++--- frameworks/CSharp/sisk/sisk/Program.cs | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/frameworks/CSharp/sisk/sisk-cadente/Program.cs b/frameworks/CSharp/sisk/sisk-cadente/Program.cs index ae586a056de..67c65f96959 100644 --- a/frameworks/CSharp/sisk/sisk-cadente/Program.cs +++ b/frameworks/CSharp/sisk/sisk-cadente/Program.cs @@ -25,16 +25,16 @@ void Host_ContextCreated ( HttpHost sender, HttpHostContext session ) { static void SerializePlainTextResponse ( HttpHostContext.HttpResponse response ) { - var messageBytes = Encoding.UTF8.GetBytes ( "Hello, world!" ); + var messageBytes = Encoding.UTF8.GetBytes ( "Hello, World!" ); - response.Headers.Add ( new HttpHeader ( "Content-Type", "text/plain" ) ); + response.Headers.Add ( new HttpHeader ( "Content-Type", "text/plain; charset=UTF-8" ) ); response.ResponseStream = new MemoryStream ( messageBytes ); } static void SerializeJsonResponse ( HttpHostContext.HttpResponse response ) { var contentBytes = JsonSerializer.SerializeToUtf8Bytes ( new { - message = "Hello, world!" + message = "Hello, World!" } ); response.Headers.Add ( new HttpHeader ( "Content-Type", "application/json" ) ); diff --git a/frameworks/CSharp/sisk/sisk/Program.cs b/frameworks/CSharp/sisk/sisk/Program.cs index 12d331767ad..7b80417d4b7 100644 --- a/frameworks/CSharp/sisk/sisk/Program.cs +++ b/frameworks/CSharp/sisk/sisk/Program.cs @@ -1,9 +1,13 @@ using System.Net.Http.Json; +using System.Text; using Sisk.Core.Http; using Sisk.Core.Routing; var app = HttpServer.CreateBuilder ( host => { host.UseListeningPort ( "http://+:8080/" ); + host.UseConfiguration ( config => { + config.AccessLogsStream = null; + } ); } ).Build (); app.Router.SetRoute ( RouteMethod.Get, "/plaintext", PlainText ); @@ -12,11 +16,11 @@ app.Start (); static HttpResponse PlainText ( HttpRequest request ) { - return new HttpResponse ( "Hello, world!" ); + return new HttpResponse ( new StringContent ( "Hello, World!", Encoding.UTF8, "text/plain" ) ); } static HttpResponse Json ( HttpRequest request ) { return new HttpResponse ( JsonContent.Create ( new { - message = "Hello, world!" + message = "Hello, World!" } ) ); } \ No newline at end of file From cf666c11c54cbfa9817cddd10ae90d9514075df6 Mon Sep 17 00:00:00 2001 From: cypherpotato Date: Wed, 5 Feb 2025 15:10:44 -0300 Subject: [PATCH 5/7] update cadente version --- frameworks/CSharp/sisk/sisk-cadente/Program.cs | 2 ++ frameworks/CSharp/sisk/sisk-cadente/sisk.csproj | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/frameworks/CSharp/sisk/sisk-cadente/Program.cs b/frameworks/CSharp/sisk/sisk-cadente/Program.cs index 67c65f96959..a0244bdd033 100644 --- a/frameworks/CSharp/sisk/sisk-cadente/Program.cs +++ b/frameworks/CSharp/sisk/sisk-cadente/Program.cs @@ -3,6 +3,8 @@ using System.Text.Json; using Sisk.Cadente; +HttpHost.QueueSize = 4096; + var host = new HttpHost ( new IPEndPoint ( IPAddress.Any, 8080 ) ); host.ContextCreated += Host_ContextCreated; diff --git a/frameworks/CSharp/sisk/sisk-cadente/sisk.csproj b/frameworks/CSharp/sisk/sisk-cadente/sisk.csproj index 6393f4b3ed8..2670680a301 100644 --- a/frameworks/CSharp/sisk/sisk-cadente/sisk.csproj +++ b/frameworks/CSharp/sisk/sisk-cadente/sisk.csproj @@ -9,7 +9,7 @@ - + \ No newline at end of file From b92150b78cb34b74e5862e5ee6a3578a3cbcb0f3 Mon Sep 17 00:00:00 2001 From: cypherpotato Date: Sun, 23 Feb 2025 16:57:38 -0300 Subject: [PATCH 6/7] update cadente version --- frameworks/CSharp/sisk/sisk-cadente/Program.cs | 4 ++-- frameworks/CSharp/sisk/sisk-cadente/sisk.csproj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/CSharp/sisk/sisk-cadente/Program.cs b/frameworks/CSharp/sisk/sisk-cadente/Program.cs index a0244bdd033..267877ee584 100644 --- a/frameworks/CSharp/sisk/sisk-cadente/Program.cs +++ b/frameworks/CSharp/sisk/sisk-cadente/Program.cs @@ -13,7 +13,7 @@ void Host_ContextCreated ( HttpHost sender, HttpHostContext session ) { var request = session.Request; - + if (request.Path == "/plaintext") { SerializePlainTextResponse ( session.Response ); } @@ -38,7 +38,7 @@ static void SerializeJsonResponse ( HttpHostContext.HttpResponse response ) { var contentBytes = JsonSerializer.SerializeToUtf8Bytes ( new { message = "Hello, World!" } ); - + response.Headers.Add ( new HttpHeader ( "Content-Type", "application/json" ) ); response.ResponseStream = new MemoryStream ( contentBytes ); } \ No newline at end of file diff --git a/frameworks/CSharp/sisk/sisk-cadente/sisk.csproj b/frameworks/CSharp/sisk/sisk-cadente/sisk.csproj index 2670680a301..c72c3f1faee 100644 --- a/frameworks/CSharp/sisk/sisk-cadente/sisk.csproj +++ b/frameworks/CSharp/sisk/sisk-cadente/sisk.csproj @@ -9,7 +9,7 @@ - + \ No newline at end of file From 4d923621404c5e21951a344aaad1e0c529638fd7 Mon Sep 17 00:00:00 2001 From: CypherPotato Date: Mon, 10 Nov 2025 17:25:28 -0300 Subject: [PATCH 7/7] update sisk benchmarks --- .../CSharp/sisk/sisk-cadente/Program.cs | 70 ++++++++++--------- .../CSharp/sisk/sisk-cadente/sisk.csproj | 2 +- frameworks/CSharp/sisk/sisk.dockerfile | 4 ++ 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/frameworks/CSharp/sisk/sisk-cadente/Program.cs b/frameworks/CSharp/sisk/sisk-cadente/Program.cs index 267877ee584..f198260cbde 100644 --- a/frameworks/CSharp/sisk/sisk-cadente/Program.cs +++ b/frameworks/CSharp/sisk/sisk-cadente/Program.cs @@ -1,44 +1,50 @@ -using System.Net; +using System.Buffers.Text; +using System.Net; using System.Text; using System.Text.Json; using Sisk.Cadente; -HttpHost.QueueSize = 4096; - -var host = new HttpHost ( new IPEndPoint ( IPAddress.Any, 8080 ) ); -host.ContextCreated += Host_ContextCreated; +using var host = new HttpHost ( new IPEndPoint ( IPAddress.Any, 8080 ) ); +host.Handler = new DefaultHandler(); host.Start (); Thread.Sleep ( Timeout.Infinite ); -void Host_ContextCreated ( HttpHost sender, HttpHostContext session ) { - var request = session.Request; - - if (request.Path == "/plaintext") { - SerializePlainTextResponse ( session.Response ); - } - else if (request.Path == "/json") { - SerializeJsonResponse ( session.Response ); - } - else { - session.Response.StatusCode = 404; - } -} - -static void SerializePlainTextResponse ( HttpHostContext.HttpResponse response ) { - - var messageBytes = Encoding.UTF8.GetBytes ( "Hello, World!" ); - response.Headers.Add ( new HttpHeader ( "Content-Type", "text/plain; charset=UTF-8" ) ); - response.ResponseStream = new MemoryStream ( messageBytes ); -} +class DefaultHandler : HttpHostHandler +{ + public override async Task OnContextCreatedAsync(HttpHost host, HttpHostContext context) + { + var request = context.Request; + var response = context.Response; + + if (request.Path == "/plaintext") + { + var contentBytes = Encoding.UTF8.GetBytes("Hello, World!"); + + await SerializeResponseAsync(response, contentBytes, "text/plain; charset=utf-8"); + } + else if (request.Path == "/json") + { + var contentBytes = JsonSerializer.SerializeToUtf8Bytes(new + { + message = "Hello, World!" + }); + + await SerializeResponseAsync(response, contentBytes, "application/json; charset=utf-8"); + } + else + { + response.StatusCode = 404; + } + } -static void SerializeJsonResponse ( HttpHostContext.HttpResponse response ) { + static async ValueTask SerializeResponseAsync(HttpHostContext.HttpResponse response, Memory content, string contentType) + { + response.Headers.Add(new HttpHeader("Content-Type", contentType)); + response.Headers.Add(new HttpHeader("Content-Length", content.Length.ToString())); - var contentBytes = JsonSerializer.SerializeToUtf8Bytes ( new { - message = "Hello, World!" - } ); - - response.Headers.Add ( new HttpHeader ( "Content-Type", "application/json" ) ); - response.ResponseStream = new MemoryStream ( contentBytes ); + using var responseStream = await response.GetResponseStreamAsync(); + await responseStream.WriteAsync(content); + } } \ No newline at end of file diff --git a/frameworks/CSharp/sisk/sisk-cadente/sisk.csproj b/frameworks/CSharp/sisk/sisk-cadente/sisk.csproj index c72c3f1faee..12f1a5d7c2c 100644 --- a/frameworks/CSharp/sisk/sisk-cadente/sisk.csproj +++ b/frameworks/CSharp/sisk/sisk-cadente/sisk.csproj @@ -9,7 +9,7 @@ - + \ No newline at end of file diff --git a/frameworks/CSharp/sisk/sisk.dockerfile b/frameworks/CSharp/sisk/sisk.dockerfile index 2a23e04743f..6509bffbd8a 100644 --- a/frameworks/CSharp/sisk/sisk.dockerfile +++ b/frameworks/CSharp/sisk/sisk.dockerfile @@ -9,6 +9,10 @@ RUN dotnet restore -r linux-musl-x64 COPY sisk/ . RUN dotnet publish -c release -o /app -r linux-musl-x64 +ENV DOTNET_GCDynamicAdaptationMode=0 +ENV DOTNET_ReadyToRun=0 +ENV DOTNET_HillClimbing_Disable=1 + # final stage/image FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime WORKDIR /app