diff --git a/SignalR.sln b/SignalR.sln index 6c1e5527ff..4f0a69fe76 100644 --- a/SignalR.sln +++ b/SignalR.sln @@ -81,14 +81,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JwtClientSample", "samples\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.SignalR.Tests.Utils", "test\Microsoft.AspNetCore.SignalR.Tests.Utils\Microsoft.AspNetCore.SignalR.Tests.Utils.csproj", "{0A0A6135-EA24-4307-95C2-CE1B7E164A5E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.SignalR.Protocols.MsgPack", "src\Microsoft.AspNetCore.SignalR.Protocols.MsgPack\Microsoft.AspNetCore.SignalR.Protocols.MsgPack.csproj", "{55DB4B6F-12E5-4A27-97F4-E97E135470FF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.SignalR.Protocols.MsgPack", "src\Microsoft.AspNetCore.SignalR.Protocols.MsgPack\Microsoft.AspNetCore.SignalR.Protocols.MsgPack.csproj", "{55DB4B6F-12E5-4A27-97F4-E97E135470FF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.SignalR.MsgPack", "src\Microsoft.AspNetCore.SignalR.MsgPack\Microsoft.AspNetCore.SignalR.MsgPack.csproj", "{FDDB4E1F-2FD2-49E8-B0FF-874B0931369A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.SignalR.MsgPack", "src\Microsoft.AspNetCore.SignalR.MsgPack\Microsoft.AspNetCore.SignalR.MsgPack.csproj", "{FDDB4E1F-2FD2-49E8-B0FF-874B0931369A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.SignalR.Client.MsgPack", "src\Microsoft.AspNetCore.SignalR.Client.MsgPack\Microsoft.AspNetCore.SignalR.Client.MsgPack.csproj", "{4DBF918E-BD37-4309-B448-BA68C935944D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.SignalR.Client.MsgPack", "src\Microsoft.AspNetCore.SignalR.Client.MsgPack\Microsoft.AspNetCore.SignalR.Client.MsgPack.csproj", "{4DBF918E-BD37-4309-B448-BA68C935944D}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionalTests", "client-ts\FunctionalTests\FunctionalTests.csproj", "{D0C7B22E-B0B6-4D62-BF7D-79EE4AAF1981}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchmarkServer", "benchmarks\BenchmarkServer\BenchmarkServer.csproj", "{B5286020-C218-443C-91A9-B65751FB9B29}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -215,6 +217,10 @@ Global {D0C7B22E-B0B6-4D62-BF7D-79EE4AAF1981}.Debug|Any CPU.Build.0 = Debug|Any CPU {D0C7B22E-B0B6-4D62-BF7D-79EE4AAF1981}.Release|Any CPU.ActiveCfg = Release|Any CPU {D0C7B22E-B0B6-4D62-BF7D-79EE4AAF1981}.Release|Any CPU.Build.0 = Release|Any CPU + {B5286020-C218-443C-91A9-B65751FB9B29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B5286020-C218-443C-91A9-B65751FB9B29}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B5286020-C218-443C-91A9-B65751FB9B29}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B5286020-C218-443C-91A9-B65751FB9B29}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -250,6 +256,7 @@ Global {FDDB4E1F-2FD2-49E8-B0FF-874B0931369A} = {DA69F624-5398-4884-87E4-B816698CDE65} {4DBF918E-BD37-4309-B448-BA68C935944D} = {DA69F624-5398-4884-87E4-B816698CDE65} {D0C7B22E-B0B6-4D62-BF7D-79EE4AAF1981} = {3A76C5A2-79ED-49BC-8BDC-6A3A766FFA1B} + {B5286020-C218-443C-91A9-B65751FB9B29} = {8A4582C8-DC59-4B61-BCE7-119FBAA99EFB} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {7945A4E4-ACDB-4F6E-95CA-6AC6E7C2CD59} diff --git a/benchmarks/BenchmarkServer/BenchmarkServer.csproj b/benchmarks/BenchmarkServer/BenchmarkServer.csproj new file mode 100644 index 0000000000..271cf4719a --- /dev/null +++ b/benchmarks/BenchmarkServer/BenchmarkServer.csproj @@ -0,0 +1,20 @@ + + + + netcoreapp2.1 + + + + + + + + + + + + + + + + diff --git a/benchmarks/BenchmarkServer/Hubs/EchoHub.cs b/benchmarks/BenchmarkServer/Hubs/EchoHub.cs new file mode 100644 index 0000000000..739be3fc61 --- /dev/null +++ b/benchmarks/BenchmarkServer/Hubs/EchoHub.cs @@ -0,0 +1,32 @@ +// 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 System.Threading.Tasks; +using Microsoft.AspNetCore.SignalR; + +namespace BenchmarkServer.Hubs +{ + public class EchoHub : Hub + { + public async Task Echo(int duration) + { + try + { + var t = new CancellationTokenSource(); + t.CancelAfter(TimeSpan.FromSeconds(duration)); + while (!t.IsCancellationRequested && !Context.Connection.ConnectionAbortedToken.IsCancellationRequested) + { + await Clients.All.SendAsync("echo", DateTime.UtcNow); + } + } + catch (Exception e) + { + Console.WriteLine(e); + } + + Console.WriteLine("Echo exited"); + } + } +} diff --git a/benchmarks/BenchmarkServer/Program.cs b/benchmarks/BenchmarkServer/Program.cs new file mode 100644 index 0000000000..a280edb3b6 --- /dev/null +++ b/benchmarks/BenchmarkServer/Program.cs @@ -0,0 +1,35 @@ +// 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 Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace BenchmarkServer +{ + public class Program + { + public static void Main(string[] args) + { + var config = new ConfigurationBuilder() + .AddEnvironmentVariables(prefix: "ASPNETCORE_") + .AddCommandLine(args) + .Build(); + + var host = new WebHostBuilder() + .UseConfiguration(config) + .ConfigureLogging(loggerFactory => + { + if (Enum.TryParse(config["LogLevel"], out LogLevel logLevel)) + { + loggerFactory.AddConsole().SetMinimumLevel(logLevel); + } + }) + .UseKestrel() + .UseStartup(); + + host.Build().Run(); + } + } +} diff --git a/benchmarks/BenchmarkServer/README.md b/benchmarks/BenchmarkServer/README.md new file mode 100644 index 0000000000..f9ea3fa3c5 --- /dev/null +++ b/benchmarks/BenchmarkServer/README.md @@ -0,0 +1,17 @@ +## Purpose + +This project is to assist in Benchmarking SignalR. +It makes it easier to test local changes than having the App in the Benchmarks repo by letting us make changes in signalr branches and using the example commandline below to run the benchmarks against our branches. + +The SignalRWorker that runs against this server is located at https://github.com/aspnet/benchmarks/blob/dev/src/BenchmarksWorkers/Workers/SignalRWorker.cs. + +## Usage + +1. Push changes you would like to test to a branch on GitHub +2. Clone aspnet/benchmarks repo to your machine or install the global BenchmarksDriver tool https://www.nuget.org/packages/BenchmarksDriver/ +3. If cloned go to the BenchmarksDriver project +4. Use the following command as a guideline for running a test using your changes + +`dotnet run --server --client --properties "Transport=WebSockets" --properties "HubProtocol=messagepack" -j --repository signalr@branch-name --projectFile benchmarks/BenchmarkServer/BenchmarkServer.csproj` + +5. For more info/commands see https://github.com/aspnet/benchmarks/blob/dev/src/BenchmarksDriver/README.md \ No newline at end of file diff --git a/benchmarks/BenchmarkServer/Startup.cs b/benchmarks/BenchmarkServer/Startup.cs new file mode 100644 index 0000000000..22a336bf05 --- /dev/null +++ b/benchmarks/BenchmarkServer/Startup.cs @@ -0,0 +1,27 @@ +// 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 BenchmarkServer.Hubs; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; + +namespace BenchmarkServer +{ + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + services.AddSignalR() + .AddMessagePackProtocol(); + } + + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + app.UseSignalR(routes => + { + routes.MapHub("/echo"); + }); + } + } +} diff --git a/benchmarks/BenchmarkServer/signalr.json b/benchmarks/BenchmarkServer/signalr.json new file mode 100644 index 0000000000..410e76ffe6 --- /dev/null +++ b/benchmarks/BenchmarkServer/signalr.json @@ -0,0 +1,16 @@ +{ + "Default": { + "Client": "SignalR", + "Source": { + "Repository": "https://github.com/aspnet/benchmarks.git", + "BranchOrCommit": "dev", + "Project": "src/Benchmarks/Benchmarks.csproj" + }, + "Connections": 10, + "Duration": 20, + "Warmup": 2 + }, + "SignalRBroadcast": { + "Path": "/echo" + } +} \ No newline at end of file