Skip to content

Commit

Permalink
Refactored solution into parts.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hallatore committed Jun 23, 2018
1 parent 508abf0 commit edc7470
Show file tree
Hide file tree
Showing 47 changed files with 837 additions and 1,026 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*.suo
*.user
*.sln.docstates
.vs/


# Build
Expand Down
4 changes: 2 additions & 2 deletions Netling.Client/App.config
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1"/>
</startup>
<system.net>
<connectionManagement>
<add address="*" maxconnection="1000" />
<add address="*" maxconnection="1000"/>
</connectionManagement>
</system.net>
</configuration>
28 changes: 0 additions & 28 deletions Netling.Client/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,6 @@
<ComboBoxItem>10000 runs on 1 thread</ComboBoxItem>
</ComboBox>
</StackPanel>
<StackPanel Margin="0,0,20,0">
<TextBlock Text="Pipelining" VerticalAlignment="Top" HorizontalAlignment="Left"/>
<ComboBox x:Name="Pipelining" VerticalAlignment="Top" HorizontalAlignment="Left" Width="60" Height="25" Margin="0,5,0,0">
<ComboBoxItem IsSelected="True">1</ComboBoxItem>
<ComboBoxItem>2</ComboBoxItem>
<ComboBoxItem>3</ComboBoxItem>
<ComboBoxItem>4</ComboBoxItem>
<ComboBoxItem>5</ComboBoxItem>
<ComboBoxItem>10</ComboBoxItem>
<ComboBoxItem>20</ComboBoxItem>
<ComboBoxItem>30</ComboBoxItem>
<ComboBoxItem>40</ComboBoxItem>
<ComboBoxItem>50</ComboBoxItem>
<ComboBoxItem>60</ComboBoxItem>
<ComboBoxItem>70</ComboBoxItem>
<ComboBoxItem>80</ComboBoxItem>
<ComboBoxItem>90</ComboBoxItem>
<ComboBoxItem>100</ComboBoxItem>
<ComboBoxItem>200</ComboBoxItem>
<ComboBoxItem>300</ComboBoxItem>
<ComboBoxItem>400</ComboBoxItem>
<ComboBoxItem>500</ComboBoxItem>
</ComboBox>
</StackPanel>
<StackPanel Margin="0,0,20,0">
<TextBlock Text="Thread affinity" VerticalAlignment="Top" HorizontalAlignment="Left" />
<CheckBox x:Name="ThreadAffinity" VerticalAlignment="Top" HorizontalAlignment="Left" Width="60" Margin="0,10,0,0"/>
</StackPanel>
</StackPanel>

<TextBlock Text="URL" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,61,0,0"/>
Expand Down
20 changes: 9 additions & 11 deletions Netling.Client/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Windows.Input;
using Netling.Core;
using Netling.Core.Models;
using Netling.Core.SocketWorker;

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

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

Uri uri;

if (!Uri.TryCreate(Url.Text.Trim(), UriKind.Absolute, out uri))
if (!Uri.TryCreate(Url.Text.Trim(), UriKind.Absolute, out var uri))
return;

Threads.IsEnabled = false;
Duration.IsEnabled = false;
Url.IsEnabled = false;
Pipelining.IsEnabled = false;
ThreadAffinity.IsEnabled = false;
StartButton.Content = "Cancel";
_running = true;

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

var worker = new Worker(new SocketWorkerJob(uri));

if (count.HasValue)
_task = Worker.Run(uri, count.Value, cancellationToken);
_task = worker.Run(count.Value, cancellationToken);
else
_task = Worker.Run(uri, threads, threadAffinity, pipelining, duration, cancellationToken);
_task = worker.Run(threads, duration, cancellationToken);

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

private async Task JobCompleted()
{
if (_cancellationTokenSource != null && !_cancellationTokenSource.IsCancellationRequested)
_cancellationTokenSource.Cancel();

_running = false;
Threads.IsEnabled = true;
Duration.IsEnabled = true;
Url.IsEnabled = true;
Pipelining.IsEnabled = true;
ThreadAffinity.IsEnabled = true;
StartButton.IsEnabled = false;
_cancellationTokenSource = null;

Expand Down
11 changes: 10 additions & 1 deletion Netling.Client/Netling.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Netling.Client</RootNamespace>
<AssemblyName>Netling.Client</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
Expand Down Expand Up @@ -110,6 +110,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -193,6 +194,14 @@
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Netling.Core.HttpClientWorker\Netling.Core.HttpClientWorker.csproj">
<Project>{1098eaa8-0341-44e9-8fde-d05a2a56e083}</Project>
<Name>Netling.Core.HttpClientWorker</Name>
</ProjectReference>
<ProjectReference Include="..\Netling.Core.SocketWorker\Netling.Core.SocketWorker.csproj">
<Project>{10e2f65d-8993-409a-abe5-59cc2697cb32}</Project>
<Name>Netling.Core.SocketWorker</Name>
</ProjectReference>
<ProjectReference Include="..\Netling.Core\Netling.Core.csproj">
<Project>{84ceec3f-5fcf-4ca5-a6d7-f83cf7ea0b52}</Project>
<Name>Netling.Core</Name>
Expand Down
2 changes: 1 addition & 1 deletion Netling.Client/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Netling.Client/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Netling.Client/ResultWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<client:ValueUserControl x:Name="ThreadsValueUserControl" Title="Threads" Grid.Row="0" Grid.Column="0" Margin="0,0,0,20"/>
<client:ValueUserControl x:Name="PipeliningValueUserControl" Title="Pipelining" Grid.Row="0" Grid.Column="1"/>
<client:ValueUserControl x:Name="ThreadAffinityValueUserControl" Title="Thread affinity" Grid.Row="0" Grid.Column="2"/>
<Grid Grid.Row="0" Grid.Column="3">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
Expand Down
6 changes: 0 additions & 6 deletions Netling.Client/ResultWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public async Task Load(WorkerResult workerResult)

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

RequestsValueUserControl.Value = _resultWindowItem.JobsPerSecond.ToString("#,0");
ElapsedValueUserControl.Value = $"{_resultWindowItem.ElapsedSeconds:0}";
Expand Down Expand Up @@ -94,8 +92,6 @@ private void ClearBaseline(object sender, RoutedEventArgs e)
{
_sender.ResultWindowItem = null;
ThreadsValueUserControl.BaselineValue = null;
PipeliningValueUserControl.BaselineValue = null;
ThreadAffinityValueUserControl.BaselineValue = null;

RequestsValueUserControl.BaselineValue = null;
RequestsValueUserControl.BaseLine = BaseLine.Equal;
Expand Down Expand Up @@ -125,8 +121,6 @@ private void ClearBaseline(object sender, RoutedEventArgs e)
private void LoadBaseline(ResultWindowItem baseline)
{
ThreadsValueUserControl.BaselineValue = baseline.Threads.ToString();
PipeliningValueUserControl.BaselineValue = baseline.Pipelining.ToString();
ThreadAffinityValueUserControl.BaselineValue = baseline.ThreadAffinity ? "ON" : "OFF";

RequestsValueUserControl.BaselineValue = $"{baseline.JobsPerSecond:#,0}";
RequestsValueUserControl.BaseLine = GetBaseline(_resultWindowItem.JobsPerSecond, baseline.JobsPerSecond);
Expand Down
5 changes: 0 additions & 5 deletions Netling.Client/ResultWindowItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ public static ResultWindowItem Parse(WorkerResult result)
{
return new ResultWindowItem
{
Url = result.Url,
Threads = result.Threads,
Pipelining = result.Pipelining,
ThreadAffinity = result.ThreadAffinity,

JobsPerSecond = result.RequestsPerSecond,
ElapsedSeconds = result.Elapsed.TotalSeconds,
Expand All @@ -29,8 +26,6 @@ public static ResultWindowItem Parse(WorkerResult result)
public double Bandwidth { get; set; }
public double ElapsedSeconds { get; set; }
public double JobsPerSecond { get; set; }
public bool ThreadAffinity { get; set; }
public int Pipelining { get; set; }
public int Threads { get; set; }
public string Url { get; set; }
public double Max { get; set; }
Expand Down
143 changes: 12 additions & 131 deletions Netling.ConsoleClient/Netling.ConsoleClient.csproj
Original file line number Diff line number Diff line change
@@ -1,138 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{170E12EF-4094-4B8B-93D3-4A399F81BE9D}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Netling.ConsoleClient</RootNamespace>
<AssemblyName>netling</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TieredCompilation>true</TieredCompilation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="NDesk.Options, Version=0.2.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NDesk.Options.0.2.1\lib\NDesk.Options.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>

<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.6.1 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<PackageReference Include="CommandLine.Options" Version="0.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Netling.Core\Netling.Core.csproj">
<Project>{84ceec3f-5fcf-4ca5-a6d7-f83cf7ea0b52}</Project>
<Name>Netling.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Netling.Core.HttpClientWorker\Netling.Core.HttpClientWorker.csproj" />
<ProjectReference Include="..\Netling.Core.SocketWorker\Netling.Core.SocketWorker.csproj" />
<ProjectReference Include="..\Netling.Core\Netling.Core.csproj" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

</Project>
Loading

0 comments on commit edc7470

Please sign in to comment.