What is the purpose of maxNumberOfServerInstances in the NamedPipeServerStream class?

I am currently writing a Windows service in .NET, and I am using named pipes so that other processes communicate with my service. In more complex NamedPipeServerStream constructors, there is a parameter with a descriptive name maxNumberOfServerInstances. Awesome. But what does this mean?

The MSDN documentation is also helpful in explaining:

The maximum number of server instances that have the same name.

Good. This still does not tell me what it means to me, or how I use it. It would be prudent if NamedPipeServerStream would also accept the delegate for “running this code when receiving the connection,” so each “server instance” then ran that code. But this is not so.

+4
source share
1 answer

This is an odd argument, you will find a little more information about this in the documentation for the basic Windows API function (CreateNamedPipe) . Pipes use a very valuable resource for pipe buffers, they are allocated from the kernel memory pool without loading. I think this argument helps Windows optimize pool usage. Exactly how this is done is hopelessly undocumented.

The ideal number for a single service that accepts multiple client connections is 1. You would only increase it if you want to run several services that do the same job. This is pretty rare.

+2
source

Source: https://habr.com/ru/post/1390435/


All Articles