Skip to content

Commit

Permalink
Add SignalR Client and scenario (aspnet#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennanConroy authored Mar 5, 2018
1 parent 9456d87 commit 584b3c2
Show file tree
Hide file tree
Showing 16 changed files with 716 additions and 15 deletions.
5 changes: 3 additions & 2 deletions build/dependencies.props
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Project>
<PropertyGroup>
<AspNetCoreVersion>2.1.0-*</AspNetCoreVersion>
<AspNetCoreVersion>2.1.0-preview2-3*</AspNetCoreVersion>
<CoreFxVersion>4.4.0-*</CoreFxVersion>
<InternalAspNetCoreSdkVersion>2.1.1-*</InternalAspNetCoreSdkVersion>
<JsonNetVersion>10.0.1</JsonNetVersion>
<JilVersion>2.15.4</JilVersion>
<SignalRVersion>1.0.0-*</SignalRVersion>
<NETStandardImplicitPackageVersion>2.0.0</NETStandardImplicitPackageVersion>
<NETCoreAppImplicitPackageVersion>2.0.0</NETCoreAppImplicitPackageVersion>
<MicrosoftNETCoreApp20PackageVersion>2.0.0</MicrosoftNETCoreApp20PackageVersion>
<MicrosoftNETCoreApp21PackageVersion>2.1.0-preview1-26016-05</MicrosoftNETCoreApp21PackageVersion>
<MicrosoftNETCoreApp21PackageVersion>2.1.0-preview2-26225-03</MicrosoftNETCoreApp21PackageVersion>
<RuntimeFrameworkVersion>2.0.0-*</RuntimeFrameworkVersion>
<DefaultTargetFramework>netcoreapp2.0</DefaultTargetFramework>

Expand Down
10 changes: 5 additions & 5 deletions src/Benchmarks.ClientJob/Latency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ namespace Benchmarks.ClientJob
{
public class Latency
{
public double Average { get; set; }
public double Within50thPercentile { get; set; }
public double Within75thPercentile { get; set; }
public double Within90thPercentile { get; set; }
public double Within99thPercentile { get; set; }
public double Average { get; set; } = -1;
public double Within50thPercentile { get; set; } = -1;
public double Within75thPercentile { get; set; } = -1;
public double Within90thPercentile { get; set; } = -1;
public double Within99thPercentile { get; set; } = -1;
}
}
3 changes: 2 additions & 1 deletion src/Benchmarks.ClientJob/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Benchmarks.ClientJob
{
public enum Worker
{
Wrk
Wrk,
SignalR,
}
}
2 changes: 2 additions & 0 deletions src/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<PackageReference Include="Microsoft.AspNetCore.Server.HttpSys" Version="$(BenchmarksAspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(BenchmarksAspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Https" Version="$(BenchmarksAspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="$(SignalRVersion)" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.MsgPack" Version="$(SignalRVersion)" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="$(BenchmarksAspNetCoreVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(BenchmarksAspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="$(BenchmarksAspNetCoreVersion)" />
Expand Down
3 changes: 3 additions & 0 deletions src/Benchmarks/Configuration/Scenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ public Scenarios(IScenariosConfiguration scenariosConfiguration)
[ScenarioPath("/mvc/fortunes/dapper")]
public bool MvcDbFortunesDapper { get; set; }

[ScenarioPath("/signalr/broadcast")]
public bool SignalRBroadcast { get; set; }

public bool Any(string partialName) =>
typeof(Scenarios).GetTypeInfo().DeclaredProperties
.Where(p => p.Name.IndexOf(partialName, StringComparison.Ordinal) >= 0 && (bool)p.GetValue(this))
Expand Down
45 changes: 45 additions & 0 deletions src/Benchmarks/Middleware/SignalRMiddleware.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 Benchmarks.Configuration;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.SignalR;

namespace Benchmarks.Middleware
{
public static class SignalRMiddlewareExtensions
{
public static IApplicationBuilder UseSignalRMiddleware(this IApplicationBuilder builder)
{
return builder.UseSignalR(route =>
{
route.MapHub<EchoHub>(Scenarios.GetPath(s => s.SignalRBroadcast) + "/default");
});
}
}

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");
}
}
}
11 changes: 11 additions & 0 deletions src/Benchmarks/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ public void ConfigureServices(IServiceCollection services)
{
services.AddResponseCaching();
}

if (Scenarios.Any("SignalR"))
{
services.AddSignalR()
.AddMessagePackProtocol();
}
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
Expand Down Expand Up @@ -307,6 +313,11 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
app.UseResponseCachingPlaintextVaryByCached();
}

if (Scenarios.SignalRBroadcast)
{
app.UseSignalRMiddleware();
}

app.RunDebugInfoPage();
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/Benchmarks/signalr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Default": {
"ClientName": "signalr",
"Source": {
"Repository": "https://github.com/aspnet/benchmarks.git",
"BranchOrCommit": "brecon/signalrClientNew",
"Project": "src/Benchmarks/Benchmarks.csproj"
}
},
"SignalRBroadcast": {
"Path": "/signalr/broadcast"
}
}
11 changes: 7 additions & 4 deletions src/BenchmarksClient/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private static async Task ProcessJobs(CancellationToken cancellationToken)
job.State = ClientState.Deleting;
}
else
{
{
await worker.StartAsync();
}
}
Expand All @@ -151,15 +151,18 @@ private static async Task ProcessJobs(CancellationToken cancellationToken)
}
else if (job.State == ClientState.Deleting)
{
Log($"Deleting job {worker.JobLogText}");
Log($"Deleting job {worker?.JobLogText ?? "no worker found"}");

try
{
await worker.StopAsync();
if (worker != null)
{
await worker.StopAsync();
}
}
finally
{
worker.Dispose();
worker?.Dispose();
worker = null;

_jobs.Remove(job.Id);
Expand Down
10 changes: 9 additions & 1 deletion src/BenchmarksDriver/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,19 @@ public static int Main(string[] args)
mergedClientJob.Merge(job);
_clientJob = mergedClientJob.ToObject<ClientJob>();

if (clientNameOption.HasValue() && Enum.TryParse<Worker>(clientNameOption.Value(), ignoreCase: true, result: out var worker))
if (clientNameOption.HasValue())
{
if (!Enum.TryParse<Worker>(clientNameOption.Value(), ignoreCase: true, result: out var worker))
{
Log($"Could not find worker {clientNameOption.Value()}");
return 9;
}

_clientJob.Client = worker;
}

Log($"Using worker {_clientJob.Client}");

// Override default ClientJob settings if options are set
if (connectionsOption.HasValue())
{
Expand Down
5 changes: 5 additions & 0 deletions src/BenchmarksDriver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ Properties of the Wrk client
ScriptName Name of the script used by wrk.
PipelineDepth Depth of pipeline used by clients.
Properties of the SignalR client
HubProtocol Name of the hub protocol to be used between client and server.
TransportType Name of the transport to communicate over.
LogLevel LogLevel name for SignalR connections to use. e.g. 'Trace' or 'Warning'
```

### Examples
Expand Down
2 changes: 2 additions & 0 deletions src/BenchmarksWorkers/BenchmarksWorkers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
<ProjectReference Include="..\Benchmarks.ClientJob\Benchmarks.ClientJob.csproj" />
<ProjectReference Include="..\Benchmarks.ServerJob\Benchmarks.ServerJob.csproj" />
<PackageReference Include="System.Data.SqlClient" Version="$(CoreFxVersion)" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="$(SignalRVersion)" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client.MsgPack" Version="$(SignalRVersion)" />
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions src/BenchmarksWorkers/WorkerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ static WorkerFactory()
// Wrk
Workers[Worker.Wrk] = clientJob => new WrkWorker(clientJob);
ResultSerializers[Worker.Wrk] = () => new WrkSerializer();

// SignalR
Workers[Worker.SignalR] = clientJob => new SignalRWorker(clientJob);
ResultSerializers[Worker.SignalR] = () => new SignalRSerializer();
}

static public IWorker CreateWorker(ClientJob clientJob)
Expand Down
Loading

0 comments on commit 584b3c2

Please sign in to comment.