From 1f743123737590460095bed982ed94395f1d631d Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Mon, 14 Dec 2015 12:42:32 -0800 Subject: [PATCH 01/14] Add missing dependency to project.json. --- src/Benchmarks/project.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Benchmarks/project.json b/src/Benchmarks/project.json index 7f2664858..891cf25ea 100644 --- a/src/Benchmarks/project.json +++ b/src/Benchmarks/project.json @@ -14,6 +14,7 @@ "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", "Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.AspNet.StaticFiles": "1.0.0-*", + "Microsoft.Extensions.Configuration.Binder": "1.0.0-*", "Microsoft.Extensions.WebEncoders": "1.0.0-*", "Newtonsoft.Json": "7.0.1" }, From 4acaef9e80cff7950118a309550eb107a270a1b6 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 22 Dec 2015 12:18:54 -0400 Subject: [PATCH 02/14] Fixed the benchmarks - Use the new hosting API - Found a CoreCLR bug with intercept = true on *nix --- src/Benchmarks/Program.cs | 101 +++++++++++------------------------- src/Benchmarks/hosting.json | 3 +- src/Benchmarks/project.json | 6 ++- 3 files changed, 37 insertions(+), 73 deletions(-) diff --git a/src/Benchmarks/Program.cs b/src/Benchmarks/Program.cs index e2fd9d803..f5f3fa638 100644 --- a/src/Benchmarks/Program.cs +++ b/src/Benchmarks/Program.cs @@ -4,9 +4,6 @@ using System; using System.Threading; using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Features; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace Benchmarks @@ -15,81 +12,43 @@ public class Program { public static void Main(string[] args) { - var hostingConfig = new ConfigurationBuilder() - .AddJsonFile("hosting.json", optional: true) - .AddEnvironmentVariables() - .AddEnvironmentVariables(prefix: "ASPNET_") - .AddCommandLine(args) - .Build(); - - var hostBuilder = new WebHostBuilder(hostingConfig, captureStartupErrors: true); - hostBuilder.UseStartup(typeof(Startup)); - - var host = hostBuilder.Build(); - - using (var app = host.Start()) + var app = new WebApplicationBuilder() + .UseConfiguration(WebApplicationConfiguration.GetDefault(args)) + .UseStartup() + .Build(); + + // Run the interaction on a separate thread as we don't have Console.KeyAvailable on .NET Core so can't + // do a pre-emptive check before we call Console.ReadKey (which blocks, hard) + var interactiveThread = new Thread(() => { - // Echo out the addresses we're listening on - var hostingEnv = app.Services.GetRequiredService(); - Console.WriteLine("Hosting environment: " + hostingEnv.EnvironmentName); + Console.WriteLine(); + Console.WriteLine("Press 'C' to force GC or any other key to display GC stats"); - var serverAddresses = app.ServerFeatures.Get(); - if (serverAddresses != null) + while (true) { - foreach (var address in serverAddresses.Addresses) + var key = Console.ReadKey(intercept: true); + + if (key.Key == ConsoleKey.C) { - Console.WriteLine("Now listening on: " + address); + Console.WriteLine(); + Console.Write("Forcing GC..."); + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); + Console.WriteLine(" done!"); } - } - - Console.WriteLine("Application started. Press Ctrl+C to shut down."); - - var appLifetime = app.Services.GetRequiredService(); - - // Run the interaction on a separate thread as we don't have Console.KeyAvailable on .NET Core so can't - // do a pre-emptive check before we call Console.ReadKey (which blocks, hard) - var interactiveThread = new Thread(() => - { - Console.WriteLine(); - Console.WriteLine("Press 'C' to force GC or any other key to display GC stats"); - - while (true) + else { - var key = Console.ReadKey(intercept: true); - - if (key.Key == ConsoleKey.C) - { - Console.WriteLine(); - Console.Write("Forcing GC..."); - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); - Console.WriteLine(" done!"); - } - else - { - Console.WriteLine(); - Console.WriteLine($"Allocated: {GetAllocatedMemory()}"); - Console.WriteLine($"Gen 0: {GC.CollectionCount(0)}, Gen 1: {GC.CollectionCount(1)}, Gen 2: {GC.CollectionCount(2)}"); - } + Console.WriteLine(); + Console.WriteLine($"Allocated: {GetAllocatedMemory()}"); + Console.WriteLine($"Gen 0: {GC.CollectionCount(0)}, Gen 1: {GC.CollectionCount(1)}, Gen 2: {GC.CollectionCount(2)}"); } - }); - - // Handle Ctrl+C in order to gracefully shutdown the web server - Console.CancelKeyPress += (sender, eventArgs) => - { - Console.WriteLine(); - Console.WriteLine("Shutting down application..."); - - appLifetime.StopApplication(); - - eventArgs.Cancel = true; - }; - - interactiveThread.Start(); - - appLifetime.ApplicationStopping.WaitHandle.WaitOne(); - } + } + }); + interactiveThread.IsBackground = true; + interactiveThread.Start(); + + app.Run(); } private static string GetAllocatedMemory(bool forceFullCollection = false) diff --git a/src/Benchmarks/hosting.json b/src/Benchmarks/hosting.json index 765930471..daa8238d5 100644 --- a/src/Benchmarks/hosting.json +++ b/src/Benchmarks/hosting.json @@ -1,4 +1,5 @@ { "server": "Microsoft.AspNet.Server.Kestrel", - "server.urls": "http://*:5001" + "server.urls": "http://*:5001", + "captureStartupErrors": true } diff --git a/src/Benchmarks/project.json b/src/Benchmarks/project.json index 891cf25ea..4d3167e70 100644 --- a/src/Benchmarks/project.json +++ b/src/Benchmarks/project.json @@ -26,7 +26,11 @@ "frameworks": { "dnx451": { }, - "dnxcore50": { } + "dnxcore50": { + "dependencies": { + "System.Runtime.Serialization.Primitives": "4.1.0-*" + } + } }, "publishExclude": [ From 12a26890320c8279b8bad52ca0d8017cf2ab5998 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 25 Dec 2015 06:14:12 +0000 Subject: [PATCH 03/14] OrdinalIgnoreCase is unnecessary https://www.techempower.com/benchmarks/#section=code&hw=peak&test=json > General requirements 3. Specific characters and character case matter. --- src/Benchmarks/FortunesDapperMiddleware.cs | 4 +--- src/Benchmarks/FortunesEfMiddleware.cs | 4 +--- src/Benchmarks/FortunesRawMiddleware.cs | 4 +--- src/Benchmarks/JsonMiddleware.cs | 4 +--- src/Benchmarks/MultipleQueriesDapperMiddleware.cs | 3 +-- src/Benchmarks/MultipleQueriesEfMiddleware.cs | 4 +--- src/Benchmarks/MultipleQueriesRawMiddleware.cs | 4 +--- src/Benchmarks/PlaintextMiddleware.cs | 4 +--- src/Benchmarks/SingleQueryDapperMiddleware.cs | 4 +--- src/Benchmarks/SingleQueryEfMiddleware.cs | 4 +--- src/Benchmarks/SingleQueryRawMiddleware.cs | 4 +--- 11 files changed, 11 insertions(+), 32 deletions(-) diff --git a/src/Benchmarks/FortunesDapperMiddleware.cs b/src/Benchmarks/FortunesDapperMiddleware.cs index 94d08aa31..b56c4ad29 100644 --- a/src/Benchmarks/FortunesDapperMiddleware.cs +++ b/src/Benchmarks/FortunesDapperMiddleware.cs @@ -30,9 +30,7 @@ public FortunesDapperMiddleware(RequestDelegate next, string connectionString, D public async Task Invoke(HttpContext httpContext, HtmlEncoder htmlEncoder) { - // We check Ordinal explicitly first because it's faster than OrdinalIgnoreCase - if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal) || - httpContext.Request.Path.StartsWithSegments(_path, StringComparison.OrdinalIgnoreCase)) + if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal)) { var rows = await LoadRows(_connectionString, _dbProviderFactory); diff --git a/src/Benchmarks/FortunesEfMiddleware.cs b/src/Benchmarks/FortunesEfMiddleware.cs index 51c668d99..9cd16b415 100644 --- a/src/Benchmarks/FortunesEfMiddleware.cs +++ b/src/Benchmarks/FortunesEfMiddleware.cs @@ -25,9 +25,7 @@ public FortunesEfMiddleware(RequestDelegate next) public async Task Invoke(HttpContext httpContext, HtmlEncoder htmlEncoder) { - // We check Ordinal explicitly first because it's faster than OrdinalIgnoreCase - if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal) || - httpContext.Request.Path.StartsWithSegments(_path, StringComparison.OrdinalIgnoreCase)) + if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal)) { var db = (ApplicationDbContext)httpContext.RequestServices.GetService(typeof(ApplicationDbContext)); db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; diff --git a/src/Benchmarks/FortunesRawMiddleware.cs b/src/Benchmarks/FortunesRawMiddleware.cs index f30b3636c..40a738ea0 100644 --- a/src/Benchmarks/FortunesRawMiddleware.cs +++ b/src/Benchmarks/FortunesRawMiddleware.cs @@ -30,9 +30,7 @@ public FortunesRawMiddleware(RequestDelegate next, string connectionString, DbPr public async Task Invoke(HttpContext httpContext, HtmlEncoder htmlEncoder) { - // We check Ordinal explicitly first because it's faster than OrdinalIgnoreCase - if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal) || - httpContext.Request.Path.StartsWithSegments(_path, StringComparison.OrdinalIgnoreCase)) + if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal)) { var rows = await LoadRows(_connectionString, _dbProviderFactory); diff --git a/src/Benchmarks/JsonMiddleware.cs b/src/Benchmarks/JsonMiddleware.cs index dfa24a9de..8c54c7da1 100644 --- a/src/Benchmarks/JsonMiddleware.cs +++ b/src/Benchmarks/JsonMiddleware.cs @@ -26,9 +26,7 @@ public JsonMiddleware(RequestDelegate next) public Task Invoke(HttpContext httpContext) { - // We check Ordinal explicitly first because it's faster than OrdinalIgnoreCase - if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal) || - httpContext.Request.Path.StartsWithSegments(_path, StringComparison.OrdinalIgnoreCase)) + if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal)) { httpContext.Response.StatusCode = 200; httpContext.Response.ContentType = "application/json"; diff --git a/src/Benchmarks/MultipleQueriesDapperMiddleware.cs b/src/Benchmarks/MultipleQueriesDapperMiddleware.cs index 7f558faa9..8d267adf1 100644 --- a/src/Benchmarks/MultipleQueriesDapperMiddleware.cs +++ b/src/Benchmarks/MultipleQueriesDapperMiddleware.cs @@ -37,8 +37,7 @@ public MultipleQueriesDapperMiddleware(RequestDelegate next, string connectionSt public async Task Invoke(HttpContext httpContext) { // We check Ordinal explicitly first because it's faster than OrdinalIgnoreCase - if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal) || - httpContext.Request.Path.StartsWithSegments(_path, StringComparison.OrdinalIgnoreCase)) + if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal)) { var count = GetQueryCount(httpContext); var rows = await LoadRows(count, _connectionString, _dbProviderFactory); diff --git a/src/Benchmarks/MultipleQueriesEfMiddleware.cs b/src/Benchmarks/MultipleQueriesEfMiddleware.cs index b306a156e..e28e5a39c 100644 --- a/src/Benchmarks/MultipleQueriesEfMiddleware.cs +++ b/src/Benchmarks/MultipleQueriesEfMiddleware.cs @@ -29,9 +29,7 @@ public MultipleQueriesEfMiddleware(RequestDelegate next) public async Task Invoke(HttpContext httpContext) { - // We check Ordinal explicitly first because it's faster than OrdinalIgnoreCase - if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal) || - httpContext.Request.Path.StartsWithSegments(_path, StringComparison.OrdinalIgnoreCase)) + if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal)) { var db = (ApplicationDbContext)httpContext.RequestServices.GetService(typeof(ApplicationDbContext)); db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; diff --git a/src/Benchmarks/MultipleQueriesRawMiddleware.cs b/src/Benchmarks/MultipleQueriesRawMiddleware.cs index 5bc4936ba..c443da634 100644 --- a/src/Benchmarks/MultipleQueriesRawMiddleware.cs +++ b/src/Benchmarks/MultipleQueriesRawMiddleware.cs @@ -35,9 +35,7 @@ public MultipleQueriesRawMiddleware(RequestDelegate next, string connectionStrin public async Task Invoke(HttpContext httpContext) { - // We check Ordinal explicitly first because it's faster than OrdinalIgnoreCase - if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal) || - httpContext.Request.Path.StartsWithSegments(_path, StringComparison.OrdinalIgnoreCase)) + if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal)) { var count = GetQueryCount(httpContext); var rows = await LoadRows(count, _connectionString, _dbProviderFactory); diff --git a/src/Benchmarks/PlaintextMiddleware.cs b/src/Benchmarks/PlaintextMiddleware.cs index 1302525a6..f84b2c400 100644 --- a/src/Benchmarks/PlaintextMiddleware.cs +++ b/src/Benchmarks/PlaintextMiddleware.cs @@ -23,9 +23,7 @@ public PlaintextMiddleware(RequestDelegate next) public Task Invoke(HttpContext httpContext) { - // We check Ordinal explicitly first because it's faster than OrdinalIgnoreCase - if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal) || - httpContext.Request.Path.StartsWithSegments(_path, StringComparison.OrdinalIgnoreCase)) + if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal)) { httpContext.Response.StatusCode = 200; httpContext.Response.ContentType = "text/plain"; diff --git a/src/Benchmarks/SingleQueryDapperMiddleware.cs b/src/Benchmarks/SingleQueryDapperMiddleware.cs index dff57ef44..6719fd6f9 100644 --- a/src/Benchmarks/SingleQueryDapperMiddleware.cs +++ b/src/Benchmarks/SingleQueryDapperMiddleware.cs @@ -36,9 +36,7 @@ public SingleQueryDapperMiddleware(RequestDelegate next, string connectionString public async Task Invoke(HttpContext httpContext) { - // We check Ordinal explicitly first because it's faster than OrdinalIgnoreCase - if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal) || - httpContext.Request.Path.StartsWithSegments(_path, StringComparison.OrdinalIgnoreCase)) + if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal)) { var row = await LoadRow(_connectionString, _dbProviderFactory); diff --git a/src/Benchmarks/SingleQueryEfMiddleware.cs b/src/Benchmarks/SingleQueryEfMiddleware.cs index 394e6963c..9d55edba5 100644 --- a/src/Benchmarks/SingleQueryEfMiddleware.cs +++ b/src/Benchmarks/SingleQueryEfMiddleware.cs @@ -29,9 +29,7 @@ public SingleQueryEfMiddleware(RequestDelegate next) public async Task Invoke(HttpContext httpContext) { - // We check Ordinal explicitly first because it's faster than OrdinalIgnoreCase - if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal) || - httpContext.Request.Path.StartsWithSegments(_path, StringComparison.OrdinalIgnoreCase)) + if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal)) { var db = (ApplicationDbContext)httpContext.RequestServices.GetService(typeof(ApplicationDbContext)); diff --git a/src/Benchmarks/SingleQueryRawMiddleware.cs b/src/Benchmarks/SingleQueryRawMiddleware.cs index cd5b51fb7..64cfb203a 100644 --- a/src/Benchmarks/SingleQueryRawMiddleware.cs +++ b/src/Benchmarks/SingleQueryRawMiddleware.cs @@ -35,9 +35,7 @@ public SingleQueryRawMiddleware(RequestDelegate next, string connectionString, D public async Task Invoke(HttpContext httpContext) { - // We check Ordinal explicitly first because it's faster than OrdinalIgnoreCase - if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal) || - httpContext.Request.Path.StartsWithSegments(_path, StringComparison.OrdinalIgnoreCase)) + if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal)) { var row = await LoadRow(_connectionString, _dbProviderFactory); From 842276eca1fc6b1bede1e18eb01c8e723dc0585d Mon Sep 17 00:00:00 2001 From: Simon Murdock Date: Mon, 28 Dec 2015 23:19:25 +0000 Subject: [PATCH 04/14] Typo in intro text --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 63d150550..a9b3ce9bd 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Benchmarks for ASP.NET 5 including (but not limited to) scenarios from the [Tech The benchmark repo is set up to work against the latest sources (i.e. not packages from nuget.org) for ASP.NET 5 so make sure you read through the following details to help you get started. -The ASP.NET 5 benchmarks server application itself is in the `./src/Benchmarks` folder. The `./expiremental` folder contains various experimental projects that aren't themselves part of the benchmarks. +The ASP.NET 5 benchmarks server application itself is in the `./src/Benchmarks` folder. The `./experimental` folder contains various experimental projects that aren't themselves part of the benchmarks. ## The scenarios Following are the details of each of the scenarios the server application contains implementations for and thus can be benchmarked: From 4e51e962578d91e2b78b6ba0707ceebaea92a8c7 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 6 Jan 2016 15:30:19 -0800 Subject: [PATCH 05/14] Adding build.cmd --- .gitignore | 1 + build.cmd | 40 +++++++++++++++++++++++++++++++++++++ makefile.shade | 14 +++++++++++++ src/Benchmarks/project.json | 4 +--- 4 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 build.cmd create mode 100644 makefile.shade diff --git a/.gitignore b/.gitignore index 942ef38c5..582a9e7d5 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ nuget.exe debugSettings.json project.lock.json version.h +.build/ # Profiler result files, just in case they are left lying around :) /.vs/ diff --git a/build.cmd b/build.cmd new file mode 100644 index 000000000..61b58f61a --- /dev/null +++ b/build.cmd @@ -0,0 +1,40 @@ +@ECHO off +SETLOCAL + +SET REPO_FOLDER=%~dp0 +CD %REPO_FOLDER% + +SET BUILD_FOLDER=.build +SET KOREBUILD_FOLDER=%BUILD_FOLDER%\KoreBuild-dotnet +SET KOREBUILD_VERSION= + +SET NUGET_PATH=%BUILD_FOLDER%\NuGet.exe +SET NUGET_VERSION=latest +SET CACHED_NUGET=%LocalAppData%\NuGet\nuget.%NUGET_VERSION%.exe + +IF NOT EXIST %BUILD_FOLDER% ( + md %BUILD_FOLDER% +) + +IF NOT EXIST %NUGET_PATH% ( + IF NOT EXIST %CACHED_NUGET% ( + echo Downloading latest version of NuGet.exe... + IF NOT EXIST %LocalAppData%\NuGet ( + md %LocalAppData%\NuGet + ) + @powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/%NUGET_VERSION%/nuget.exe' -OutFile '%CACHED_NUGET%'" + ) + + copy %CACHED_NUGET% %NUGET_PATH% > nul +) + +IF NOT EXIST %KOREBUILD_FOLDER% ( + SET KOREBUILD_DOWNLOAD_ARGS= + IF NOT "%KOREBUILD_VERSION%"=="" ( + SET KOREBUILD_DOWNLOAD_ARGS=-version %KOREBUILD_VERSION% + ) + + %BUILD_FOLDER%\nuget.exe install KoreBuild-dotnet -ExcludeVersion -o %BUILD_FOLDER% -nocache -pre %KOREBUILD_DOWNLOAD_ARGS% +) + +"%KOREBUILD_FOLDER%\build\KoreBuild.cmd" %* diff --git a/makefile.shade b/makefile.shade new file mode 100644 index 000000000..889307dda --- /dev/null +++ b/makefile.shade @@ -0,0 +1,14 @@ +var AUTHORS='Microsoft Open Technologies, Inc.' + +use-standard-lifecycle +k-standard-goals + +#build-compile target='compile' + @{ + var projectFiles = Files + .Include("src/**/project.json") + .Include("experimental/**/project.json") + .ToList(); + + projectFiles.ForEach(projectFile => DotnetBuild(projectFile, E("Configuration"))); + } diff --git a/src/Benchmarks/project.json b/src/Benchmarks/project.json index 4d3167e70..cc5a95ad9 100644 --- a/src/Benchmarks/project.json +++ b/src/Benchmarks/project.json @@ -14,9 +14,7 @@ "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", "Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.AspNet.StaticFiles": "1.0.0-*", - "Microsoft.Extensions.Configuration.Binder": "1.0.0-*", - "Microsoft.Extensions.WebEncoders": "1.0.0-*", - "Newtonsoft.Json": "7.0.1" + "Microsoft.Extensions.Configuration.Binder": "1.0.0-*" }, "commands": { From 56268afb95e9d5fd7f6441592fe7fb38e88f637d Mon Sep 17 00:00:00 2001 From: John Luo Date: Sun, 17 Jan 2016 18:15:10 -0800 Subject: [PATCH 06/14] Reacting to hosting rename --- src/Benchmarks/Program.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Benchmarks/Program.cs b/src/Benchmarks/Program.cs index f5f3fa638..625a02df8 100644 --- a/src/Benchmarks/Program.cs +++ b/src/Benchmarks/Program.cs @@ -12,8 +12,8 @@ public class Program { public static void Main(string[] args) { - var app = new WebApplicationBuilder() - .UseConfiguration(WebApplicationConfiguration.GetDefault(args)) + var host = new WebHostBuilder() + .UseDefaultConfiguration(args) .UseStartup() .Build(); @@ -48,7 +48,7 @@ public static void Main(string[] args) interactiveThread.IsBackground = true; interactiveThread.Start(); - app.Run(); + host.Run(); } private static string GetAllocatedMemory(bool forceFullCollection = false) From 10a6c632345e376b4571f23c79a68d1285f576e0 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Mon, 25 Jan 2016 10:22:17 -0800 Subject: [PATCH 07/14] Rename AspNet 5 file contents. See https://github.com/aspnet/Announcements/issues/144 for more information. --- src/Benchmarks/Controllers/HomeController.cs | 6 +++--- src/Benchmarks/Data/ApplicationDbContext.cs | 4 ++-- src/Benchmarks/DebugInfoPageMiddleware.cs | 10 +++++----- src/Benchmarks/ErrorHandlerMiddleware.cs | 6 +++--- src/Benchmarks/FortunesDapperMiddleware.cs | 6 +++--- src/Benchmarks/FortunesEfMiddleware.cs | 8 ++++---- src/Benchmarks/FortunesRawMiddleware.cs | 6 +++--- src/Benchmarks/JsonMiddleware.cs | 6 +++--- .../Migrations/20151113004227_Initial.Designer.cs | 8 ++++---- .../Migrations/20151113004227_Initial.cs | 4 ++-- .../Migrations/20151124205054_Fortune.Designer.cs | 8 ++++---- .../Migrations/20151124205054_Fortune.cs | 4 ++-- .../ApplicationDbContextModelSnapshot.cs | 8 ++++---- src/Benchmarks/MultipleQueriesDapperMiddleware.cs | 6 +++--- src/Benchmarks/MultipleQueriesEfMiddleware.cs | 8 ++++---- src/Benchmarks/MultipleQueriesRawMiddleware.cs | 6 +++--- src/Benchmarks/PlaintextMiddleware.cs | 6 +++--- src/Benchmarks/Program.cs | 4 ++-- src/Benchmarks/SingleQueryDapperMiddleware.cs | 6 +++--- src/Benchmarks/SingleQueryEfMiddleware.cs | 8 ++++---- src/Benchmarks/SingleQueryRawMiddleware.cs | 6 +++--- src/Benchmarks/Startup.cs | 10 +++++----- src/Benchmarks/hosting.json | 4 ++-- src/Benchmarks/project.json | 14 +++++++------- 24 files changed, 81 insertions(+), 81 deletions(-) diff --git a/src/Benchmarks/Controllers/HomeController.cs b/src/Benchmarks/Controllers/HomeController.cs index 7eaccb4a8..83d368226 100644 --- a/src/Benchmarks/Controllers/HomeController.cs +++ b/src/Benchmarks/Controllers/HomeController.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. using System.Text; using System.Threading.Tasks; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Mvc; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; namespace Benchmarks.Controllers { diff --git a/src/Benchmarks/Data/ApplicationDbContext.cs b/src/Benchmarks/Data/ApplicationDbContext.cs index 52e0e931f..b09cb2f4a 100644 --- a/src/Benchmarks/Data/ApplicationDbContext.cs +++ b/src/Benchmarks/Data/ApplicationDbContext.cs @@ -1,7 +1,7 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. -using Microsoft.Data.Entity; +using Microsoft.EntityFrameworkCore; namespace Benchmarks.Data { diff --git a/src/Benchmarks/DebugInfoPageMiddleware.cs b/src/Benchmarks/DebugInfoPageMiddleware.cs index 58b6444f2..efebd3fb5 100644 --- a/src/Benchmarks/DebugInfoPageMiddleware.cs +++ b/src/Benchmarks/DebugInfoPageMiddleware.cs @@ -1,12 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. using System; using System.Threading.Tasks; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Features; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.PlatformAbstractions; namespace Benchmarks diff --git a/src/Benchmarks/ErrorHandlerMiddleware.cs b/src/Benchmarks/ErrorHandlerMiddleware.cs index 117def1ad..004355fb5 100644 --- a/src/Benchmarks/ErrorHandlerMiddleware.cs +++ b/src/Benchmarks/ErrorHandlerMiddleware.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. using System; using System.Threading.Tasks; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; namespace Benchmarks { diff --git a/src/Benchmarks/FortunesDapperMiddleware.cs b/src/Benchmarks/FortunesDapperMiddleware.cs index 94d08aa31..8d99cd4f9 100644 --- a/src/Benchmarks/FortunesDapperMiddleware.cs +++ b/src/Benchmarks/FortunesDapperMiddleware.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. using System; @@ -8,8 +8,8 @@ using System.Threading.Tasks; using Benchmarks.Data; using Dapper; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; namespace Benchmarks { diff --git a/src/Benchmarks/FortunesEfMiddleware.cs b/src/Benchmarks/FortunesEfMiddleware.cs index 51c668d99..1e706c231 100644 --- a/src/Benchmarks/FortunesEfMiddleware.cs +++ b/src/Benchmarks/FortunesEfMiddleware.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. using System; @@ -6,9 +6,9 @@ using System.Text.Encodings.Web; using System.Threading.Tasks; using Benchmarks.Data; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; -using Microsoft.Data.Entity; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; +using Microsoft.EntityFrameworkCore; namespace Benchmarks { diff --git a/src/Benchmarks/FortunesRawMiddleware.cs b/src/Benchmarks/FortunesRawMiddleware.cs index f30b3636c..f8a8a81a4 100644 --- a/src/Benchmarks/FortunesRawMiddleware.cs +++ b/src/Benchmarks/FortunesRawMiddleware.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. using System; @@ -8,8 +8,8 @@ using System.Text.Encodings.Web; using System.Threading.Tasks; using Benchmarks.Data; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; namespace Benchmarks { diff --git a/src/Benchmarks/JsonMiddleware.cs b/src/Benchmarks/JsonMiddleware.cs index dfa24a9de..5d7458dbb 100644 --- a/src/Benchmarks/JsonMiddleware.cs +++ b/src/Benchmarks/JsonMiddleware.cs @@ -1,12 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. using System; using System.IO; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; using Newtonsoft.Json; namespace Benchmarks diff --git a/src/Benchmarks/Migrations/20151113004227_Initial.Designer.cs b/src/Benchmarks/Migrations/20151113004227_Initial.Designer.cs index bfce825c0..4ea189b25 100644 --- a/src/Benchmarks/Migrations/20151113004227_Initial.Designer.cs +++ b/src/Benchmarks/Migrations/20151113004227_Initial.Designer.cs @@ -1,8 +1,8 @@ using System; -using Microsoft.Data.Entity; -using Microsoft.Data.Entity.Infrastructure; -using Microsoft.Data.Entity.Metadata; -using Microsoft.Data.Entity.Migrations; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; using Benchmarks.Data; namespace Benchmarks.Migrations diff --git a/src/Benchmarks/Migrations/20151113004227_Initial.cs b/src/Benchmarks/Migrations/20151113004227_Initial.cs index f880edd6d..63de764aa 100644 --- a/src/Benchmarks/Migrations/20151113004227_Initial.cs +++ b/src/Benchmarks/Migrations/20151113004227_Initial.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -using Microsoft.Data.Entity.Migrations; -using Microsoft.Data.Entity.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Metadata; using System.Text; namespace Benchmarks.Migrations diff --git a/src/Benchmarks/Migrations/20151124205054_Fortune.Designer.cs b/src/Benchmarks/Migrations/20151124205054_Fortune.Designer.cs index 0204aa214..0267669cb 100644 --- a/src/Benchmarks/Migrations/20151124205054_Fortune.Designer.cs +++ b/src/Benchmarks/Migrations/20151124205054_Fortune.Designer.cs @@ -1,8 +1,8 @@ using System; -using Microsoft.Data.Entity; -using Microsoft.Data.Entity.Infrastructure; -using Microsoft.Data.Entity.Metadata; -using Microsoft.Data.Entity.Migrations; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; using Benchmarks.Data; namespace Benchmarks.Migrations diff --git a/src/Benchmarks/Migrations/20151124205054_Fortune.cs b/src/Benchmarks/Migrations/20151124205054_Fortune.cs index e22e90923..9488d18d0 100644 --- a/src/Benchmarks/Migrations/20151124205054_Fortune.cs +++ b/src/Benchmarks/Migrations/20151124205054_Fortune.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -using Microsoft.Data.Entity.Migrations; -using Microsoft.Data.Entity.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Metadata; namespace Benchmarks.Migrations { diff --git a/src/Benchmarks/Migrations/ApplicationDbContextModelSnapshot.cs b/src/Benchmarks/Migrations/ApplicationDbContextModelSnapshot.cs index cf67310f6..320af52ff 100644 --- a/src/Benchmarks/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/src/Benchmarks/Migrations/ApplicationDbContextModelSnapshot.cs @@ -1,8 +1,8 @@ using System; -using Microsoft.Data.Entity; -using Microsoft.Data.Entity.Infrastructure; -using Microsoft.Data.Entity.Metadata; -using Microsoft.Data.Entity.Migrations; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; using Benchmarks.Data; namespace Benchmarks.Migrations diff --git a/src/Benchmarks/MultipleQueriesDapperMiddleware.cs b/src/Benchmarks/MultipleQueriesDapperMiddleware.cs index 7f558faa9..a34dae571 100644 --- a/src/Benchmarks/MultipleQueriesDapperMiddleware.cs +++ b/src/Benchmarks/MultipleQueriesDapperMiddleware.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. using System; @@ -7,8 +7,8 @@ using System.Threading.Tasks; using Benchmarks.Data; using Dapper; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; diff --git a/src/Benchmarks/MultipleQueriesEfMiddleware.cs b/src/Benchmarks/MultipleQueriesEfMiddleware.cs index b306a156e..fa186bedf 100644 --- a/src/Benchmarks/MultipleQueriesEfMiddleware.cs +++ b/src/Benchmarks/MultipleQueriesEfMiddleware.cs @@ -1,12 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. using System; using System.Threading.Tasks; using Benchmarks.Data; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; -using Microsoft.Data.Entity; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; +using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; diff --git a/src/Benchmarks/MultipleQueriesRawMiddleware.cs b/src/Benchmarks/MultipleQueriesRawMiddleware.cs index 5bc4936ba..8ebe47949 100644 --- a/src/Benchmarks/MultipleQueriesRawMiddleware.cs +++ b/src/Benchmarks/MultipleQueriesRawMiddleware.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. using System; @@ -6,8 +6,8 @@ using System.Data.Common; using System.Threading.Tasks; using Benchmarks.Data; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; diff --git a/src/Benchmarks/PlaintextMiddleware.cs b/src/Benchmarks/PlaintextMiddleware.cs index 1302525a6..05c233716 100644 --- a/src/Benchmarks/PlaintextMiddleware.cs +++ b/src/Benchmarks/PlaintextMiddleware.cs @@ -1,11 +1,11 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. using System; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; namespace Benchmarks { diff --git a/src/Benchmarks/Program.cs b/src/Benchmarks/Program.cs index 625a02df8..04cdd3b05 100644 --- a/src/Benchmarks/Program.cs +++ b/src/Benchmarks/Program.cs @@ -1,9 +1,9 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. using System; using System.Threading; -using Microsoft.AspNet.Hosting; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; namespace Benchmarks diff --git a/src/Benchmarks/SingleQueryDapperMiddleware.cs b/src/Benchmarks/SingleQueryDapperMiddleware.cs index dff57ef44..adeeec177 100644 --- a/src/Benchmarks/SingleQueryDapperMiddleware.cs +++ b/src/Benchmarks/SingleQueryDapperMiddleware.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. using System; @@ -7,8 +7,8 @@ using System.Threading.Tasks; using Benchmarks.Data; using Dapper; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; diff --git a/src/Benchmarks/SingleQueryEfMiddleware.cs b/src/Benchmarks/SingleQueryEfMiddleware.cs index 394e6963c..3e89384d3 100644 --- a/src/Benchmarks/SingleQueryEfMiddleware.cs +++ b/src/Benchmarks/SingleQueryEfMiddleware.cs @@ -1,12 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. using System; using System.Threading.Tasks; using Benchmarks.Data; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; -using Microsoft.Data.Entity; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; +using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; diff --git a/src/Benchmarks/SingleQueryRawMiddleware.cs b/src/Benchmarks/SingleQueryRawMiddleware.cs index cd5b51fb7..3eb6d0155 100644 --- a/src/Benchmarks/SingleQueryRawMiddleware.cs +++ b/src/Benchmarks/SingleQueryRawMiddleware.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. using System; @@ -6,8 +6,8 @@ using System.Data.Common; using System.Threading.Tasks; using Benchmarks.Data; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Http; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; diff --git a/src/Benchmarks/Startup.cs b/src/Benchmarks/Startup.cs index aa2f288bc..402295944 100644 --- a/src/Benchmarks/Startup.cs +++ b/src/Benchmarks/Startup.cs @@ -1,14 +1,14 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. using System; using System.Data.Common; using System.Data.SqlClient; using Benchmarks.Data; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Http; -using Microsoft.Data.Entity; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; diff --git a/src/Benchmarks/hosting.json b/src/Benchmarks/hosting.json index daa8238d5..e706790e8 100644 --- a/src/Benchmarks/hosting.json +++ b/src/Benchmarks/hosting.json @@ -1,5 +1,5 @@ -{ - "server": "Microsoft.AspNet.Server.Kestrel", +{ + "server": "Microsoft.AspNetCore.Server.Kestrel", "server.urls": "http://*:5001", "captureStartupErrors": true } diff --git a/src/Benchmarks/project.json b/src/Benchmarks/project.json index cc5a95ad9..b594499e9 100644 --- a/src/Benchmarks/project.json +++ b/src/Benchmarks/project.json @@ -8,18 +8,18 @@ "dependencies": { "Dapper": "1.50.0-*", - "EntityFramework.Commands": "7.0.0-*", - "EntityFramework.MicrosoftSqlServer": "7.0.0-*", - "Microsoft.AspNet.Mvc": "6.0.0-*", - "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", - "Microsoft.AspNet.Server.WebListener": "1.0.0-*", - "Microsoft.AspNet.StaticFiles": "1.0.0-*", + "Microsoft.EntityFrameworkCore.Commands": "7.0.0-*", + "Microsoft.EntityFrameworkCore.SqlServer": "7.0.0-*", + "Microsoft.AspNetCore.Mvc": "6.0.0-*", + "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", + "Microsoft.AspNetCore.Server.WebListener": "1.0.0-*", + "Microsoft.AspNetCore.StaticFiles": "1.0.0-*", "Microsoft.Extensions.Configuration.Binder": "1.0.0-*" }, "commands": { "Benchmarks": "Benchmarks", - "ef": "EntityFramework.Commands" + "ef": "Microsoft.EntityFrameworkCore.Commands" }, "frameworks": { From 1d8f07c873689a7ed08b95d9c3ba261bdce71583 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Mon, 25 Jan 2016 10:22:33 -0800 Subject: [PATCH 08/14] Update ASP.NET 5 versions for ASP.NET Core. See https://github.com/aspnet/Announcements/issues/144 for more information. --- src/Benchmarks/project.json | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/Benchmarks/project.json b/src/Benchmarks/project.json index b594499e9..1ba862613 100644 --- a/src/Benchmarks/project.json +++ b/src/Benchmarks/project.json @@ -1,36 +1,31 @@ { "webroot": "wwwroot", "version": "1.0.0-*", - "compilationOptions": { "emitEntryPoint": true }, - "dependencies": { "Dapper": "1.50.0-*", - "Microsoft.EntityFrameworkCore.Commands": "7.0.0-*", - "Microsoft.EntityFrameworkCore.SqlServer": "7.0.0-*", - "Microsoft.AspNetCore.Mvc": "6.0.0-*", + "Microsoft.EntityFrameworkCore.Commands": "1.0.0-*", + "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-*", + "Microsoft.AspNetCore.Mvc": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", - "Microsoft.AspNetCore.Server.WebListener": "1.0.0-*", + "Microsoft.AspNetCore.Server.WebListener": "0.1.0-*", "Microsoft.AspNetCore.StaticFiles": "1.0.0-*", "Microsoft.Extensions.Configuration.Binder": "1.0.0-*" }, - "commands": { "Benchmarks": "Benchmarks", "ef": "Microsoft.EntityFrameworkCore.Commands" }, - "frameworks": { - "dnx451": { }, - "dnxcore50": { - "dependencies": { - "System.Runtime.Serialization.Primitives": "4.1.0-*" - } + "dnx451": {}, + "dnxcore50": { + "dependencies": { + "System.Runtime.Serialization.Primitives": "4.1.0-*" + } } }, - "publishExclude": [ "node_modules", "bower_components", @@ -43,4 +38,4 @@ "node_modules", "bower_components" ] -} +} \ No newline at end of file From 47c6d367afa53f0060a95b93234eaa87bad33062 Mon Sep 17 00:00:00 2001 From: damianedwards Date: Thu, 31 Dec 2015 17:33:49 -0800 Subject: [PATCH 09/14] WIP --- src/Benchmarks/Program.cs | 19 ++++- src/Benchmarks/Startup.cs | 144 +++++++++++++++++++++++++------- src/Benchmarks/appsettings.json | 3 +- 3 files changed, 132 insertions(+), 34 deletions(-) diff --git a/src/Benchmarks/Program.cs b/src/Benchmarks/Program.cs index 04cdd3b05..cf9fba1d9 100644 --- a/src/Benchmarks/Program.cs +++ b/src/Benchmarks/Program.cs @@ -4,7 +4,7 @@ using System; using System.Threading; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Configuration; namespace Benchmarks { @@ -16,6 +16,21 @@ public static void Main(string[] args) .UseDefaultConfiguration(args) .UseStartup() .Build(); + Console.WriteLine(); + Console.WriteLine("ASP.NET 5 Benchmarks"); + Console.WriteLine("--------------------"); + + var config = new ConfigurationBuilder() + .AddCommandLine(args) + .Build(); + + if (string.IsNullOrEmpty(config["scenarios"])) + { + Console.WriteLine("Which scenarios would you like to enable?:"); + Console.WriteLine(" 1: Raw middleware"); + Console.WriteLine(" 2: All MV"); + Console.Write("1, 2, 3, A(ll)> "); + } // Run the interaction on a separate thread as we don't have Console.KeyAvailable on .NET Core so can't // do a pre-emptive check before we call Console.ReadKey (which blocks, hard) @@ -47,7 +62,7 @@ public static void Main(string[] args) }); interactiveThread.IsBackground = true; interactiveThread.Start(); - + host.Run(); } diff --git a/src/Benchmarks/Startup.cs b/src/Benchmarks/Startup.cs index 402295944..5b9eb321d 100644 --- a/src/Benchmarks/Startup.cs +++ b/src/Benchmarks/Startup.cs @@ -2,8 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.Data.Common; using System.Data.SqlClient; +using System.Linq; +using System.Reflection; using Benchmarks.Data; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -22,13 +25,8 @@ public Startup(IHostingEnvironment env) var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) - .AddEnvironmentVariables(); - - if (env.Configuration != null) - { - // This allows passing of config values via the cmd line, e.g.: dnx web --app.EnableDbTests=true - builder.AddConfiguration("app.", env.Configuration); - } + .AddEnvironmentVariables() + .AddCommandLine(Environment.GetCommandLineArgs()); Configuration = builder.Build(); @@ -45,65 +43,158 @@ public void ConfigureServices(IServiceCollection services) // no-op version to avoid the cost. services.AddSingleton(typeof(IHttpContextAccessor), typeof(InertHttpContextAccessor)); - if (StartupOptions.EnableDbTests) + if (StartupOptions.Scenarios.Any("Db")) { services.AddSingleton(); - // TODO: Add support for plugging in different DbProviderFactory implementations via configuration services.AddSingleton(SqlClientFactory.Instance); + } + if (StartupOptions.Scenarios.Any("Ef")) + { services.AddEntityFramework() .AddSqlServer() .AddDbContext(options => options.UseSqlServer(StartupOptions.ConnectionString)); + } + + if (StartupOptions.Scenarios.Any("Fortunes")) + { services.AddWebEncoders(); } - services.AddMvc(); + if (StartupOptions.Scenarios.MvcApis) + { + services.AddMvcCore(); + } + else if (StartupOptions.Scenarios.MvcViews) + { + services.AddMvcCore() + .AddViews() + .AddRazorViewEngine(); + } } public void Configure(IApplicationBuilder app) { app.UseErrorHandler(); - app.UsePlainText(); - app.UseJson(); - if (StartupOptions.EnableDbTests) + if (StartupOptions.Scenarios.Plaintext) + { + app.UsePlainText(); + } + + if (StartupOptions.Scenarios.Json) + { + app.UseJson(); + } + + // Single query endpoints + if (StartupOptions.Scenarios.DbSingleQueryRaw) { app.UseSingleQueryRaw(StartupOptions.ConnectionString); + } + + if (StartupOptions.Scenarios.DbSingleQueryDapper) + { app.UseSingleQueryDapper(StartupOptions.ConnectionString); + } + + if (StartupOptions.Scenarios.DbSingleQueryEf) + { app.UseSingleQueryEf(); + } + // Multiple query endpoints + if (StartupOptions.Scenarios.DbMultiQueryRaw) + { app.UseMultipleQueriesRaw(StartupOptions.ConnectionString); + } + + if (StartupOptions.Scenarios.DbMultiQueryDapper) + { app.UseMultipleQueriesDapper(StartupOptions.ConnectionString); - app.UseMultipleQueriesEf(); + } - app.UseFortunesRaw(StartupOptions.ConnectionString); - app.UseFortunesDapper(StartupOptions.ConnectionString); - app.UseFortunesEf(); + if (StartupOptions.Scenarios.DbMultiQueryEf) + { + app.UseMultipleQueriesEf(); + } + if (StartupOptions.Scenarios.Any("Db")) + { var dbContext = (ApplicationDbContext)app.ApplicationServices.GetService(typeof(ApplicationDbContext)); var seeder = (ApplicationDbSeeder)app.ApplicationServices.GetService(typeof(ApplicationDbSeeder)); if (!seeder.Seed(dbContext)) { Environment.Exit(1); } - Console.WriteLine("Database tests enabled"); } - app.UseMvc(); + if (StartupOptions.Scenarios.Any("Mvc")) + { + app.UseMvc(); + } - if (StartupOptions.EnableStaticFileTests) + if (StartupOptions.Scenarios.StaticFiles) { app.UseStaticFiles(); - Console.WriteLine("Static file tests enabled"); } app.UseDebugInfoPage(); app.Run(context => context.Response.WriteAsync("Try /plaintext instead")); } - + + public class Options + { + public string ConnectionString { get; set; } + + public Scenarios Scenarios { get; } = new Scenarios(); + } + + public class Scenarios + { + public bool All { get; set; } + + public bool Plaintext { get; set; } + + public bool Json { get; set; } + + public bool StaticFiles { get; set; } + + public bool MvcApis { get; set; } + + public bool MvcViews { get; set; } + + public bool DbSingleQueryRaw { get; set; } + + public bool DbSingleQueryEf { get; set; } + + public bool DbSingleQueryDapper { get; set; } + + public bool DbMultiQueryRaw { get; set; } + + public bool DbMultiQueryEf { get; set; } + + public bool DbMultiQueryDapper { get; set; } + + public bool DbFortunesRaw { get; set; } + + public bool DbFortunesEf { get; set; } + + public bool DbFortunesDapper { get; set; } + + public bool Any(string partialName) => + typeof(Scenarios).GetTypeInfo().DeclaredProperties + .Where(p => p.Name.IndexOf(partialName, StringComparison.Ordinal) >= 0 && (bool)p.GetValue(this)) + .Any(); + + public IEnumerable Names => + typeof(Scenarios).GetTypeInfo().DeclaredProperties + .Select(p => p.Name); + } + public class InertHttpContextAccessor : IHttpContextAccessor { public HttpContext HttpContext @@ -112,14 +203,5 @@ public HttpContext HttpContext set { return; } } } - - public class Options - { - public bool EnableDbTests { get; set; } - - public bool EnableStaticFileTests { get; set; } - - public string ConnectionString { get; set; } - } } } diff --git a/src/Benchmarks/appsettings.json b/src/Benchmarks/appsettings.json index 7456d9719..ae0375d8f 100644 --- a/src/Benchmarks/appsettings.json +++ b/src/Benchmarks/appsettings.json @@ -1,3 +1,4 @@ { - "ConnectionString": "Server=(localdb)\\mssqllocaldb;Database=aspnet5-Benchmarks;Trusted_Connection=True;MultipleActiveResultSets=true" + "ConnectionString": "Server=(localdb)\\mssqllocaldb;Database=aspnet5-Benchmarks;Trusted_Connection=True;MultipleActiveResultSets=true", + "Scenarios": "Plaintext,Json" } From fa502de4631deb95f3626e09dea0d4cd5989c7f5 Mon Sep 17 00:00:00 2001 From: damianedwards Date: Mon, 25 Jan 2016 18:44:01 -0800 Subject: [PATCH 10/14] Ability to enable specific scenarios: - Updated for rename too - Removed hosting.json --- .../MultipleQueriesDapperMiddleware.cs | 1 - src/Benchmarks/Program.cs | 109 +++++++++++++++--- src/Benchmarks/Scenarios.cs | 72 ++++++++++++ src/Benchmarks/Startup.cs | 102 +++++----------- src/Benchmarks/hosting.json | 5 - 5 files changed, 197 insertions(+), 92 deletions(-) create mode 100644 src/Benchmarks/Scenarios.cs delete mode 100644 src/Benchmarks/hosting.json diff --git a/src/Benchmarks/MultipleQueriesDapperMiddleware.cs b/src/Benchmarks/MultipleQueriesDapperMiddleware.cs index a34dae571..6a1a44fae 100644 --- a/src/Benchmarks/MultipleQueriesDapperMiddleware.cs +++ b/src/Benchmarks/MultipleQueriesDapperMiddleware.cs @@ -3,7 +3,6 @@ using System; using System.Data.Common; -using System.Linq; using System.Threading.Tasks; using Benchmarks.Data; using Dapper; diff --git a/src/Benchmarks/Program.cs b/src/Benchmarks/Program.cs index cf9fba1d9..f39cb9e27 100644 --- a/src/Benchmarks/Program.cs +++ b/src/Benchmarks/Program.cs @@ -2,42 +2,122 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Linq; using System.Threading; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; namespace Benchmarks { public class Program { + public static string[] Args; + public static void Main(string[] args) { - var host = new WebHostBuilder() - .UseDefaultConfiguration(args) - .UseStartup() - .Build(); + Args = args; + Console.WriteLine(); - Console.WriteLine("ASP.NET 5 Benchmarks"); - Console.WriteLine("--------------------"); + Console.WriteLine("ASP.NET Core Benchmarks"); + Console.WriteLine("-----------------------"); - var config = new ConfigurationBuilder() - .AddCommandLine(args) + var scenarios = LoadScenarios(args); + + StartInteractiveConsoleThread(); + + var webHost = new WebHostBuilder() + .UseServer("Microsoft.AspNetCore.Server.Kestrel") + .UseCaptureStartupErrors(false) + .UseDefaultConfiguration(args) + .UseStartup() + .ConfigureServices(services => services.AddSingleton(scenarios)) .Build(); - if (string.IsNullOrEmpty(config["scenarios"])) + webHost.Run(); + } + + private static Scenarios LoadScenarios(string[] args) + { + var scenarioConfig = new ConfigurationBuilder() + .AddJsonFile("scenarios.json", optional: true) + .AddCommandLine(args) + .Build() + .GetChildren() + .ToList(); + + var scenarios = new Scenarios(); + + if (scenarioConfig.Count > 0) + { + Console.WriteLine("Scenario configuration found in scenarios.json and/or command line args"); + foreach (var scenario in scenarioConfig) + { + scenarios.Enable(scenario.Value); + } + } + else { Console.WriteLine("Which scenarios would you like to enable?:"); - Console.WriteLine(" 1: Raw middleware"); - Console.WriteLine(" 2: All MV"); - Console.Write("1, 2, 3, A(ll)> "); + Console.WriteLine(); + foreach (var scenario in scenarios.GetNames()) + { + Console.WriteLine(" " + scenario); + } + Console.WriteLine(); + Console.WriteLine("Type full or partial scenario names separated by commas and hit [Enter]"); + Console.Write("> "); + + var choices = Console.ReadLine().Split(new [] {','}, StringSplitOptions.RemoveEmptyEntries); + + if (choices.Length == 0) + { + Console.WriteLine(); + Console.WriteLine("No choice entered, enabling default scenarios"); + scenarios.EnableDefault(); + } + else + { + var count = 0; + + foreach (var choice in choices) + { + count += scenarios.Enable(choice); + } + + if (count == 0) + { + Console.WriteLine(); + Console.WriteLine("No matching scenarios found, enabling defaults"); + scenarios.EnableDefault(); + } + } + } + + Console.WriteLine(); + Console.WriteLine("The following scenarios were enabled:"); + foreach (var scenario in scenarios.GetEnabled()) + { + Console.WriteLine(" " + scenario); } + Console.WriteLine(); + + return scenarios; + } + private static void StartInteractiveConsoleThread() + { // Run the interaction on a separate thread as we don't have Console.KeyAvailable on .NET Core so can't // do a pre-emptive check before we call Console.ReadKey (which blocks, hard) + + var started = new ManualResetEvent(false); + var interactiveThread = new Thread(() => { - Console.WriteLine(); Console.WriteLine("Press 'C' to force GC or any other key to display GC stats"); + Console.WriteLine(); + + started.Set(); while (true) { @@ -60,10 +140,11 @@ public static void Main(string[] args) } } }); + interactiveThread.IsBackground = true; interactiveThread.Start(); - host.Run(); + started.WaitOne(); } private static string GetAllocatedMemory(bool forceFullCollection = false) diff --git a/src/Benchmarks/Scenarios.cs b/src/Benchmarks/Scenarios.cs new file mode 100644 index 000000000..87478d19d --- /dev/null +++ b/src/Benchmarks/Scenarios.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Linq; + +namespace Benchmarks +{ + public class Scenarios + { + public bool Plaintext { get; set; } + + public bool Json { get; set; } + + public bool StaticFiles { get; set; } + + public bool MvcApis { get; set; } + + public bool MvcViews { get; set; } + + public bool DbSingleQueryRaw { get; set; } + + public bool DbSingleQueryEf { get; set; } + + public bool DbSingleQueryDapper { get; set; } + + public bool DbMultiQueryRaw { get; set; } + + public bool DbMultiQueryEf { get; set; } + + public bool DbMultiQueryDapper { get; set; } + + public bool DbFortunesRaw { get; set; } + + public bool DbFortunesEf { get; set; } + + public bool DbFortunesDapper { get; set; } + + public bool Any(string partialName) => + typeof(Scenarios).GetTypeInfo().DeclaredProperties + .Where(p => p.Name.IndexOf(partialName, StringComparison.Ordinal) >= 0 && (bool)p.GetValue(this)) + .Any(); + + public IEnumerable GetNames() => + typeof(Scenarios).GetTypeInfo().DeclaredProperties + .Select(p => p.Name); + + public IEnumerable GetEnabled() => + typeof(Scenarios).GetTypeInfo().DeclaredProperties + .Where(p => p.GetValue(this) is bool && (bool)p.GetValue(this)) + .Select(p => p.Name); + + public int Enable(string partialName) + { + var props = typeof(Scenarios).GetTypeInfo().DeclaredProperties + .Where(p => string.Equals(partialName, "[all]", StringComparison.OrdinalIgnoreCase) || p.Name.IndexOf(partialName, StringComparison.OrdinalIgnoreCase) >= 0) + .ToList(); + + foreach (var p in props) + { + p.SetValue(this, true); + } + + return props.Count; + } + + public void EnableDefault() + { + Plaintext = true; + Json = true; + } + } +} \ No newline at end of file diff --git a/src/Benchmarks/Startup.cs b/src/Benchmarks/Startup.cs index 5b9eb321d..baab61780 100644 --- a/src/Benchmarks/Startup.cs +++ b/src/Benchmarks/Startup.cs @@ -2,11 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Data.Common; using System.Data.SqlClient; -using System.Linq; -using System.Reflection; using Benchmarks.Data; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -19,23 +16,27 @@ namespace Benchmarks { public class Startup { - public Startup(IHostingEnvironment env) + public Startup(IHostingEnvironment env, Scenarios scenarios) { // Set up configuration sources. var builder = new ConfigurationBuilder() + .Include(env.Configuration) .AddJsonFile("appsettings.json") .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) - .AddEnvironmentVariables() - .AddCommandLine(Environment.GetCommandLineArgs()); + .AddEnvironmentVariables(); Configuration = builder.Build(); Configuration.Bind(StartupOptions); + + Scenarios = scenarios ?? new Scenarios(); } public IConfigurationRoot Configuration { get; set; } public Options StartupOptions { get; } = new Options(); + + public Scenarios Scenarios { get; } public void ConfigureServices(IServiceCollection services) { @@ -43,14 +44,14 @@ public void ConfigureServices(IServiceCollection services) // no-op version to avoid the cost. services.AddSingleton(typeof(IHttpContextAccessor), typeof(InertHttpContextAccessor)); - if (StartupOptions.Scenarios.Any("Db")) + if (Scenarios.Any("Db")) { services.AddSingleton(); // TODO: Add support for plugging in different DbProviderFactory implementations via configuration services.AddSingleton(SqlClientFactory.Instance); } - if (StartupOptions.Scenarios.Any("Ef")) + if (Scenarios.Any("Ef")) { services.AddEntityFramework() .AddSqlServer() @@ -58,20 +59,21 @@ public void ConfigureServices(IServiceCollection services) options.UseSqlServer(StartupOptions.ConnectionString)); } - if (StartupOptions.Scenarios.Any("Fortunes")) + if (Scenarios.Any("Fortunes")) { services.AddWebEncoders(); } - if (StartupOptions.Scenarios.MvcApis) - { - services.AddMvcCore(); - } - else if (StartupOptions.Scenarios.MvcViews) + if (Scenarios.Any("Mvc")) { - services.AddMvcCore() - .AddViews() - .AddRazorViewEngine(); + var mvcBuilder = services.AddMvcCore(); + + if (Scenarios.MvcViews) + { + mvcBuilder + .AddViews() + .AddRazorViewEngine(); + } } } @@ -79,49 +81,49 @@ public void Configure(IApplicationBuilder app) { app.UseErrorHandler(); - if (StartupOptions.Scenarios.Plaintext) + if (Scenarios.Plaintext) { app.UsePlainText(); } - if (StartupOptions.Scenarios.Json) + if (Scenarios.Json) { app.UseJson(); } // Single query endpoints - if (StartupOptions.Scenarios.DbSingleQueryRaw) + if (Scenarios.DbSingleQueryRaw) { app.UseSingleQueryRaw(StartupOptions.ConnectionString); } - if (StartupOptions.Scenarios.DbSingleQueryDapper) + if (Scenarios.DbSingleQueryDapper) { app.UseSingleQueryDapper(StartupOptions.ConnectionString); } - if (StartupOptions.Scenarios.DbSingleQueryEf) + if (Scenarios.DbSingleQueryEf) { app.UseSingleQueryEf(); } // Multiple query endpoints - if (StartupOptions.Scenarios.DbMultiQueryRaw) + if (Scenarios.DbMultiQueryRaw) { app.UseMultipleQueriesRaw(StartupOptions.ConnectionString); } - if (StartupOptions.Scenarios.DbMultiQueryDapper) + if (Scenarios.DbMultiQueryDapper) { app.UseMultipleQueriesDapper(StartupOptions.ConnectionString); } - if (StartupOptions.Scenarios.DbMultiQueryEf) + if (Scenarios.DbMultiQueryEf) { app.UseMultipleQueriesEf(); } - if (StartupOptions.Scenarios.Any("Db")) + if (Scenarios.Any("Db")) { var dbContext = (ApplicationDbContext)app.ApplicationServices.GetService(typeof(ApplicationDbContext)); var seeder = (ApplicationDbSeeder)app.ApplicationServices.GetService(typeof(ApplicationDbSeeder)); @@ -131,12 +133,12 @@ public void Configure(IApplicationBuilder app) } } - if (StartupOptions.Scenarios.Any("Mvc")) + if (Scenarios.Any("Mvc")) { app.UseMvc(); } - if (StartupOptions.Scenarios.StaticFiles) + if (Scenarios.StaticFiles) { app.UseStaticFiles(); } @@ -149,50 +151,6 @@ public void Configure(IApplicationBuilder app) public class Options { public string ConnectionString { get; set; } - - public Scenarios Scenarios { get; } = new Scenarios(); - } - - public class Scenarios - { - public bool All { get; set; } - - public bool Plaintext { get; set; } - - public bool Json { get; set; } - - public bool StaticFiles { get; set; } - - public bool MvcApis { get; set; } - - public bool MvcViews { get; set; } - - public bool DbSingleQueryRaw { get; set; } - - public bool DbSingleQueryEf { get; set; } - - public bool DbSingleQueryDapper { get; set; } - - public bool DbMultiQueryRaw { get; set; } - - public bool DbMultiQueryEf { get; set; } - - public bool DbMultiQueryDapper { get; set; } - - public bool DbFortunesRaw { get; set; } - - public bool DbFortunesEf { get; set; } - - public bool DbFortunesDapper { get; set; } - - public bool Any(string partialName) => - typeof(Scenarios).GetTypeInfo().DeclaredProperties - .Where(p => p.Name.IndexOf(partialName, StringComparison.Ordinal) >= 0 && (bool)p.GetValue(this)) - .Any(); - - public IEnumerable Names => - typeof(Scenarios).GetTypeInfo().DeclaredProperties - .Select(p => p.Name); } public class InertHttpContextAccessor : IHttpContextAccessor diff --git a/src/Benchmarks/hosting.json b/src/Benchmarks/hosting.json deleted file mode 100644 index e706790e8..000000000 --- a/src/Benchmarks/hosting.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "server": "Microsoft.AspNetCore.Server.Kestrel", - "server.urls": "http://*:5001", - "captureStartupErrors": true -} From e67daaa20fdc21bc7d451995b65df7f5325953a9 Mon Sep 17 00:00:00 2001 From: damianedwards Date: Mon, 25 Jan 2016 22:45:00 -0800 Subject: [PATCH 11/14] Tweak default middleware message --- src/Benchmarks/Startup.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Benchmarks/Startup.cs b/src/Benchmarks/Startup.cs index baab61780..55d81d643 100644 --- a/src/Benchmarks/Startup.cs +++ b/src/Benchmarks/Startup.cs @@ -145,7 +145,7 @@ public void Configure(IApplicationBuilder app) app.UseDebugInfoPage(); - app.Run(context => context.Response.WriteAsync("Try /plaintext instead")); + app.Run(context => context.Response.WriteAsync("Try /plaintext instead, or /debug for more information")); } public class Options From 0bf5694a5c55d142b667bb877e95851073f50f90 Mon Sep 17 00:00:00 2001 From: damianedwards Date: Tue, 26 Jan 2016 12:53:47 -0800 Subject: [PATCH 12/14] Switch to using net451 TFM instead of dnx451 --- src/Benchmarks/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Benchmarks/project.json b/src/Benchmarks/project.json index 1ba862613..6bdec0abe 100644 --- a/src/Benchmarks/project.json +++ b/src/Benchmarks/project.json @@ -19,7 +19,7 @@ "ef": "Microsoft.EntityFrameworkCore.Commands" }, "frameworks": { - "dnx451": {}, + "net451": {}, "dnxcore50": { "dependencies": { "System.Runtime.Serialization.Primitives": "4.1.0-*" From a263612a8835ac41ee1ecba3f93c180289fbef24 Mon Sep 17 00:00:00 2001 From: damianedwards Date: Tue, 26 Jan 2016 16:06:22 -0800 Subject: [PATCH 13/14] Remove remaining OrdinalIgnoreCase path checks --- src/Benchmarks/DebugInfoPageMiddleware.cs | 4 +--- src/Benchmarks/MultipleQueriesDapperMiddleware.cs | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Benchmarks/DebugInfoPageMiddleware.cs b/src/Benchmarks/DebugInfoPageMiddleware.cs index efebd3fb5..5f649d7da 100644 --- a/src/Benchmarks/DebugInfoPageMiddleware.cs +++ b/src/Benchmarks/DebugInfoPageMiddleware.cs @@ -35,9 +35,7 @@ public DebugInfoPageMiddleware(RequestDelegate next, IHostingEnvironment hosting public async Task Invoke(HttpContext httpContext) { - // We check Ordinal explicitly first because it's faster than OrdinalIgnoreCase - if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal) || - httpContext.Request.Path.StartsWithSegments(_path, StringComparison.OrdinalIgnoreCase)) + if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal)) { httpContext.Response.ContentType = "text/html"; diff --git a/src/Benchmarks/MultipleQueriesDapperMiddleware.cs b/src/Benchmarks/MultipleQueriesDapperMiddleware.cs index f3bd7912e..fd60a09ab 100644 --- a/src/Benchmarks/MultipleQueriesDapperMiddleware.cs +++ b/src/Benchmarks/MultipleQueriesDapperMiddleware.cs @@ -35,7 +35,6 @@ public MultipleQueriesDapperMiddleware(RequestDelegate next, string connectionSt public async Task Invoke(HttpContext httpContext) { - // We check Ordinal explicitly first because it's faster than OrdinalIgnoreCase if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal)) { var count = GetQueryCount(httpContext); From 648217f23ea05b0f251e309d76578a95847ea980 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 27 Jan 2016 00:31:35 +0000 Subject: [PATCH 14/14] Pool http context --- src/Benchmarks/Startup.cs | 68 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/Benchmarks/Startup.cs b/src/Benchmarks/Startup.cs index 55d81d643..74272997f 100644 --- a/src/Benchmarks/Startup.cs +++ b/src/Benchmarks/Startup.cs @@ -2,12 +2,15 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.Data.Common; using System.Data.SqlClient; using Benchmarks.Data; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Http.Internal; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -43,6 +46,7 @@ public void ConfigureServices(IServiceCollection services) // No scenarios covered by the benchmarks require the HttpContextAccessor so we're replacing it with a // no-op version to avoid the cost. services.AddSingleton(typeof(IHttpContextAccessor), typeof(InertHttpContextAccessor)); + services.AddSingleton(typeof(IHttpContextFactory), typeof(PooledContextFactory)); if (Scenarios.Any("Db")) { @@ -161,5 +165,69 @@ public HttpContext HttpContext set { return; } } } + + public class PooledContextFactory : IHttpContextFactory + { + private IHttpContextAccessor _httpContextAccessor; + + [ThreadStatic] + static Queue _contextPool; + + public PooledContextFactory() : this(httpContextAccessor: null) + { + } + + public PooledContextFactory(IHttpContextAccessor httpContextAccessor) + { + _httpContextAccessor = httpContextAccessor; + } + + private Queue ContextPool + { + get + { + if (_contextPool == null) + { + _contextPool = new Queue(16); + } + + return _contextPool; + } + } + + public HttpContext Create(IFeatureCollection featureCollection) + { + var contextPool = ContextPool; + if (contextPool.Count > 0) + { + var context = contextPool.Dequeue(); + context.Initialize(featureCollection); + return context; + } + + return new DefaultHttpContext(featureCollection); + } + + public void Dispose(HttpContext httpContext) + { + if (_httpContextAccessor != null) + { + _httpContextAccessor.HttpContext = null; + } + + var context = httpContext as DefaultHttpContext; + + if (context != null) + { + context.Uninitialize(); + + var contextPool = ContextPool; + if (contextPool.Count < 16) + { + contextPool.Enqueue(context); + } + } + } + } } }