-
Notifications
You must be signed in to change notification settings - Fork 51
allow fifo task execution #49
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ namespace GrpcDotNetNamedPipes; | |
| public class NamedPipeServer : IDisposable | ||
| { | ||
| private readonly ServerStreamPool _pool; | ||
| private readonly TaskFactory _taskFactory; | ||
| private readonly Action<string> _log; | ||
| private readonly Dictionary<string, Func<ServerConnectionContext, Task>> _methodHandlers = new(); | ||
|
|
||
|
|
@@ -32,11 +33,12 @@ public NamedPipeServer(string pipeName, NamedPipeServerOptions options) | |
| { | ||
| } | ||
|
|
||
| internal NamedPipeServer(string pipeName, NamedPipeServerOptions options, Action<string> log) | ||
| public NamedPipeServer(string pipeName, NamedPipeServerOptions options, Action<string> log) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should still be internal |
||
| { | ||
| _pool = new ServerStreamPool(pipeName, options, HandleConnection, InvokeError); | ||
| _log = log; | ||
| ServiceBinder = new ServiceBinderImpl(this); | ||
| _taskFactory = options.TaskFactory ?? new TaskFactory(); | ||
| } | ||
|
|
||
| public ServiceBinderBase ServiceBinder { get; } | ||
|
|
@@ -66,7 +68,7 @@ public void Dispose() | |
| private async Task HandleConnection(NamedPipeServerStream pipeStream) | ||
| { | ||
| var logger = ConnectionLogger.Server(_log); | ||
| var ctx = new ServerConnectionContext(pipeStream, logger, _methodHandlers); | ||
| var ctx = new ServerConnectionContext(pipeStream, logger, _methodHandlers, _taskFactory); | ||
| await Task.Run(new PipeReader(pipeStream, ctx, logger, ctx.Dispose, InvokeError).ReadLoop); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,4 +31,17 @@ public class NamedPipeServerOptions | |
| /// </summary> | ||
| public PipeSecurity PipeSecurity { get; set; } | ||
| #endif | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a Custom Task Factory to control how tasks are serviced. | ||
| /// For example, causing threads to be processsed in FIFO rather than LIFO | ||
| /// by using TaskCreationOptions.preferFairness | ||
| /// </summary> | ||
| public TaskFactory TaskFactory { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a count of threads to use for the listener. | ||
| /// If you need to address a synchronous code execution issue, try increasing | ||
| /// </summary> | ||
| public int ThreadPoolSize { get; set; } = 4; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure this helps? In general the listener thread pool is sitting idle and whenever a connection is established, immediately hands off to a task on a different thread and goes back to idling. You shouldn't need a ton of threads to be able to handle that. If there is a problem it's presumably in high-contention scenarios where clients have trouble connecting, but in that scenario I would rather make improvements to client connection reliability that work out of the box rather than adding a knob that needs to be tuned. |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave package version updates out of this PR unless they're needed for some reason