Jelajahi Sumber

ASP.NET Core - Platform - SingleQuery (#3779)

* Aspnetcore - Plat - SingleQuery

* Reorder routing
Ben Adams 7 tahun lalu
induk
melakukan
a69887c97e

+ 51 - 6
frameworks/CSharp/aspnetcore/PlatformBenchmarks/BenchmarkApplication.cs

@@ -39,9 +39,10 @@ namespace PlatformBenchmarks
 
         public static class Paths
         {
-            public readonly static AsciiString Plaintext = "/plaintext";
+            public readonly static AsciiString SingleQuery = "/db";
             public readonly static AsciiString Json = "/json";
             public readonly static AsciiString Fortunes = "/fortunes";
+            public readonly static AsciiString Plaintext = "/plaintext";
         }
 
         private RequestType _requestType;
@@ -51,18 +52,23 @@ namespace PlatformBenchmarks
             var requestType = RequestType.NotRecognized;
             if (method == HttpMethod.Get)
             {
-                if (Paths.Plaintext.Length <= path.Length && path.StartsWith(Paths.Plaintext))
+                var pathLength = path.Length;
+                if (Paths.SingleQuery.Length <= pathLength && path.StartsWith(Paths.SingleQuery))
                 {
-                    requestType = RequestType.PlainText;
+                    requestType = RequestType.SingleQuery;
                 }
-                else if (Paths.Json.Length <= path.Length && path.StartsWith(Paths.Json))
+                else if (Paths.Json.Length <= pathLength && path.StartsWith(Paths.Json))
                 {
                     requestType = RequestType.Json;
                 }
-                else if (Paths.Fortunes.Length <= path.Length && path.StartsWith(Paths.Fortunes))
+                else if (Paths.Fortunes.Length <= pathLength && path.StartsWith(Paths.Fortunes))
                 {
                     requestType = RequestType.Fortunes;
                 }
+                else if (Paths.Plaintext.Length <= pathLength && path.StartsWith(Paths.Plaintext))
+                {
+                    requestType = RequestType.PlainText;
+                }
             }
 
             _requestType = requestType;
@@ -82,6 +88,10 @@ namespace PlatformBenchmarks
             {
                 return Fortunes(Writer);
             }
+            else if (_requestType == RequestType.SingleQuery)
+            {
+                return SingleQuery(Writer);
+            }
             else
             {
                 Default(Writer);
@@ -194,6 +204,40 @@ namespace PlatformBenchmarks
             writer.Commit();
         }
 
+        private async Task SingleQuery(PipeWriter pipeWriter)
+        {
+            OutputSingleQuery(pipeWriter, await Db.LoadSingleQueryRow());
+        }
+
+        private static void OutputSingleQuery(PipeWriter pipeWriter, World row)
+        {
+            var writer = GetWriter(pipeWriter);
+
+            // HTTP 1.1 OK
+            writer.Write(_http11OK);
+
+            // Server headers
+            writer.Write(_headerServer);
+
+            // Date header
+            writer.Write(DateHeader.HeaderBytes);
+
+            // Content-Type header
+            writer.Write(_headerContentTypeJson);
+
+            // Content-Length header
+            writer.Write(_headerContentLength);
+            var jsonPayload = JsonSerializer.SerializeUnsafe(row);
+            writer.WriteNumeric((uint)jsonPayload.Count);
+
+            // End of headers
+            writer.Write(_eoh);
+
+            // Body
+            writer.Write(jsonPayload);
+            writer.Commit();
+        }
+
         private static void Default(PipeWriter pipeWriter)
         {
             var writer = GetWriter(pipeWriter);
@@ -220,7 +264,8 @@ namespace PlatformBenchmarks
             NotRecognized,
             PlainText,
             Json,
-            Fortunes
+            Fortunes,
+            SingleQuery
         }
     }
 }

+ 1 - 0
frameworks/CSharp/aspnetcore/PlatformBenchmarks/Program.cs

@@ -23,6 +23,7 @@ namespace PlatformBenchmarks
             Console.WriteLine(BenchmarkApplication.Paths.Plaintext);
             Console.WriteLine(BenchmarkApplication.Paths.Json);
             Console.WriteLine(BenchmarkApplication.Paths.Fortunes);
+            Console.WriteLine(BenchmarkApplication.Paths.SingleQuery);
             DateHeader.SyncDateTimer();
 
             BuildWebHost(args).Run();

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

@@ -22,6 +22,7 @@
     },
     "ado-pg": {
       "fortune_url": "/fortunes",
+      "db_url": "/db",
       "port": 8080,
       "approach": "Realistic",
       "classification": "Platform",
@@ -40,6 +41,7 @@
     },
     "ado-my": {
       "fortune_url": "/fortunes",
+      "db_url": "/db",
       "port": 8080,
       "approach": "Realistic",
       "classification": "Platform",