Browse Source

Add Unhinged adapter with genhttp (#10247)

* Add Unhinged adapter with genhttp

* Update Unhinged to 9.0.5

* Update dependencies, unhinged to micro, added http parsing and routing
Diogo Martins 1 month ago
parent
commit
d62d2941db

+ 40 - 0
frameworks/CSharp/wiredio/UnhGHttp/Program.cs

@@ -0,0 +1,40 @@
+using System.Text.Json;
+using GenHTTP.Api.Protocol;
+using GenHTTP.Modules.IO;
+using GenHTTP.Modules.Layouting;
+using GenHTTP.Modules.Layouting.Provider;
+using Unhinged;
+using Unhinged.GenHttp.Experimental;
+
+internal class Program
+{
+    public static void Main(string[] args)
+    {
+        var builder = UnhingedEngine
+            .CreateBuilder()
+            .SetNWorkersSolver(() => Environment.ProcessorCount / 2)
+            .SetBacklog(16384)
+            .SetMaxEventsPerWake(512)
+            .SetMaxNumberConnectionsPerWorker(512)
+            .SetPort(8080)
+            .SetSlabSizes(32 * 1024, 16 * 1024)
+            .Map(CreateLayoutBuilder());
+        
+        var engine = builder.Build();
+        engine.Run();
+    }
+
+    private static LayoutBuilder CreateLayoutBuilder() =>
+        Layout
+            .Create()
+            .Add("/plaintext", Content.From(Resource.FromString("Hello, World!")))
+
+            .Add("/json", Content.From(
+                Resource.FromString(JsonSerializer.Serialize(new JsonMessage { message = "Hello, World!" }))
+                    .Type(new FlexibleContentType("application/json"))));
+}
+
+public class JsonMessage
+{
+    public string message { get; set; }
+}

+ 23 - 0
frameworks/CSharp/wiredio/UnhGHttp/UnhGHttp.csproj

@@ -0,0 +1,23 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+    <PropertyGroup>
+        <OutputType>Exe</OutputType>
+        <TargetFramework>net9.0</TargetFramework>
+        <ImplicitUsings>enable</ImplicitUsings>
+        <Nullable>enable</Nullable>
+
+        <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+        <IsTestAssetProject>true</IsTestAssetProject>
+        <ServerGarbageCollection>true</ServerGarbageCollection>
+        <TieredPGO>true</TieredPGO>
+
+        <RuntimeIdentifier>linux-musl-x64</RuntimeIdentifier>
+        
+    </PropertyGroup>
+
+    <ItemGroup>
+      <PackageReference Include="GenHTTP.Modules.Layouting" Version="9.8.0" />
+      <PackageReference Include="Unhinged.GenHttp.Experimental" Version="9.8.3" />
+    </ItemGroup>
+
+</Project>

+ 21 - 4
frameworks/CSharp/wiredio/benchmark_config.json

@@ -20,12 +20,12 @@
         "display_name": "Wired.IO",
         "display_name": "Wired.IO",
         "notes": "Only plaintext and JSON benchmarks implemented yet"
         "notes": "Only plaintext and JSON benchmarks implemented yet"
       },
       },
-      "plt": {
+      "mcr": {
         "plaintext_url": "/plaintext",
         "plaintext_url": "/plaintext",
         "json_url": "/json",
         "json_url": "/json",
         "port": 8080,
         "port": 8080,
         "approach": "Realistic",
         "approach": "Realistic",
-        "classification": "Platform",
+        "classification": "Micro",
         "database": "None",
         "database": "None",
         "framework": "Unhinged",
         "framework": "Unhinged",
         "language": "C#",
         "language": "C#",
@@ -34,8 +34,25 @@
         "webserver": "Unhinged",
         "webserver": "Unhinged",
         "os": "Linux",
         "os": "Linux",
         "database_os": "Linux",
         "database_os": "Linux",
-        "display_name": "Wired.IO [Unhinged]",
-        "notes": "Not a framework"
+        "display_name": "Unhinged",
+        "notes": "epoll"
+      },
+      "gen": {
+        "plaintext_url": "/plaintext",
+        "json_url": "/json",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Fullstack",
+        "database": "None",
+        "framework": "GenHttp",
+        "language": "C#",
+        "orm": "None",
+        "platform": ".NET",
+        "webserver": "Unhinged",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "genhttp [Unhinged]",
+        "notes": "Adapter"
       }
       }
     }
     }
   ]
   ]

+ 14 - 2
frameworks/CSharp/wiredio/config.toml

@@ -13,11 +13,23 @@ platform = ".NET"
 webserver = "Wired.IO"
 webserver = "Wired.IO"
 versus = "None"
 versus = "None"
 
 
-[plt]
+[mcr]
 urls.plaintext = "/plaintext"
 urls.plaintext = "/plaintext"
 urls.json = "/json"
 urls.json = "/json"
 approach = "Realistic"
 approach = "Realistic"
-classification = "Platform"
+classification = "Micro"
+os = "Linux"
+database_os = "Linux"
+orm = "None"
+platform = ".NET"
+webserver = "Unhinged"
+versus = "None"
+
+[gen]
+urls.plaintext = "/plaintext"
+urls.json = "/json"
+approach = "Realistic"
+classification = "Fullstack"
 os = "Linux"
 os = "Linux"
 database_os = "Linux"
 database_os = "Linux"
 orm = "None"
 orm = "None"

+ 1 - 1
frameworks/CSharp/wiredio/src/Platform/Platform.csproj

@@ -20,6 +20,6 @@
     </ItemGroup>
     </ItemGroup>
 
 
     <ItemGroup>
     <ItemGroup>
-      <PackageReference Include="Unhinged" Version="9.0.2" />
+      <PackageReference Include="Unhinged" Version="9.0.6" />
     </ItemGroup>
     </ItemGroup>
 </Project>
 </Project>

+ 8 - 3
frameworks/CSharp/wiredio/src/Platform/Program.cs

@@ -58,14 +58,19 @@ internal static class Program
         engine.Run();
         engine.Run();
     }
     }
 
 
-    private static void RequestHandler(Connection connection)
+    private const string Json = "/json";
+    private const string PlainText = "/plaintext";
+
+    private static ValueTask RequestHandler(Connection connection)
     {
     {
         // FNV-1a Hashed routes to avoid string allocations
         // FNV-1a Hashed routes to avoid string allocations
-        if(connection.HashedRoute == 291830056)          // /json
+        if(connection.H1HeaderData.Route == Json)          // /json
             CommitJsonResponse(connection);
             CommitJsonResponse(connection);
        
        
-        else if (connection.HashedRoute == 3454831873)   // /plaintext
+        else if (connection.H1HeaderData.Route == PlainText)   // /plaintext
             CommitPlainTextResponse(connection);
             CommitPlainTextResponse(connection);
+        
+        return  ValueTask.CompletedTask;
     }
     }
     
     
     [ThreadStatic] private static Utf8JsonWriter? t_utf8JsonWriter;
     [ThreadStatic] private static Utf8JsonWriter? t_utf8JsonWriter;

+ 24 - 0
frameworks/CSharp/wiredio/wiredio-gen.dockerfile

@@ -0,0 +1,24 @@
+FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build
+WORKDIR /source
+
+# copy csproj and restore as distinct layers
+COPY UnhGHttp/*.csproj .
+RUN dotnet restore -r linux-musl-x64
+
+# copy and publish app and libraries
+COPY UnhGHttp/ .
+RUN dotnet publish -c release -o /app -r linux-musl-x64 --no-restore --self-contained
+
+# 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 .
+
+ENTRYPOINT ["./UnhGHttp"]
+
+EXPOSE 8080

+ 0 - 0
frameworks/CSharp/wiredio/wiredio-plt.dockerfile → frameworks/CSharp/wiredio/wiredio-mcr.dockerfile