Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ramp up feature to load test client #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 57 additions & 2 deletions Netling.ConsoleClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ static void Main(string[] args)
var threads = 1;
var duration = 10;
int? count = null;
int rampUps = 1;

var p = new OptionSet()
{
{"t|threads=", (int v) => threads = v},
{"d|duration=", (int v) => duration = v},
{"c|count=", (int? v) => count = v}
{"c|count=", (int? v) => count = v},
{"r|rampups=", (int v) => rampUps= v}
};

var extraArgs = p.Parse(args);
Expand All @@ -40,6 +42,10 @@ static void Main(string[] args)
{
RunWithCount(uri, count.Value).Wait();
}
else if (rampUps > 1)
{
RunWithRampingUp(uri, threads, TimeSpan.FromSeconds(duration), rampUps).Wait();
}
else if (url != null)
{
RunWithDuration(uri, threads, TimeSpan.FromSeconds(duration)).Wait();
Expand Down Expand Up @@ -67,7 +73,53 @@ private static Task RunWithDuration(Uri uri, int threads, TimeSpan duration)
return Run(uri, threads, duration, null);
}

private static async Task Run(Uri uri, int threads, TimeSpan duration, int? count)
private static async Task RunWithRampingUp(Uri uri, int threads, TimeSpan duration, int rampUps)
{
var bestResult = new WorkerResult("", 0, TimeSpan.MaxValue);
var notRampedUpCount = 0;

for (int iteration = 0; iteration < rampUps; iteration++)
{
Console.WriteLine(StartRunWithDurationString, duration.TotalSeconds, uri, threads);
var result = await Run(uri, threads, duration, null);
if (iteration == 0)
bestResult = result;

if (result.RequestsPerSecond >= bestResult.RequestsPerSecond && result.Errors <= bestResult.Errors)
{
bestResult = result;
threads++;
notRampedUpCount = 0;
}
else
{
notRampedUpCount++;
}

if (notRampedUpCount == 3)
{
Console.WriteLine("Unable to increase threads without reducing req/sec or increasing errors after 3 attempts - stopping test");
break;
}
}

if (rampUps > 1)
{
Console.WriteLine(ResultString,
$"Ramp Up identified the following as the best result with {threads} threads\n{bestResult.Count}",
bestResult.Elapsed.TotalSeconds,
bestResult.RequestsPerSecond,
bestResult.Bandwidth,
bestResult.Errors,
bestResult.Median,
bestResult.StdDev,
bestResult.Min,
bestResult.Max,
GetAsciiHistogram(bestResult));
}
}

private static async Task<WorkerResult> Run(Uri uri, int threads, TimeSpan duration, int? count)
{
WorkerResult result;
var worker = new Worker(new SocketWorkerJob(uri));
Expand All @@ -92,6 +144,7 @@ private static async Task Run(Uri uri, int threads, TimeSpan duration, int? coun
result.Min,
result.Max,
GetAsciiHistogram(result));
return result;
}

private static string GetAsciiHistogram(WorkerResult workerResult)
Expand Down Expand Up @@ -128,11 +181,13 @@ private static string GetAsciiHistogram(WorkerResult workerResult)
-t count Number of threads to spawn.
-d count Duration of the run in seconds.
-c count Amount of requests to send on a single thread.
-r rampups How many times to repeat the test while trying to increase the number of threads

Examples:
netling http://localhost:5000/
netling http://localhost:5000/ -t 8 -d 60
netling http://localhost:5000/ -c 3000
netling http://localhost:5000/ -t 8 -d 60 -r 10
";

private const string StartRunWithCountString = @"
Expand Down