8000 Experimental feature: Implicit remoting batching perf improvement by PaulHigin · Pull Request #8038 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Experimental feature: Implicit remoting batching perf improvement #8038

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

Merged
merged 11 commits into from
Oct 30, 2018
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,7 @@ private void GenerateSectionSeparator(TextWriter writer)

PrivateData = @{{
ImplicitRemoting = $true
ImplicitSessionId = '{4}'
}}
}}
";
Expand All @@ -2003,7 +2004,8 @@ private void GenerateManifest(TextWriter writer, string psm1fileName, string for
CodeGeneration.EscapeSingleQuotedStringContent(_moduleGuid.ToString()),
CodeGeneration.EscapeSingleQuotedStringContent(StringUtil.Format(ImplicitRemotingStrings.ProxyModuleDescription, this.GetConnectionString())),
CodeGeneration.EscapeSingleQuotedStringContent(Path.GetFileName(psm1fileName)),
CodeGeneration.EscapeSingleQuotedStringContent(Path.GetFileName(formatPs1xmlFileName)));
CodeGeneration.EscapeSingleQuotedStringContent(Path.GetFileName(formatPs1xmlFileName)),
this._remoteRunspaceInfo.InstanceId);
}

#endregion
Expand Down
18 changes: 18 additions & 0 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Management.Automation.Language;

using Dbg = System.Management.Automation.Diagnostics;

Expand Down Expand Up @@ -320,6 +322,22 @@ internal Collection<PSObject> ExecuteCommand(string command, out Exception excep
{
Dbg.Assert(!String.IsNullOrEmpty(command), "command should have a value");

// Experimental:
// Check for implicit remoting commands that can be batched, and execute as batched if able.
if (ExperimentalFeature.IsEnabled("PSImplicitRemotingBatching"))
{
var addOutputter = ((options & ExecutionOptions.AddOutputter) > 0);
if (addOutputter &&
!_parent.RunspaceRef.IsRunspaceOverridden &&
_parent.RunspaceRef.Runspace.ExecutionContext.Modules != null &&
_parent.RunspaceRef.Runspace.ExecutionContext.Modules.IsImplicitRemotingModuleLoaded &&
Utils.TryRunAsImplicitBatch(command, _parent.RunspaceRef.Runspace))
{
exceptionThrown = null;
return null;
}
}

Pipeline tempPipeline = CreatePipeline(command, (options & ExecutionOptions.AddToHistory) > 0);

return ExecuteCommandHelper(tempPipeline, out exceptionThrown, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ static ExperimentalFeature()
source: EngineSource,
isEnabled: false),
*/
new ExperimentalFeature(name: "PSImplicitRemotingBatching",
description: "Batch implicit remoting proxy commands to improve performance",
source: EngineSource,
isEnabled: false)
};
EngineExperimentalFeatures = new ReadOnlyCollection<ExperimentalFeature>(engineFeatures);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5034,6 +5034,21 @@ internal void RemoveModule(PSModuleInfo module, string moduleNameInRemoveModuleC

// And the appdomain level module path cache.
PSModuleInfo.RemoveFromAppDomainLevelCache(module.Name);

// Update implicit module loaded property
if (Context.Modules.IsImplicitRemotingModuleLoaded)
{
Context.Modules.IsImplicitRemotingModuleLoaded = false;
foreach (var modInfo in Context.Modules.ModuleTable.Values)
{
var privateData = modInfo.PrivateData as Hashtable;
if ((privateData != null) && privateData.ContainsKey("ImplicitRemoting"))
{
Context.Modules.IsImplicitRemotingModuleLoaded = true;
break;
}
}
}
}
}
}
Expand Down Expand Up @@ -6883,6 +6898,13 @@ internal static void AddModuleToModuleTables(ExecutionContext context, SessionSt
{
targetSessionState.Module.AddNestedModule(module);
}

var privateDataHashTable = module.PrivateData as Hashtable;
if (context.Modules.IsImplicitRemotingModuleLoaded == false &&
privateDataHashTable != null && privateDataHashTable.ContainsKey("ImplicitRemoting"))
{
context.Modules.IsImplicitRemotingModuleLoaded = true;
}
}

/// <summary>
Expand Down