2

Using the code from this answer - Async two-way communication with Windows Named Pipes (.Net) - I'm finding the maximum number of connections/clients at any one time is 10.

In the crude example below (this uses multiple threads - same thing happens if multiple processes are used) clients 1 to 10 will start and run as normal. However clients 11 and 12 will block when 'ProcessData' is called, eventually throwing a TimeoutException.

    public static void Start()
    {
        // Start Server
        new Thread(new ThreadStart(Server.MainRun)).Start();

        // Start Clients
        for (int i = 1; i <= 12; i++)
        {
            Thread.Sleep(500);
            Client c = new Client(i.ToString());
            new Thread(new ThreadStart(c.Run)).Start();
        }
    }

    // Create a contract that can be used as a callback
    public interface IMyCallbackService
    {
        [OperationContract(IsOneWay = true)]
        void NotifyClient();
    }

    // Define your service contract and specify the callback contract
    [ServiceContract(CallbackContract = typeof(IMyCallbackService))]
    public interface ISimpleService
    {
        [OperationContract]
        string ProcessData();
    }

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class SimpleService : ISimpleService
    {
        public string ProcessData()
        {
            // Get a handle to the call back channel
            var callback = OperationContext.Current.GetCallbackChannel<IMyCallbackService>();

            callback.NotifyClient();
            return DateTime.Now.ToString();
        }
    }

    class Server
    {
        public static void MainRun()
        {
            // Create a service host with an named pipe endpoint
            using (var host = new ServiceHost(typeof(SimpleService), new Uri("net.pipe://localhost")))
            {
                host.AddServiceEndpoint(typeof(ISimpleService), new NetNamedPipeBinding(), "SimpleService");
                host.Open();

                Console.WriteLine("Simple Service Running...");
                Console.ReadLine();

                host.Close();
            }
        }
    }

    class Client : IMyCallbackService
    {
        string _id;

        public Client(string ID)
        {
            _id = ID;
        }

        public void Run()
        {
            Console.WriteLine("Starting client : " + _id);
            // Consume the service
            var factory = new DuplexChannelFactory<ISimpleService>(new InstanceContext(this), new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/SimpleService"));
            var proxy = factory.CreateChannel();

            Console.WriteLine(proxy.ProcessData());

            Console.WriteLine("Client finished : " + _id);
        }

        public void NotifyClient()
        {
            Console.WriteLine("Notification from Server");
        }
    }

If the client closes the channel when done (factory.Close()) then all clients will be able to run.

I understand this question - Number of Clients that can connect to a Named Pipe - is very similar but suggests there is no low limit.

This suggests the limit is 10 on Windows XP and 2000 machines - http://msdn.microsoft.com/en-us/library/system.io.pipes.namedpipeclientstream.aspx - except this is happening on a Windows 8 machine and Windows 2008 server.

Is there a way to change this limit? Am I missing something obvious?

stop-cran
  • 4,229
  • 2
  • 30
  • 47
MJF
  • 605
  • 5
  • 18

2 Answers2

2

Google brought me here a year after this question was asked. I figure I may as well post to help anyone else who ends up here. I think I know why the limit of 10.

Are you aware of the NetNamedPipeBinding.MaxConnections property?

Gets or sets the maximum number of connections, both inbound and outbound, that are allowed to endpoints configured with the named pipe binding. ... The maximum number of named pipe connections that are allowed with this binding. The default value is 10.

guest
  • 21
  • 2
0

"guest" is correct and an old blog post from MSDN corroborates this as still being applicable in current .net releases.

It also suggests that the default setting was defined for use with development environments and "small" deployments.

From the other settings (eg, the buffer size) I'd suggest that >8kb per connection overhead would be expected.

I have not yet found any information on what issues may arise if the value is tuned for larger values (eg, >1000): the API appears tuned for shorter, burstier requests and I suspect for large values it may simply be inefficient (not so much for memory but just internal implementation) -

I'd welcome evidence either way on performance/issues (or success) with significant numbers of clients attaching to an endpoint.

simon coleman
  • 349
  • 2
  • 5