Skip to content

Commit

Permalink
Orchestration to try out load testing for Durable Task framework
Browse files Browse the repository at this point in the history
  • Loading branch information
samarabbas committed Oct 22, 2014
1 parent d703aad commit bb0ab99
Show file tree
Hide file tree
Showing 17 changed files with 791 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Test/TaskHubStressTest/.nuget/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
136 changes: 136 additions & 0 deletions Test/TaskHubStressTest/.nuget/NuGet.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>

<!-- Enable the restore command to run before builds -->
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>

<!-- Property that enables building a package from a project -->
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>

<!-- Determines if package restore consent is required to restore packages -->
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>

<!-- Download NuGet.exe if it does not already exist -->
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
</PropertyGroup>

<ItemGroup Condition=" '$(PackageSources)' == '' ">
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
<!-- The official NuGet package source (https://www.nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
<!--
<PackageSource Include="https://www.nuget.org/api/v2/" />
<PackageSource Include="https://my-nuget-source/nuget/" />
-->
</ItemGroup>

<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
<!-- Windows specific commands -->
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
</PropertyGroup>

<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
<PackagesConfig>packages.config</PackagesConfig>
</PropertyGroup>

<PropertyGroup>
<!-- NuGet command -->
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>

<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>

<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>

<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>

<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir>
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>

<!-- Commands -->
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>

<!-- We need to ensure packages are restored prior to assembly resolve -->
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
RestorePackages;
$(BuildDependsOn);
</BuildDependsOn>

<!-- Make the build depend on restore packages -->
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
$(BuildDependsOn);
BuildPackage;
</BuildDependsOn>
</PropertyGroup>

<Target Name="CheckPrerequisites">
<!-- Raise an error if we're unable to locate nuget.exe -->
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
<!--
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
This effectively acts as a lock that makes sure that the download operation will only happen once and all
parallel builds will have to wait for it to complete.
-->
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
</Target>

<Target Name="_DownloadNuGet">
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
</Target>

<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)"
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />

<Exec Command="$(RestoreCommand)"
LogStandardErrorAsError="true"
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
</Target>

<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(BuildCommand)"
Condition=" '$(OS)' != 'Windows_NT' " />

<Exec Command="$(BuildCommand)"
LogStandardErrorAsError="true"
Condition=" '$(OS)' == 'Windows_NT' " />
</Target>

<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<OutputFilename ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Net" />
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
OutputFilename = Path.GetFullPath(OutputFilename);
Log.LogMessage("Downloading latest version of NuGet.exe...");
WebClient webClient = new WebClient();
webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename);
return true;
}
catch (Exception ex) {
Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</Task>
</UsingTask>
</Project>
33 changes: 33 additions & 0 deletions Test/TaskHubStressTest/TaskHubStressTest.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TaskHubStressTest", "TaskHubStressTest\TaskHubStressTest.csproj", "{96980359-8003-4500-B97B-949A7FE01F31}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{3EB529F2-51AE-42CE-9560-706DB5B2C178}"
ProjectSection(SolutionItems) = preProject
.nuget\NuGet.Config = .nuget\NuGet.Config
.nuget\NuGet.exe = .nuget\NuGet.exe
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Framework", "..\..\Framework\Framework.csproj", "{6F5D2EAD-726D-4FE5-A575-AEB96D1CCE37}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{96980359-8003-4500-B97B-949A7FE01F31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{96980359-8003-4500-B97B-949A7FE01F31}.Debug|Any CPU.Build.0 = Debug|Any CPU
{96980359-8003-4500-B97B-949A7FE01F31}.Release|Any CPU.ActiveCfg = Release|Any CPU
{96980359-8003-4500-B97B-949A7FE01F31}.Release|Any CPU.Build.0 = Release|Any CPU
{6F5D2EAD-726D-4FE5-A575-AEB96D1CCE37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F5D2EAD-726D-4FE5-A575-AEB96D1CCE37}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F5D2EAD-726D-4FE5-A575-AEB96D1CCE37}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F5D2EAD-726D-4FE5-A575-AEB96D1CCE37}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
61 changes: 61 additions & 0 deletions Test/TaskHubStressTest/TaskHubStressTest/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<appSettings>
<add key="StorageConnectionString" value="UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://127.0.0.1:10002/" />
<add key="TaskHubName" value="StressTestHub" />
<add key="CompressOrchestrationState" value="false"/>
<add key="MaxConcurrentActivities" value="100"/>
<add key="MaxConcurrentOrchestrations" value="100"/>
<add key="DriverOrchestrationIterations" value="20"/>
<add key="DriverOrchestrationParallelTasks" value="40"/>
<add key="ChildOrchestrationParallelTasks" value="10"/>
<add key="ChildOrchestrationSerialTasks" value="5"/>
<add key="TestTimeoutInSeconds" value="86400"/>
<add key="TestTaskMaxDelayInMinutes" value="5"/>
</appSettings>
<connectionStrings>
<!-- Service Bus connection string -->
<add name="Microsoft.ServiceBus.ConnectionString" connectionString="[Enter you connection string here]" />
</connectionStrings>
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="DurableTask" switchName="mySwitch" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<clear />
<!--add name="configConsoleListener"
type=" TaskHubStressTest.OrchestrationConsoleTraceListener, TaskHubStressTest"
traceOutputOptions="DateTime" /-->
<add name="configFileTraceListener" type=" TaskHubStressTest.OrchestrationFileTraceListener, TaskHubStressTest" initializeData="Trace.log" traceOutputOptions="DateTime" />
</listeners>
</source>
</sources>
<switches>
<add name="mySwitch" value="Verbose" />
</switches>
</system.diagnostics>

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.WindowsAzure.Storage" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.4" newVersion="2.1.0.4" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
33 changes: 33 additions & 0 deletions Test/TaskHubStressTest/TaskHubStressTest/DriverOrchestration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace TaskHubStressTest
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DurableTask;

public class DriverOrchestration : TaskOrchestration<int, DriverOrchestrationData>
{
public override async Task<int> RunTask(OrchestrationContext context, DriverOrchestrationData data)
{
int result = 0;
List<Task<int>> results = new List<Task<int>>();
int i = 0;
for (; i < data.NumberOfParallelTasks; i++)
{
results.Add(context.CreateSubOrchestrationInstance<int>(typeof(TestOrchestration), data.SubOrchestrationData));
}

int[] counters = await Task.WhenAll(results.ToArray());
result = counters.Max();

if (data.NumberOfIteration > 0)
{
data.NumberOfIteration--;
context.ContinueAsNew(data);
}

return result;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace TaskHubStressTest
{
public class DriverOrchestrationData
{
public int NumberOfParallelTasks { get; set; }
public int NumberOfIteration { get; set; }
public TestOrchestrationData SubOrchestrationData { get; set; }
}
}
40 changes: 40 additions & 0 deletions Test/TaskHubStressTest/TaskHubStressTest/Options.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace TaskHubStressTest
{
using CommandLine;
using CommandLine.Text;
using System.Text;

class Options
{
[Option('c', "create-hub", DefaultValue = false,
HelpText = "Create Orchestration Hub.")]
public bool CreateHub { get; set; }

[Option('s', "start-instance", DefaultValue = null,
HelpText = "Start Driver Instance")]
public string StartInstance { get; set; }

[Option('i', "instance-id",
HelpText = "Instance id for new orchestration instance.")]
public string InstanceId { get; set; }

[HelpOption]
public string GetUsage()
{
// this without using CommandLine.Text
// or using HelpText.AutoBuild

var help = new HelpText
{
Heading = new HeadingInfo("TaskHubStressTest", "1.0"),
AdditionalNewLineAfterOption = true,
AddDashesToOption = true
};
help.AddPreOptionsLine("Usage: TaskHubStressTest.exe -c");
help.AddPreOptionsLine("Usage: TaskHubStressTest.exe -c -s <id>");
help.AddPreOptionsLine("Usage: TaskHubStressTest.exe -i <id>");
help.AddOptions(this);
return help;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace TaskHubStressTest
{
using System;
using System.Linq;
using System.Diagnostics;

class OrchestrationConsoleTraceListener : ConsoleTraceListener
{
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
{
try
{
var dict = message.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
.Select(part => part.Split('='))
.ToDictionary(split => split[0], split => split[1]);
string iid;
if (dict.TryGetValue("iid", out iid))
{
string toWrite = string.Format("[{0} {1}] {2}", DateTime.Now, iid, dict["msg"]);
Console.WriteLine(toWrite);
Debug.WriteLine(toWrite);
}
else
{
string toWrite = string.Format("[{0}] {1}", DateTime.Now, dict["msg"]);
Console.WriteLine(toWrite);
Debug.WriteLine(toWrite);
}
}
catch (Exception exception)
{
string toWrite = string.Format("Exception while parsing trace: {0}\n\t", exception.Message, exception.StackTrace);
Console.WriteLine(toWrite);
Debug.WriteLine(toWrite);
}
}
}
}
Loading

0 comments on commit bb0ab99

Please sign in to comment.