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

Run server GC OOP with reduced process priority #51405

Merged
2 commits merged into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.ComponentModel;
using System.Diagnostics;

namespace Microsoft.CodeAnalysis.Remote
{
internal static class ProcessExtensions
{
private static bool s_settingPrioritySupported = true;

public static bool TrySetPriorityClass(this Process process, ProcessPriorityClass priorityClass)
{
if (!s_settingPrioritySupported)
{
return false;
}

try
{
process.PriorityClass = priorityClass;
return true;
}
catch (Exception e) when (e is PlatformNotSupportedException or Win32Exception)
{
// the runtime does not support changing process priority
s_settingPrioritySupported = false;

return false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -51,6 +52,14 @@ internal partial class RemoteHostService : ServiceBase, IRemoteHostService, IAss

static RemoteHostService()
{
if (GCSettings.IsServerGC)
{
// Server GC runs processor-affinitized threads with high priority. To avoid interfering with other
// applications while still allowing efficient out-of-process execution, slightly reduce the process
// priority when using server GC.
Process.GetCurrentProcess().TrySetPriorityClass(ProcessPriorityClass.BelowNormal);
}

// this is the very first service which will be called from client (VS)
// we set up logger here
RoslynLogger.SetLogger(new EtwLogger(s_logChecker));
Expand Down