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

[Perf] Add ThreadPool options #20372

Merged
merged 6 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions common/Perf/Azure.Test.Perf/PerfOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ public class PerfOptions
[Option('l', "latency", HelpText = "Track and print per-operation latency statistics")]
public bool Latency { get; set; }

[Option("max-completion-port-threads", HelpText = "The maximum number of asynchronous I/O threads that the thread pool creates on demand")]
public int? MaxCompletionPortThreads { get; set; }
mikeharder marked this conversation as resolved.
Show resolved Hide resolved

[Option("max-worker-threads", HelpText = "The maximum number of worker threads that the thread pool creates on demand")]
public int? MaxWorkerThreads { get; set; }

[Option("min-completion-port-threads", HelpText = "The minimum number of asynchronous I/O threads that the thread pool creates on demand")]
public int? MinCompletionPortThreads { get; set; }

[Option("min-worker-threads", HelpText = "The minimum number of worker threads that the thread pool creates on demand")]
public int? MinWorkerThreads { get; set; }

[Option("no-cleanup", HelpText = "Disables test cleanup")]
public bool NoCleanup { get; set; }

Expand Down
46 changes: 46 additions & 0 deletions common/Perf/Azure.Test.Perf/PerfProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ private static async Task Run(Type testType, PerfOptions options)
}));
Console.WriteLine();

ConfigureThreadPool(options);

PrintEnvironment();

using var setupStatusCts = new CancellationTokenSource();
var setupStatusThread = PerfStressUtilities.PrintStatus("=== Setup ===", () => ".", newLine: false, setupStatusCts.Token);

Expand Down Expand Up @@ -174,6 +178,48 @@ private static async Task Run(Type testType, PerfOptions options)
PrintAssemblyVersions(testType);
}

private static void ConfigureThreadPool(PerfOptions options)
{
if (options.MinWorkerThreads.HasValue || options.MinCompletionPortThreads.HasValue)
{
ThreadPool.GetMinThreads(out var minWorkerThreads, out var minCompletionPortThreads);
ThreadPool.SetMinThreads(options.MinWorkerThreads ?? minWorkerThreads,
mikeharder marked this conversation as resolved.
Show resolved Hide resolved
options.MinCompletionPortThreads ?? minCompletionPortThreads);
}

if (options.MaxWorkerThreads.HasValue || options.MaxCompletionPortThreads.HasValue)
{
ThreadPool.GetMaxThreads(out var maxWorkerThreads, out var maxCompletionPortThreads);
ThreadPool.SetMaxThreads(options.MaxWorkerThreads ?? maxWorkerThreads,
options.MaxCompletionPortThreads ?? maxCompletionPortThreads);
}
}

private static void PrintEnvironment()
{
Console.WriteLine("=== Environment ===");

Console.Write("Configuration: ");
#if DEBUG
Console.WriteLine("Debug");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to print the same for referenced assemblies.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pakrym: Print what for the referenced assemblies? We already print the versions:

Console.WriteLine($"{name}:");
Console.WriteLine($" Referenced: {referencedVersion}");
Console.WriteLine($" Loaded: {loadedVersion}");
Console.WriteLine($" Informational: {informationalVersion}");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configuration (DEBUG/RELEASE).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I determine this for a reference assembly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[assembly: AssemblyConfiguration("Debug")] attribute is set on DEBUG assemblies, at least the ones we produce in azure-sdk-for-net.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] but we need to parse it's argument and see if it contains DebuggableAttribute.DebuggingModes.DisableOptimizations

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pakrym: Added in this commit: 078402a. Open to more feedback on naming, etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! thank you

#elif RELEASE
Console.WriteLine("Release");
#endif

Console.WriteLine($"GCSettings.IsServerGC: {GCSettings.IsServerGC}");

Console.WriteLine($"Environment.ProcessorCount: {Environment.ProcessorCount}");
mikeharder marked this conversation as resolved.
Show resolved Hide resolved

ThreadPool.GetMinThreads(out var minWorkerThreads, out var minCompletionPortThreads);
ThreadPool.GetMaxThreads(out var maxWorkerThreads, out var maxCompletionPortThreads);
Console.WriteLine($"ThreadPool.MinWorkerThreads: {minWorkerThreads}");
Console.WriteLine($"ThreadPool.MinCompletionPortThreads: {minCompletionPortThreads}");
Console.WriteLine($"ThreadPool.MaxWorkerThreads: {maxWorkerThreads}");
Console.WriteLine($"ThreadPool.MaxCompletionPortThreads: {maxCompletionPortThreads}");

Console.WriteLine();
}

private static void PrintAssemblyVersions(Type testType)
{
Console.WriteLine("=== Versions ===");
Expand Down