请求在 WCF IIS 服务器中堆积

Requests are piling up in WCF IIS server

我们在服务中使用 BasicHttpBinding,并且我们已将并发模式设置为多个,实例上下文模式设置为单个,如下所示

 [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single,
 ConcurrencyMode =ConcurrencyMode.Multiple)]
public class Service1 : IService1

我们通过引用在控制台消费了这个服务。我们遇到了一个问题,一段时间后我们看到消息堆积在 IIS 工作进程中。

例如 -> 在 1 分钟内,它在 IIS 的工作进程中显示为只有一个线程,但一段时间后我们在 IIS 中看到多个请求?

任何人都可以在这里提供帮助,比如为什么一段时间后我们看到消息在 IIS 中排队?

下面是配置中的绑定

<binding name="BasicHttpBinding_Common" 
        closeTimeout="00:10:00" openTimeout="00:10:00" 
        receiveTimeout="00:10:00" sendTimeout="00:10:00" 
        allowCookies="false" bypassProxyOnLocal="false" 

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

Specifies the number of service instances available for handling calls that are contained in incoming messages: InstanceContextMode.Single -Only one InstanceContext object is used for all incoming calls and is not recycled subsequent to the calls. If a service object does not exist, one is created.

Specifies whether a service class supports single-threaded or multi-threaded modes of operation: ConcurrencyMode.Multiple - The service instance is multi-threaded. No synchronization guarantees are made. Because other threads can change your service object at any time, you must handle synchronization and state consistency at all times. It is your responsibility to guard your state with locks. The service implementation must be thread-safe to use this concurrency mode.

您可以尝试将 UseSynchronizationContext = false 添加到您的 ServiceBehavior。如果这没有帮助,您可以尝试将 ReleaseServiceInstanceOnTransactionComplete=truefalse 添加到您的 ServiceBehavior。如果 InstanceContextMode 为多个,我不确定您是否可以设置为 true。

由于 ConcurrencyMode.Multiple 没有做出同步保证,并且 UseSynchronizationContext 的默认值为 true,它可能会尝试处理同一线程上的所有调用,从而导致队列。

您用来调用该服务的代码也可能存在一些问题。不看我们就不知道。

为每次调用启动一个线程可能只是需要一点时间??在你的图片中,最长的请求只有 5.5 秒。 (我知道这对于一个简单的电话来说很长。)

这也可能是无知的: