Skip to content

Commit

Permalink
release 2.0.2 - added tweaks to help Linux with thread management
Browse files Browse the repository at this point in the history
  • Loading branch information
iizotov committed Nov 21, 2018
1 parent 7ebf06d commit 1e99966
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Payload options:

Example:
```bash
wget https://github.com/iizotov/azure-sb-loadgenerator-dotnetcore/releases/download/2.0.1/azure-sb-loadgenerator-dotnetcore.tar.gz
wget https://github.com/iizotov/azure-sb-loadgenerator-dotnetcore/releases/download/2.0.2/azure-sb-loadgenerator-dotnetcore.tar.gz
tar -xvzf azure-sb-loadgenerator-dotnetcore.tar.gz
cd ./azure-sb-loadgenerator-dotnetcore/
dotnet loadgenerator.dll <parameters>
Expand Down
24 changes: 9 additions & 15 deletions loadgenerator/OrchestratorClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private void SetThrottler()
double controlInterval = 1.0; // seconds

// how many invokations per second are allowed
double invocationsPerControlInterval = (double)(this.targetThroughput * overheadCompensator) / (double)this.batchSize * controlInterval ;
double invocationsPerControlInterval = (double)(this.targetThroughput * overheadCompensator) / (double)this.batchSize * controlInterval;

double clampBelowInterval = controlInterval / invocationsPerControlInterval * 1000.0;

Expand Down Expand Up @@ -94,14 +94,15 @@ public string GetStatusSnapshot()
// Kicks off the main loop
public void Start()
{
CancellationToken cancellationToken = this.cancellationTokenSource.Token;
Task task = new Task(
() => this._Start()
);
() => this._Start(cancellationToken)
, cancellationToken);
task.Start();
}

// The main loop
private void _Start()
private void _Start(CancellationToken cancellationToken)
{
// ensure only one instance is running
if (this.isRunning)
Expand Down Expand Up @@ -131,24 +132,22 @@ private void _Start()

if (this.targetThroughput <= 0) // unconstrained
{
task = this.loadGeneratee.GenerateBatchAndSend(this.batchSize, this.dryRun, this.cancellationTokenSource.Token, this.DataGenerator);
task = this.loadGeneratee.GenerateBatchAndSend(this.batchSize, this.dryRun, cancellationToken, this.DataGenerator);
}
else
{

task = this.throttler.Perform(() =>
{
this.loadGeneratee.GenerateBatchAndSend(this.batchSize, this.dryRun, this.cancellationTokenSource.Token, this.DataGenerator);
this.loadGeneratee.GenerateBatchAndSend(this.batchSize, this.dryRun, cancellationToken, this.DataGenerator);
});
}

task.ContinueWith((taskResult) =>
{
Int64 total = Interlocked.Add(ref this.totalMessageCount, this.batchSize);

}, TaskContinuationOptions.OnlyOnRanToCompletion);

if (this.cancellationTokenSource.IsCancellationRequested)
if (cancellationToken.IsCancellationRequested)
{
break;
}
Expand All @@ -160,18 +159,13 @@ private void _Start()
this.isRunning = false;
this.isJobDone = true;
this.statisticsTimer.Stop();
cancellationToken.ThrowIfCancellationRequested();
}
}
public void Stop()
{
this.cancellationTokenSource.Cancel();
}

public void Restart()
{
this.Stop();
this.Start();
}
}

}
14 changes: 13 additions & 1 deletion loadgenerator/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using CommandLine;
using System.Threading;

namespace LoadGeneratorDotnetCore
{
Expand Down Expand Up @@ -77,6 +78,7 @@ public static int Main(string[] args)
{
if (DateTime.Now >= terminationDT)
{
loadOrchestrator.Stop();
String dt = DateTime.UtcNow.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff");
Console.WriteLine($"[{dt}], terminating after {executionOptions.TerminateAfter} seconds...");
break;
Expand All @@ -95,7 +97,7 @@ public static int Main(string[] args)
switch (ch)
{
case ConsoleKey.Escape:
Console.WriteLine("Exiting...");
Console.WriteLine($"[{dt}] Exiting...");
loadOrchestrator.Stop();
break;

Expand All @@ -105,6 +107,8 @@ public static int Main(string[] args)

loadOrchestrator.Stop();
loadOrchestrator = null;
GC.Collect();

func = () => { return loadGeneratee.GeneratePayload(executionOptions.GenerateJson, executionOptions.MessageSize); };
loadOrchestrator = new OrchestratorClass(
loadGeneratee, executionOptions.TargetThroughput, executionOptions.MessagesToSend,
Expand All @@ -120,6 +124,8 @@ public static int Main(string[] args)

loadOrchestrator.Stop();
loadOrchestrator = null;
GC.Collect();

func = () => { return loadGeneratee.GeneratePayload(executionOptions.GenerateJson, executionOptions.MessageSize); };
loadOrchestrator = new OrchestratorClass(
loadGeneratee, executionOptions.TargetThroughput, executionOptions.MessagesToSend,
Expand All @@ -133,6 +139,8 @@ public static int Main(string[] args)

loadOrchestrator.Stop();
loadOrchestrator = null;
GC.Collect();

func = () => { return loadGeneratee.GeneratePayload(executionOptions.GenerateJson, executionOptions.MessageSize); };
loadOrchestrator = new OrchestratorClass(
loadGeneratee, executionOptions.TargetThroughput, executionOptions.MessagesToSend,
Expand All @@ -147,6 +155,8 @@ public static int Main(string[] args)

loadOrchestrator.Stop();
loadOrchestrator = null;
GC.Collect();

func = () => { return loadGeneratee.GeneratePayload(executionOptions.GenerateJson, executionOptions.MessageSize); };
loadOrchestrator = new OrchestratorClass(
loadGeneratee, executionOptions.TargetThroughput, executionOptions.MessagesToSend,
Expand All @@ -155,6 +165,7 @@ public static int Main(string[] args)
break;
}
}
Thread.Sleep(300);
// sit and relax
} while (true);
}
Expand All @@ -171,6 +182,7 @@ public static int Main(string[] args)
{
telemetryTimer.Stop();
}
GC.Collect();
Console.WriteLine();
Console.WriteLine($"Execution completed, exit code {exitCode}");
}
Expand Down

0 comments on commit 1e99966

Please sign in to comment.