Skip to content

Commit

Permalink
Migrated to .NET 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hallatore committed Jun 1, 2020
1 parent 5ee3e2b commit 81b56a7
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 19 deletions.
38 changes: 38 additions & 0 deletions Netling.Benchmarks/Core/WorkerThreadResults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using Netling.Core;
using Netling.Core.Models;
using Netling.Core.SocketWorker;

namespace Netling.Benchmarks.Core
{
[MemoryDiagnoser]
public class WorkerThreadResults
{
private readonly WorkerThreadResult _result;
private IWorkerJob _worker;

public WorkerThreadResults()
{
_result = new WorkerThreadResult();
var socketWorker = new SocketWorkerJob(new Uri("http://localhost:5000"));
_worker = socketWorker.Init(0, _result).Result;
}

//[Benchmark]
public void Add()
{
for (var i = 0; i < 1000; i++)
{
_result.Add(i / 100, 1337, 10f, 200, false);
}
}

[Benchmark]
public async ValueTask SocketWorker()
{
await _worker.DoWork();
}
}
}
4 changes: 2 additions & 2 deletions Netling.Benchmarks/Netling.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.11.4" />
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Netling.Client/Netling.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<UseWPF>true</UseWPF>
<ApplicationIcon>netling-icon.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OxyPlot.Wpf" Version="1.0.0" />
<PackageReference Include="OxyPlot.Wpf" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 7 additions & 1 deletion Netling.Client/ResultWindowItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public static ResultWindowItem Parse(WorkerResult result)
Median = result.Median,
StdDev = result.StdDev,
Min = result.Min,
Max = result.Max
Max = result.Max,
P99 = result.P99,
P95 = result.P95,
P50 = result.P50
};
}

Expand All @@ -30,6 +33,9 @@ public static ResultWindowItem Parse(WorkerResult result)
public double ElapsedSeconds { get; set; }
public double JobsPerSecond { get; set; }
public double Max { get; set; }
public double P99 { get; set; }
public double P95 { get; set; }
public double P50 { get; set; }
public double Min { get; set; }
public double StdDev { get; set; }
public double Median { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Netling.ConsoleClient/Netling.ConsoleClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Netling.Core.SocketWorker/Netling.Core.SocketWorker.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions Netling.Core/Models/WorkerResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public WorkerResult(string name, int threads, TimeSpan elapsed)
public double StdDev { get; private set; }
public double Min { get; private set; }
public double Max { get; private set; }
public double P99 { get; private set; }
public double P95 { get; private set; }
public double P50 { get; private set; }
public int[] Histogram { get; private set; }

public double Bandwidth => Math.Round(BytesPrSecond * 8 / 1024 / 1024, MidpointRounding.AwayFromZero);
Expand All @@ -57,6 +60,9 @@ public void Process(CombinedWorkerThreadResult wtResult)
StdDev = responseTimes.GetStdDev();
Min = responseTimes.First();
Max = responseTimes.Last();
P99 = responseTimes[(int)(responseTimes.Length * 0.99)];
P95 = responseTimes[(int)(responseTimes.Length * 0.95)];
P50 = responseTimes[(int)(responseTimes.Length / 2)];
Histogram = GenerateHistogram(responseTimes);
}

Expand Down
20 changes: 15 additions & 5 deletions Netling.Core/Models/WorkerThreadResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,33 @@ public class WorkerThreadResult
public Dictionary<int, int> StatusCodes { get; set; }
public Dictionary<Type,Exception> Exceptions { get; set; }

private Second _tmpSeconds;
private int _tmpElapsedSeconds = -1;

public WorkerThreadResult()
{
Seconds = new Dictionary<int, Second>();
StatusCodes = new Dictionary<int, int>();
Exceptions = new Dictionary<Type, Exception>();
}

public void Add(int elapsedSeconds, long bytes, float responsetime, int statusCode, bool trackResponseTime)
public void Add(int elapsedSeconds, long bytes, float responseTime, int statusCode, bool trackResponseTime)
{
AddOrUpdateStatusCode(statusCode);
GetItem(elapsedSeconds).Add(bytes, responsetime, trackResponseTime);

if (_tmpElapsedSeconds != elapsedSeconds)
{
_tmpSeconds = GetCurrentSecond(elapsedSeconds);
_tmpElapsedSeconds = elapsedSeconds;
}

_tmpSeconds.Add(bytes, responseTime, trackResponseTime);
}

public void AddError(int elapsedSeconds, float responsetime, int statusCode, bool trackResponseTime, Exception exception = null)
public void AddError(int elapsedSeconds, float responseTime, int statusCode, bool trackResponseTime, Exception exception = null)
{
AddOrUpdateStatusCode(statusCode);
GetItem(elapsedSeconds).AddError(responsetime, trackResponseTime);
GetCurrentSecond(elapsedSeconds).AddError(responseTime, trackResponseTime);

if (exception != null && !Exceptions.ContainsKey(exception.GetType()))
{
Expand All @@ -48,7 +58,7 @@ private void AddOrUpdateStatusCode(int statusCode)
StatusCodes[statusCode]++;
}

private Second GetItem(int elapsedSeconds)
private Second GetCurrentSecond(int elapsedSeconds)
{
if (Seconds.ContainsKey(elapsedSeconds))
{
Expand Down
2 changes: 1 addition & 1 deletion Netling.Core/Netling.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

</Project>
11 changes: 7 additions & 4 deletions Netling.Tests/Netling.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Netling is a load tester client for easy web testing. It is extremely fast while using little CPU or memory.

## Requirements
.NET Core 3.0
.NET 5

## Usage

Expand Down

0 comments on commit 81b56a7

Please sign in to comment.