Browse Source

[CSharp] Add back AOT version of platform benchmarks (#8671)

* Add back AOT version of platform benchmarks

These were deleted in #8498 as "Kept for future PRs for simplicity" but the future is now.

* Skip fortunes benchmark

Looks like RazorSlices nuget got a lot worse between 0.3.0 and 0.7.0.
Michal Strehovský 1 năm trước cách đây
mục cha
commit
6e4fa67451

+ 17 - 0
frameworks/CSharp/aspnetcore/aspnetcore-aot.dockerfile

@@ -0,0 +1,17 @@
+FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
+RUN apt-get update
+RUN apt-get -yqq install clang zlib1g-dev
+WORKDIR /app
+COPY src/Platform .
+RUN dotnet publish -c Release -o out /p:DatabaseProvider=Npgsql /p:PublishAot=true /p:OptimizationPreference=Speed /p:GarbageCollectionAdaptationMode=0
+
+FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
+ENV URLS http://+:8080
+
+WORKDIR /app
+COPY --from=build /app/out ./
+COPY appsettings.postgresql.json ./appsettings.json
+
+EXPOSE 8080
+
+ENTRYPOINT ["./Platform"]

+ 22 - 0
frameworks/CSharp/aspnetcore/benchmark_config.json

@@ -25,6 +25,28 @@
         "display_name": "ASP.NET Core [Platform, Pg]",
         "notes": ""
       },
+      "aot": {
+        "plaintext_url": "/plaintext",
+        "json_url": "/json",
+        "db_url": "/db",
+        "query_url": "/queries/",
+        "update_url": "/updates/",
+        "cached_query_url": "/cached-worlds/",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Platform",
+        "database": "Postgres",
+        "framework": "ASP.NET Core",
+        "language": "C#",
+        "orm": "Raw",
+        "platform": ".NET",
+        "flavor": "NativeAOT",
+        "webserver": "Kestrel",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "ASP.NET Core [Platform, Pg, AOT]",
+        "notes": ""
+      },
       "minimal": {
         "plaintext_url": "/plaintext",
         "json_url": "/json",

+ 17 - 0
frameworks/CSharp/aspnetcore/config.toml

@@ -19,6 +19,23 @@ platform = ".NET"
 webserver = "Kestrel"
 versus = "None"
 
+[aot]
+urls.plaintext = "/plaintext"
+urls.json = "/json"
+urls.db = "/db"
+urls.query = "/queries/"
+urls.update = "/updates/"
+urls.cached_query = "/cached-worlds/"
+approach = "Realistic"
+classification = "Platform"
+database = "Postgres"
+database_os = "Linux"
+os = "Linux"
+orm = "Raw"
+platform = ".NET"
+webserver = "Kestrel"
+versus = "None"
+
 [minimal]
 urls.plaintext = "/plaintext"
 urls.json = "/json"

+ 2 - 0
frameworks/CSharp/aspnetcore/src/Platform/BenchmarkApplication.Fortunes.cs

@@ -1,6 +1,7 @@
 // Copyright (c) .NET Foundation. All rights reserved.
 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 
+#if !AOT
 using System.IO.Pipelines;
 using System.Runtime.CompilerServices;
 using System.Threading.Tasks;
@@ -64,3 +65,4 @@ public partial class BenchmarkApplication
         template.Dispose();
     }
 }
+#endif

+ 6 - 0
frameworks/CSharp/aspnetcore/src/Platform/BenchmarkApplication.cs

@@ -10,7 +10,9 @@ using System.Text.Json.Serialization;
 using System.Threading.Tasks;
 using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
 using Microsoft.Extensions.ObjectPool;
+#if !AOT
 using RazorSlices;
+#endif
 
 namespace PlatformBenchmarks
 {
@@ -54,10 +56,12 @@ namespace PlatformBenchmarks
             }
         }
 
+#if !AOT
 #if NPGSQL
         private readonly static SliceFactory<List<FortuneUtf8>> FortunesTemplateFactory = RazorSlice.ResolveSliceFactory<List<FortuneUtf8>>("/Templates/FortunesUtf8.cshtml");
 #else
         private readonly static SliceFactory<List<FortuneUtf16>> FortunesTemplateFactory = RazorSlice.ResolveSliceFactory<List<FortuneUtf16>>("/Templates/FortunesUtf16.cshtml");
+#endif
 #endif
 
         [ThreadStatic]
@@ -163,7 +167,9 @@ namespace PlatformBenchmarks
 
         private Task ProcessRequestAsync() => _requestType switch
         {
+#if !AOT
             RequestType.FortunesRaw => FortunesRaw(Writer),
+#endif
             RequestType.SingleQuery => SingleQuery(Writer),
             RequestType.Caching => Caching(Writer, _queries),
             RequestType.Updates => Updates(Writer, _queries),

+ 6 - 1
frameworks/CSharp/aspnetcore/src/Platform/Platform.csproj

@@ -6,6 +6,7 @@
     <IsTestAssetProject>true</IsTestAssetProject>
     <LangVersion>preview</LangVersion>
     <UserSecretsId>38063504-d08c-495a-89c9-daaad2f60f31</UserSecretsId>
+    <DefineConstants Condition="'$(PublishAot)' == 'true'">AOT;$(DefineConstants)</DefineConstants>
   </PropertyGroup>
 
   <PropertyGroup>
@@ -21,7 +22,11 @@
     <PackageReference Include="Npgsql" Version="8.0.1" />
     <PackageReference Include="MySqlConnector" Version="2.3.1" />
     <PackageReference Include="Dapper" Version="2.1.21" />
-    <PackageReference Include="RazorSlices" Version="0.7.0" />
+    <PackageReference Include="RazorSlices" Version="0.7.0" Condition="$(PublishAot) != 'true'" />
   </ItemGroup>
 
+  <PropertyGroup Condition="$(PublishAot) == 'true'">
+    <DefaultItemExcludes>$(MSBuildThisFileDirectory)Templates/**;$(DefaultItemExcludes)</DefaultItemExcludes>
+  </PropertyGroup>
+
 </Project>