3

I have a program that run in a loop, each iteration runs in a different thread and I'm creating new process that open new service host:

ServiceHost _host = new ServiceHost(_service, new Uri("net.pipe://localhost/" + i_PipeName));
_host.AddServiceEndpoint(typeof(ICommandService), new NetNamedPipeBinding() { TransferMode = TransferMode.Buffered }, i_PipeName);
_host.Open();

from my main program I connect to the open .net pipe at the following way:

ICommandService ServiceProxy = ChannelFactory<ICommandService>.CreateChannel
(new NetNamedPipeBinding(), new EndpointAddress(@"net.pipe://localhost/" + i_PipeName" + @"/" + i_PipeName));

So my problem is that for the first 200+ proccess/iterations it working fine, I can open connection and pass messages but later on there errors that starts to appear:

There was no endpoint listening at net.pipe://localhost/pipea0360/pipea0360 that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException if present, for more details.

My question is if there are any limitations on the number of pipes I can open in parallel?
Is this because I open so many proccesses?

Dor Cohen
  • 16,769
  • 23
  • 93
  • 161
  • Did you follow the exception's advice to *See InnerException*? It may help you to determine the actual cause of the problem. Perhaps you could edit the description of the inner exception into your question. – MvanGeest Sep 13 '12 at 11:53
  • @MvanGeest the inner exception is the same as the outer one: There was no endpoint listening at net.pipe://localhost/pipea0360/pipea0360 that could accept the message. – Dor Cohen Sep 13 '12 at 12:00
  • You are creating a new thread for each _host so you are creating over 200 threads? Why? I am pretty confident the optimal number of threads is less than 200. And why over 200 _host? – paparazzo Sep 13 '12 at 13:37
  • I'm simulating multiple parallel logins – Dor Cohen Sep 13 '12 at 13:40
  • OK why over 200 threads? Why do you think this is a number of pipes problem? Did you consider it could a number threads problem? – paparazzo Sep 13 '12 at 14:49
  • Do your calls to `_host.Open()` continue to succeed when the client starts to see these errors? Or are the service hosts throwing exceptions as well? – Chris Dickson Sep 13 '12 at 15:13

1 Answers1

3

Have you ruled out a race condition, where the client is attempting to connect to a pipe that the server hasn't established yet? If you have a lot of active threads on the server, it could easily delay the thread that is supposed to start listening. That could explain why it works in the beginning.

In general, having a server thread for each client doesn't scale well; you'll get better performance with a thread pool approach.

bmm6o
  • 6,187
  • 3
  • 28
  • 55