Skip to content

Commit edc7470

Browse files
committed
Refactored solution into parts.
Added unit tests for socket code. Added HttpClientWorkerJob implementation. Updated WPF app to net4.7.1 Updated Console app to netcore2.1 Changed core projects to be netstandard2.0
1 parent 508abf0 commit edc7470

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+837
-1026
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*.suo
1818
*.user
1919
*.sln.docstates
20+
.vs/
2021

2122

2223
# Build

Netling.Client/App.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1"/>
55
</startup>
66
<system.net>
77
<connectionManagement>
8-
<add address="*" maxconnection="1000" />
8+
<add address="*" maxconnection="1000"/>
99
</connectionManagement>
1010
</system.net>
1111
</configuration>

Netling.Client/MainWindow.xaml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,6 @@
2424
<ComboBoxItem>10000 runs on 1 thread</ComboBoxItem>
2525
</ComboBox>
2626
</StackPanel>
27-
<StackPanel Margin="0,0,20,0">
28-
<TextBlock Text="Pipelining" VerticalAlignment="Top" HorizontalAlignment="Left"/>
29-
<ComboBox x:Name="Pipelining" VerticalAlignment="Top" HorizontalAlignment="Left" Width="60" Height="25" Margin="0,5,0,0">
30-
<ComboBoxItem IsSelected="True">1</ComboBoxItem>
31-
<ComboBoxItem>2</ComboBoxItem>
32-
<ComboBoxItem>3</ComboBoxItem>
33-
<ComboBoxItem>4</ComboBoxItem>
34-
<ComboBoxItem>5</ComboBoxItem>
35-
<ComboBoxItem>10</ComboBoxItem>
36-
<ComboBoxItem>20</ComboBoxItem>
37-
<ComboBoxItem>30</ComboBoxItem>
38-
<ComboBoxItem>40</ComboBoxItem>
39-
<ComboBoxItem>50</ComboBoxItem>
40-
<ComboBoxItem>60</ComboBoxItem>
41-
<ComboBoxItem>70</ComboBoxItem>
42-
<ComboBoxItem>80</ComboBoxItem>
43-
<ComboBoxItem>90</ComboBoxItem>
44-
<ComboBoxItem>100</ComboBoxItem>
45-
<ComboBoxItem>200</ComboBoxItem>
46-
<ComboBoxItem>300</ComboBoxItem>
47-
<ComboBoxItem>400</ComboBoxItem>
48-
<ComboBoxItem>500</ComboBoxItem>
49-
</ComboBox>
50-
</StackPanel>
51-
<StackPanel Margin="0,0,20,0">
52-
<TextBlock Text="Thread affinity" VerticalAlignment="Top" HorizontalAlignment="Left" />
53-
<CheckBox x:Name="ThreadAffinity" VerticalAlignment="Top" HorizontalAlignment="Left" Width="60" Margin="0,10,0,0"/>
54-
</StackPanel>
5527
</StackPanel>
5628

5729
<TextBlock Text="URL" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,61,0,0"/>

Netling.Client/MainWindow.xaml.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Windows.Input;
1010
using Netling.Core;
1111
using Netling.Core.Models;
12+
using Netling.Core.SocketWorker;
1213

1314
namespace Netling.Client
1415
{
@@ -55,8 +56,6 @@ private async void StartButton_Click(object sender, RoutedEventArgs e)
5556
var duration = default(TimeSpan);
5657
int? count = null;
5758
var threads = Convert.ToInt32(((KeyValuePair<int, string>)Threads.SelectionBoxItem).Key);
58-
var threadAffinity = ThreadAffinity.IsChecked.HasValue && ThreadAffinity.IsChecked.Value;
59-
var pipelining = Convert.ToInt32(Pipelining.SelectionBoxItem);
6059
var durationText = (string)((ComboBoxItem)Duration.SelectedItem).Content;
6160
StatusProgressbar.IsIndeterminate = false;
6261

@@ -107,16 +106,12 @@ private async void StartButton_Click(object sender, RoutedEventArgs e)
107106
if (string.IsNullOrWhiteSpace(Url.Text))
108107
return;
109108

110-
Uri uri;
111-
112-
if (!Uri.TryCreate(Url.Text.Trim(), UriKind.Absolute, out uri))
109+
if (!Uri.TryCreate(Url.Text.Trim(), UriKind.Absolute, out var uri))
113110
return;
114111

115112
Threads.IsEnabled = false;
116113
Duration.IsEnabled = false;
117114
Url.IsEnabled = false;
118-
Pipelining.IsEnabled = false;
119-
ThreadAffinity.IsEnabled = false;
120115
StartButton.Content = "Cancel";
121116
_running = true;
122117

@@ -126,10 +121,12 @@ private async void StartButton_Click(object sender, RoutedEventArgs e)
126121
StatusProgressbar.Value = 0;
127122
StatusProgressbar.Visibility = Visibility.Visible;
128123

124+
var worker = new Worker(new SocketWorkerJob(uri));
125+
129126
if (count.HasValue)
130-
_task = Worker.Run(uri, count.Value, cancellationToken);
127+
_task = worker.Run(count.Value, cancellationToken);
131128
else
132-
_task = Worker.Run(uri, threads, threadAffinity, pipelining, duration, cancellationToken);
129+
_task = worker.Run(threads, duration, cancellationToken);
133130

134131
_task.GetAwaiter().OnCompleted(async () =>
135132
{
@@ -172,12 +169,13 @@ private void Urls_OnKeyUp(object sender, KeyEventArgs e)
172169

173170
private async Task JobCompleted()
174171
{
172+
if (_cancellationTokenSource != null && !_cancellationTokenSource.IsCancellationRequested)
173+
_cancellationTokenSource.Cancel();
174+
175175
_running = false;
176176
Threads.IsEnabled = true;
177177
Duration.IsEnabled = true;
178178
Url.IsEnabled = true;
179-
Pipelining.IsEnabled = true;
180-
ThreadAffinity.IsEnabled = true;
181179
StartButton.IsEnabled = false;
182180
_cancellationTokenSource = null;
183181

Netling.Client/Netling.Client.csproj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>Netling.Client</RootNamespace>
1111
<AssemblyName>Netling.Client</AssemblyName>
12-
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
1515
<WarningLevel>4</WarningLevel>
@@ -110,6 +110,7 @@
110110
<Reference Include="System.Data" />
111111
<Reference Include="System.Net.Http" />
112112
<Reference Include="System.Net.Http.WebRequest" />
113+
<Reference Include="System.Numerics" />
113114
<Reference Include="System.Xml" />
114115
<Reference Include="Microsoft.CSharp" />
115116
<Reference Include="System.Core" />
@@ -193,6 +194,14 @@
193194
</None>
194195
</ItemGroup>
195196
<ItemGroup>
197+
<ProjectReference Include="..\Netling.Core.HttpClientWorker\Netling.Core.HttpClientWorker.csproj">
198+
<Project>{1098eaa8-0341-44e9-8fde-d05a2a56e083}</Project>
199+
<Name>Netling.Core.HttpClientWorker</Name>
200+
</ProjectReference>
201+
<ProjectReference Include="..\Netling.Core.SocketWorker\Netling.Core.SocketWorker.csproj">
202+
<Project>{10e2f65d-8993-409a-abe5-59cc2697cb32}</Project>
203+
<Name>Netling.Core.SocketWorker</Name>
204+
</ProjectReference>
196205
<ProjectReference Include="..\Netling.Core\Netling.Core.csproj">
197206
<Project>{84ceec3f-5fcf-4ca5-a6d7-f83cf7ea0b52}</Project>
198207
<Name>Netling.Core</Name>

Netling.Client/Properties/Resources.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Netling.Client/Properties/Settings.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Netling.Client/ResultWindow.xaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
<ColumnDefinition Width="*"/>
1818
</Grid.ColumnDefinitions>
1919
<client:ValueUserControl x:Name="ThreadsValueUserControl" Title="Threads" Grid.Row="0" Grid.Column="0" Margin="0,0,0,20"/>
20-
<client:ValueUserControl x:Name="PipeliningValueUserControl" Title="Pipelining" Grid.Row="0" Grid.Column="1"/>
21-
<client:ValueUserControl x:Name="ThreadAffinityValueUserControl" Title="Thread affinity" Grid.Row="0" Grid.Column="2"/>
2220
<Grid Grid.Row="0" Grid.Column="3">
2321
<Grid.RowDefinitions>
2422
<RowDefinition Height="Auto"/>

Netling.Client/ResultWindow.xaml.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ public async Task Load(WorkerResult workerResult)
3232

3333
Title = "Netling - " + _resultWindowItem.Url;
3434
ThreadsValueUserControl.Value = _resultWindowItem.Threads.ToString();
35-
PipeliningValueUserControl.Value = _resultWindowItem.Pipelining.ToString();
36-
ThreadAffinityValueUserControl.Value = _resultWindowItem.ThreadAffinity ? "ON" : "OFF";
3735

3836
RequestsValueUserControl.Value = _resultWindowItem.JobsPerSecond.ToString("#,0");
3937
ElapsedValueUserControl.Value = $"{_resultWindowItem.ElapsedSeconds:0}";
@@ -94,8 +92,6 @@ private void ClearBaseline(object sender, RoutedEventArgs e)
9492
{
9593
_sender.ResultWindowItem = null;
9694
ThreadsValueUserControl.BaselineValue = null;
97-
PipeliningValueUserControl.BaselineValue = null;
98-
ThreadAffinityValueUserControl.BaselineValue = null;
9995

10096
RequestsValueUserControl.BaselineValue = null;
10197
RequestsValueUserControl.BaseLine = BaseLine.Equal;
@@ -125,8 +121,6 @@ private void ClearBaseline(object sender, RoutedEventArgs e)
125121
private void LoadBaseline(ResultWindowItem baseline)
126122
{
127123
ThreadsValueUserControl.BaselineValue = baseline.Threads.ToString();
128-
PipeliningValueUserControl.BaselineValue = baseline.Pipelining.ToString();
129-
ThreadAffinityValueUserControl.BaselineValue = baseline.ThreadAffinity ? "ON" : "OFF";
130124

131125
RequestsValueUserControl.BaselineValue = $"{baseline.JobsPerSecond:#,0}";
132126
RequestsValueUserControl.BaseLine = GetBaseline(_resultWindowItem.JobsPerSecond, baseline.JobsPerSecond);

Netling.Client/ResultWindowItem.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ public static ResultWindowItem Parse(WorkerResult result)
88
{
99
return new ResultWindowItem
1010
{
11-
Url = result.Url,
1211
Threads = result.Threads,
13-
Pipelining = result.Pipelining,
14-
ThreadAffinity = result.ThreadAffinity,
1512

1613
JobsPerSecond = result.RequestsPerSecond,
1714
ElapsedSeconds = result.Elapsed.TotalSeconds,
@@ -29,8 +26,6 @@ public static ResultWindowItem Parse(WorkerResult result)
2926
public double Bandwidth { get; set; }
3027
public double ElapsedSeconds { get; set; }
3128
public double JobsPerSecond { get; set; }
32-
public bool ThreadAffinity { get; set; }
33-
public int Pipelining { get; set; }
3429
public int Threads { get; set; }
3530
public string Url { get; set; }
3631
public double Max { get; set; }

0 commit comments

Comments
 (0)