Browse Source

Ben second cut (#6029)

* ben second cut

* Select random for better distribution

* fix
Ben Adams 4 years ago
parent
commit
1aac0e3314

+ 33 - 2
frameworks/CSharp/ben/PlatformBenchmarks/Data/Random.cs

@@ -3,6 +3,7 @@
 
 
 using System;
 using System;
 using System.Runtime.CompilerServices;
 using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
 using System.Threading;
 using System.Threading;
 
 
 namespace PlatformBenchmarks
 namespace PlatformBenchmarks
@@ -24,9 +25,39 @@ namespace PlatformBenchmarks
             return _random;
             return _random;
         }
         }
 
 
-        public int Next(int minValue, int maxValue)
+        public int Next(int fromInclusive, int toExclusive)
         {
         {
-            return Random.Next(minValue, maxValue);
+            // The total possible range is [0, 4,294,967,295).
+            // Subtract one to account for zero being an actual possibility.
+            uint range = (uint)toExclusive - (uint)fromInclusive - 1;
+
+            // If there is only one possible choice, nothing random will actually happen, so return
+            // the only possibility.
+            if (range == 0)
+            {
+                return fromInclusive;
+            }
+
+            // Create a mask for the bits that we care about for the range. The other bits will be
+            // masked away.
+            uint mask = range;
+            mask |= mask >> 1;
+            mask |= mask >> 2;
+            mask |= mask >> 4;
+            mask |= mask >> 8;
+            mask |= mask >> 16;
+
+            Span<uint> resultSpan = stackalloc uint[1];
+            uint result;
+
+            do
+            {
+                Random.NextBytes(MemoryMarshal.AsBytes(resultSpan));
+                result = mask & resultSpan[0];
+            }
+            while (result > range);
+
+            return (int)result + fromInclusive;
         }
         }
     }
     }
 }
 }

+ 5 - 0
frameworks/CSharp/ben/PlatformBenchmarks/Program.cs

@@ -2,6 +2,7 @@
 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 
 
 using System;
 using System;
+using System.Runtime.InteropServices;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 
 
 using Microsoft.AspNetCore.Builder;
 using Microsoft.AspNetCore.Builder;
@@ -62,6 +63,10 @@ namespace PlatformBenchmarks
                 .UseSockets(options =>
                 .UseSockets(options =>
                 {
                 {
                     options.WaitForDataBeforeAllocatingBuffer = false;
                     options.WaitForDataBeforeAllocatingBuffer = false;
+                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+                    {
+                        options.UnsafePreferInlineScheduling = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_NET_SOCKETS_INLINE_COMPLETIONS") == "1";
+                    }
                 })
                 })
                 .UseKestrel((context, options) =>
                 .UseKestrel((context, options) =>
                 {
                 {

+ 1 - 1
frameworks/CSharp/ben/PlatformBenchmarks/appsettings.postgresql.json

@@ -1,4 +1,4 @@
 {
 {
-  "ConnectionString": "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=2;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4;Multiplexing=true;Write Coalescing Delay Us=500;Write Coalescing Buffer Threshold Bytes=5500",
+  "ConnectionString": "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=32;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4;Multiplexing=true;Write Coalescing Delay Us=500;Write Coalescing Buffer Threshold Bytes=5500",
   "Database": "postgresql"
   "Database": "postgresql"
 }
 }

+ 1 - 1
frameworks/CSharp/ben/PlatformBenchmarks/appsettings.postgresql.updates.json

@@ -1,4 +1,4 @@
 {
 {
-  "ConnectionString": "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=2;NoResetOnClose=true;Enlist=false;Max Auto Prepare=3;Multiplexing=true;Write Coalescing Delay Us=500;Write Coalescing Buffer Threshold Bytes=5500",
+  "ConnectionString": "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=32;NoResetOnClose=true;Enlist=false;Max Auto Prepare=3;Multiplexing=true;Write Coalescing Delay Us=500;Write Coalescing Buffer Threshold Bytes=5500",
   "Database": "postgresql"
   "Database": "postgresql"
 }
 }

+ 0 - 12
frameworks/CSharp/ben/ben-pg-up.dockerfile

@@ -1,12 +0,0 @@
-FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
-WORKDIR /app
-COPY PlatformBenchmarks .
-RUN dotnet publish -c Release -o out /p:IsDatabase=true
-
-FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime
-ENV ASPNETCORE_URLS http://+:8080
-WORKDIR /app
-COPY --from=build /app/out ./
-COPY PlatformBenchmarks/appsettings.postgresql.updates.json ./appsettings.json
-
-ENTRYPOINT ["dotnet", "PlatformBenchmarks.dll"]

+ 8 - 0
frameworks/CSharp/ben/ben-pg.dockerfile

@@ -5,8 +5,16 @@ RUN dotnet publish -c Release -o out /p:IsDatabase=true
 
 
 FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime
 FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime
 ENV ASPNETCORE_URLS http://+:8080
 ENV ASPNETCORE_URLS http://+:8080
+ENV DOTNET_SYSTEM_NET_SOCKETS_INLINE_COMPLETIONS 1
 WORKDIR /app
 WORKDIR /app
 COPY --from=build /app/out ./
 COPY --from=build /app/out ./
 COPY PlatformBenchmarks/appsettings.postgresql.json ./appsettings.json
 COPY PlatformBenchmarks/appsettings.postgresql.json ./appsettings.json
 
 
+# Switch off AoT code in libs to allow for greater instrumentation
+ENV COMPlus_ReadyToRun 0
+# Move methods with loops to Tier0 rather than Tier1 by default for greater instrumentation
+ENV COMPlus_TC_QuickJitForLoops 1
+# Switch on Profile Guided Optimization instrumentation at Tier0 
+ENV COMPlus_TieredPGO 1
+
 ENTRYPOINT ["dotnet", "PlatformBenchmarks.dll"]
 ENTRYPOINT ["dotnet", "PlatformBenchmarks.dll"]

+ 1 - 0
frameworks/CSharp/ben/ben.dockerfile

@@ -5,6 +5,7 @@ RUN dotnet publish -c Release -o out
 
 
 FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime
 FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime
 ENV ASPNETCORE_URLS http://+:8080
 ENV ASPNETCORE_URLS http://+:8080
+ENV DOTNET_SYSTEM_NET_SOCKETS_INLINE_COMPLETIONS 1
 WORKDIR /app
 WORKDIR /app
 COPY --from=build /app/out ./
 COPY --from=build /app/out ./
 
 

+ 1 - 18
frameworks/CSharp/ben/benchmark_config.json

@@ -23,6 +23,7 @@
     "pg": {
     "pg": {
       "db_url": "/db",
       "db_url": "/db",
       "query_url": "/queries/",
       "query_url": "/queries/",
+      "update_url": "/updates/",
       "cached_query_url": "/cached-worlds/",
       "cached_query_url": "/cached-worlds/",
       "port": 8080,
       "port": 8080,
       "approach": "Stripped",
       "approach": "Stripped",
@@ -39,24 +40,6 @@
       "display_name": "ASP.NET Core, ADO.NET",
       "display_name": "ASP.NET Core, ADO.NET",
       "notes": "",
       "notes": "",
       "versus": "aspcore-ado-pg"
       "versus": "aspcore-ado-pg"
-    },
-    "pg-up": {
-      "update_url": "/updates/",
-      "port": 8080,
-      "approach": "Stripped",
-      "classification": "Platform",
-      "database": "Postgres",
-      "framework": "ASP.NET Core",
-      "language": "C#",
-      "orm": "Raw",
-      "platform": ".NET",
-      "flavor": "CoreCLR",
-      "webserver": "Kestrel",
-      "os": "Linux",
-      "database_os": "Linux",
-      "display_name": "ASP.NET Core, ADO.NET",
-      "notes": "",
-      "versus": "aspcore-ado-pg-up"
     }
     }
   }]
   }]
 }
 }