Skip to content

Commit 5b364e6

Browse files
committed
Migrated to .NET 5.0
1 parent 5ee3e2b commit 5b364e6

11 files changed

Lines changed: 81 additions & 18 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using BenchmarkDotNet.Attributes;
4+
using Netling.Core;
5+
using Netling.Core.Models;
6+
using Netling.Core.SocketWorker;
7+
8+
namespace Netling.Benchmarks.Core
9+
{
10+
[MemoryDiagnoser]
11+
public class WorkerThreadResults
12+
{
13+
private readonly WorkerThreadResult _result;
14+
private IWorkerJob _worker;
15+
16+
public WorkerThreadResults()
17+
{
18+
_result = new WorkerThreadResult();
19+
var socketWorker = new SocketWorkerJob(new Uri("http://localhost:5000"));
20+
_worker = socketWorker.Init(0, _result).Result;
21+
}
22+
23+
//[Benchmark]
24+
public void Add()
25+
{
26+
for (var i = 0; i < 1000; i++)
27+
{
28+
_result.Add(i / 100, 1337, 10f, 200, false);
29+
}
30+
}
31+
32+
[Benchmark]
33+
public async ValueTask SocketWorker()
34+
{
35+
await _worker.DoWork();
36+
}
37+
}
38+
}

Netling.Benchmarks/Netling.Benchmarks.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
<TargetFramework>net5.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="BenchmarkDotNet" Version="0.11.4" />
9+
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
1010
</ItemGroup>
1111

1212
<ItemGroup>

Netling.Client/Netling.Client.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
5-
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
<TargetFramework>net5.0</TargetFramework>
66
<UseWPF>true</UseWPF>
77
<ApplicationIcon>netling-icon.ico</ApplicationIcon>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="OxyPlot.Wpf" Version="1.0.0" />
11+
<PackageReference Include="OxyPlot.Wpf" Version="2.0.0" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

Netling.Client/ResultWindowItem.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ public static ResultWindowItem Parse(WorkerResult result)
1919
Median = result.Median,
2020
StdDev = result.StdDev,
2121
Min = result.Min,
22-
Max = result.Max
22+
Max = result.Max,
23+
P99 = result.P99,
24+
P95 = result.P95,
25+
P50 = result.P50
2326
};
2427
}
2528

@@ -30,6 +33,9 @@ public static ResultWindowItem Parse(WorkerResult result)
3033
public double ElapsedSeconds { get; set; }
3134
public double JobsPerSecond { get; set; }
3235
public double Max { get; set; }
36+
public double P99 { get; set; }
37+
public double P95 { get; set; }
38+
public double P50 { get; set; }
3339
public double Min { get; set; }
3440
public double StdDev { get; set; }
3541
public double Median { get; set; }

Netling.ConsoleClient/Netling.ConsoleClient.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
<TargetFramework>net5.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>

Netling.Core.HttpClientWorker/Netling.Core.HttpClientWorker.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.0</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>

Netling.Core.SocketWorker/Netling.Core.SocketWorker.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.0</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>

Netling.Core/Models/WorkerResult.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public WorkerResult(string name, int threads, TimeSpan elapsed)
3232
public double StdDev { get; private set; }
3333
public double Min { get; private set; }
3434
public double Max { get; private set; }
35+
public double P99 { get; private set; }
36+
public double P95 { get; private set; }
37+
public double P50 { get; private set; }
3538
public int[] Histogram { get; private set; }
3639

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

Netling.Core/Models/WorkerThreadResult.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,33 @@ public class WorkerThreadResult
99
public Dictionary<int, int> StatusCodes { get; set; }
1010
public Dictionary<Type,Exception> Exceptions { get; set; }
1111

12+
private Second _tmpSeconds;
13+
private int _tmpElapsedSeconds = -1;
14+
1215
public WorkerThreadResult()
1316
{
1417
Seconds = new Dictionary<int, Second>();
1518
StatusCodes = new Dictionary<int, int>();
1619
Exceptions = new Dictionary<Type, Exception>();
1720
}
1821

19-
public void Add(int elapsedSeconds, long bytes, float responsetime, int statusCode, bool trackResponseTime)
22+
public void Add(int elapsedSeconds, long bytes, float responseTime, int statusCode, bool trackResponseTime)
2023
{
2124
AddOrUpdateStatusCode(statusCode);
22-
GetItem(elapsedSeconds).Add(bytes, responsetime, trackResponseTime);
25+
26+
if (_tmpElapsedSeconds != elapsedSeconds)
27+
{
28+
_tmpSeconds = GetCurrentSecond(elapsedSeconds);
29+
_tmpElapsedSeconds = elapsedSeconds;
30+
}
31+
32+
_tmpSeconds.Add(bytes, responseTime, trackResponseTime);
2333
}
2434

25-
public void AddError(int elapsedSeconds, float responsetime, int statusCode, bool trackResponseTime, Exception exception = null)
35+
public void AddError(int elapsedSeconds, float responseTime, int statusCode, bool trackResponseTime, Exception exception = null)
2636
{
2737
AddOrUpdateStatusCode(statusCode);
28-
GetItem(elapsedSeconds).AddError(responsetime, trackResponseTime);
38+
GetCurrentSecond(elapsedSeconds).AddError(responseTime, trackResponseTime);
2939

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

51-
private Second GetItem(int elapsedSeconds)
61+
private Second GetCurrentSecond(int elapsedSeconds)
5262
{
5363
if (Seconds.ContainsKey(elapsedSeconds))
5464
{

Netling.Core/Netling.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.0</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
</PropertyGroup>
66

77
</Project>

0 commit comments

Comments
 (0)