Configure WCF Service for Multiple Client Calls

I made a WCF service, which is defined as follows:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)] 

binding is done using netTcpBinding.

We support 50+ clients that call the server from time to time. Each client opens a channel using channelelfactory after downloading it, and uses this channel for all calls (creates a channel and proxy only once).

we created a small load tester that simulates a client by invoking a server on 50 different threads at the same time (using 50 different channels). when we run this tester, after the 10th client tries to connect, all other clients will not be able to connect. We set throttling to 100.

My questions:

  • Is it right for each client to create a channel and use it through the client's lifetime? or I need to use the using statement for each server call (create and delete a new channel for each call).
  • Does the service have a restriction on channel connections to it? others then throttle?
+4
source share
2 answers

The number of simultaneous connections to the server is controlled by both the WCF service throttling mode and your machine (this is the OS, really). Windows XP machines had a hard limit of 10 concurrent connections - maybe a problem? If you are running a server, this restriction should not apply.

service throttling behavior also has a default value of MaxConcurrentSessions , which is 10, and your netTcpBinding connections will have a session transport layer, so there is definitely a problem too.

You can change the settings of the service throttling behavior in the application configuration file:

  <serviceBehaviors> <behavior name="TcpMoreThan10"> <serviceThrottling maxConcurrentCalls="100" maxConcurrentSessions="50" maxConcurrentInstances="50" /> </behavior> </serviceBehaviors> 

and you will need to add this service behavior to the <service> , of course, to enable it:

 <service name="....." behaviorConfiguration="TcpMoreThan10"> .... </service> 

If you only have up to 50 clients calling sporadically, and they are all "internal" clients using netTcpBinding, I see no good reason why you want to make this thing multi-threaded singleton, really.

As a side note: multi-threaded singletones are not so difficult to write, it is difficult to get everything right, you need to worry about concurrent access to your internal variables, etc. - pretty dirty programming.

Why not use the default instance mode for each call? Wherein:

  • each request that is part of its own, separate, isolated, just created instance of a service class
  • each instance of the service class only processes exactly one caller, so there is no need for messy and complex multi-threaded programming models.
+4
source

Have you checked the CAL limit on your server?

It’s usually a good practice to clean up if you aren’t using something, so I stick to using the operator.

0
source

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


All Articles