mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
add a flag to make message processing parallel (#1482)
* add a flag to make message processing parallel * use discard * add comment
This commit is contained in:
@@ -57,6 +57,12 @@ namespace Microsoft.SqlTools.Hosting.Protocol
|
|||||||
protected MessageWriter MessageWriter { get; private set; }
|
protected MessageWriter MessageWriter { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the message should be handled without blocking the main thread.
|
||||||
|
/// </summary>
|
||||||
|
public bool ParallelMessageProcessing { get; set; }
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
@@ -304,10 +310,28 @@ namespace Microsoft.SqlTools.Hosting.Protocol
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
if (handlerToAwait != null)
|
if (handlerToAwait != null)
|
||||||
|
{
|
||||||
|
if (this.ParallelMessageProcessing)
|
||||||
|
{
|
||||||
|
// Run the task in a separate thread so that the main
|
||||||
|
// thread is not blocked.
|
||||||
|
_ = Task.Run(() =>
|
||||||
|
{
|
||||||
|
_ = RunTask(handlerToAwait);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await RunTask(handlerToAwait);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task RunTask(Task task)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await handlerToAwait;
|
await task;
|
||||||
}
|
}
|
||||||
catch (TaskCanceledException)
|
catch (TaskCanceledException)
|
||||||
{
|
{
|
||||||
@@ -323,7 +347,6 @@ namespace Microsoft.SqlTools.Hosting.Protocol
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
internal void OnListenTaskCompleted(Task listenTask)
|
internal void OnListenTaskCompleted(Task listenTask)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace Microsoft.SqlTools.Hosting.Protocol
|
|||||||
/// handlers for requests, responses, and events that are
|
/// handlers for requests, responses, and events that are
|
||||||
/// transmitted through the channel.
|
/// transmitted through the channel.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected MessageDispatcher MessageDispatcher { get; set; }
|
internal MessageDispatcher MessageDispatcher { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes an instance of the protocol server using the
|
/// Initializes an instance of the protocol server using the
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ namespace Microsoft.SqlTools.Hosting.Utility
|
|||||||
case "-service-name":
|
case "-service-name":
|
||||||
ServiceName = args[++i];
|
ServiceName = args[++i];
|
||||||
break;
|
break;
|
||||||
|
case "-parallel-message-processing":
|
||||||
|
ParallelMessageProcessing = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
ErrorMessage += string.Format("Unknown argument \"{0}\"" + Environment.NewLine, argName);
|
ErrorMessage += string.Format("Unknown argument \"{0}\"" + Environment.NewLine, argName);
|
||||||
break;
|
break;
|
||||||
@@ -131,6 +134,12 @@ namespace Microsoft.SqlTools.Hosting.Utility
|
|||||||
|
|
||||||
public bool AutoFlushLog { get; private set; } = false;
|
public bool AutoFlushLog { get; private set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A temporary flag to decide whether the message handling should block the main thread.
|
||||||
|
/// Eventually we will fix the issues and make this the default behavior.
|
||||||
|
/// </summary>
|
||||||
|
public bool ParallelMessageProcessing { get; private set; } = false;
|
||||||
|
|
||||||
public virtual void SetLocale(string locale)
|
public virtual void SetLocale(string locale)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ namespace Microsoft.SqlTools.ServiceLayer
|
|||||||
|
|
||||||
SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails);
|
SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails);
|
||||||
ServiceHost serviceHost = HostLoader.CreateAndStartServiceHost(sqlToolsContext);
|
ServiceHost serviceHost = HostLoader.CreateAndStartServiceHost(sqlToolsContext);
|
||||||
|
serviceHost.MessageDispatcher.ParallelMessageProcessing = commandOptions.ParallelMessageProcessing;
|
||||||
|
|
||||||
// If this service was started by another process, then it should shutdown when that parent process does.
|
// If this service was started by another process, then it should shutdown when that parent process does.
|
||||||
if (commandOptions.ParentProcessId != null)
|
if (commandOptions.ParentProcessId != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user