Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WCF可靠消息传递:MaxPendingChannel增加后的口吃服务_Wcf_.net 4.0_Ws Reliablemessaging - Fatal编程技术网

WCF可靠消息传递:MaxPendingChannel增加后的口吃服务

WCF可靠消息传递:MaxPendingChannel增加后的口吃服务,wcf,.net-4.0,ws-reliablemessaging,Wcf,.net 4.0,Ws Reliablemessaging,我们有一个问题,即在负载测试期间,如果我们在我们的一个服务上快速地发出呼叫,我们就会得到错误 “System.ServiceModel.ServerTooBusyException:RM Destination.Server的net拒绝了创建可靠会话的请求。tcp://localhost:10511/ParameterMonitorService'太忙,无法处理此请求。请稍后再试。无法打开频道。“ 我们将maxPendingChannels的值从默认值4增加到128,然后再增加到128,错误已经

我们有一个问题,即在负载测试期间,如果我们在我们的一个服务上快速地发出呼叫,我们就会得到错误

“System.ServiceModel.ServerTooBusyException:RM Destination.Server的net拒绝了创建可靠会话的请求。tcp://localhost:10511/ParameterMonitorService'太忙,无法处理此请求。请稍后再试。无法打开频道。“

我们将maxPendingChannels的值从默认值4增加到128,然后再增加到128,错误已经消失,但是现在,服务不会抛出异常,而是停止处理负载下的消息,然后在几分钟后再次开始

它似乎没有掉任何东西,只是挂了一会儿。我们对这项服务的投入越大,复苏似乎需要的时间就越长

该服务按调用配置,具有多个并发模式。其他行为设置包括:

<serviceThrottling maxConcurrentCalls="100" maxConcurrentSessions="100" maxConcurrentInstances="100"/>

<customBinding>

    <binding name="Services_Custom_Binding" openTimeout="00:00:20" sendTimeout="00:01:00">          
        <reliableSession  ordered="true" inactivityTimeout="00:10:00" maxPendingChannels="128" flowControlEnabled="true" />
        <binaryMessageEncoding>
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />            
        </binaryMessageEncoding>
        <tcpTransport maxPendingConnections="100" listenBacklog="100" />          
      </binding>
  </customBinding>


我们有点困了。感谢您的帮助

这是一个经典的性能调整故事。通过在可靠会话上重新配置节流阀,您已经消除了系统中过去的瓶颈,并将瓶颈转移到了系统中的其他地方

你真的不能指望人们凭空诊断出瓶颈在哪里,而不知道你的服务是如何托管的,在什么硬件上,它在做什么,或者它是如何进行的。您需要使用Windows性能监视器计数器尽可能全面地检测系统,并解释这些计数器,以了解系统中资源争用的位置


我的第一个猜测是,删除会话限制后并发性的增加会导致托管线程池线程的争用,但这只是一个猜测——实际上,您希望根据证据进行诊断,而不是猜测

默认情况下,线程池创建8个线程,然后每秒只添加两个线程。当你同时启动一堆工人时,WCF会停止,因为线程启动不够快

这是一个非常适合我的解决方案,无论何时启动大量线程,都可以调用AdjustThreads:

    Imports NLog
    Public Module AdjustThreads_

    Private _Logger As Logger = LogManager.GetCurrentClassLogger
    Private _MaxWorkers As Integer = 16
    Private _MaxCompletions As Integer = 16
    Public Sub AdjustThreads()
        Dim minworkerthreads As Integer = 0
        Dim maxworkerthreads As Integer = 0
        Dim mincompletionthreads As Integer = 0
        Dim maxcompletionthreads As Integer = 0
        Dim activeworkerthreads As Integer = 0
        Dim activecompletionthreads As Integer = 0
        Threading.ThreadPool.GetMinThreads(minworkerthreads, mincompletionthreads)
        Threading.ThreadPool.GetMaxThreads(maxworkerthreads, maxcompletionthreads)
        Threading.ThreadPool.GetAvailableThreads(activeworkerthreads, activecompletionthreads)
        Dim workers As Integer = maxworkerthreads - activeworkerthreads
        Dim completions As Integer = maxcompletionthreads - activecompletionthreads
        If workers > _MaxWorkers Then
            _MaxWorkers = _MaxWorkers
        End If
        If completions > _MaxCompletions Then
            _MaxCompletions = completions
        End If
        ' If current is (initially) 8, new threads only start twice a second.
        ' So, kick off a minimum of 16 and always increase by 50%
        Dim needworkers As Integer = _MaxWorkers * 3 \ 2
        Dim needcompletions As Integer = _MaxCompletions * 3 \ 2

        If needworkers > minworkerthreads OrElse
           needcompletions > mincompletionthreads Then
            _Logger.Info("Threadpool increasing workers to {0}, completions to {1}",
                         needworkers, needcompletions)
            Threading.ThreadPool.SetMinThreads(needworkers, needcompletions)
        End If
    End Sub
End Module

(该死的编辑器总是让“终端模块”从代码中消失,如果有人能修复它的话?

这个问题在我们的任何环境中都是可以重复的,包括在本地开发人员的笔记本电脑上运行或在VMware上运行的服务器环境。甚至当可靠消息被关闭时也会发生这种情况:我们没有得到可靠消息错误,而是得到了更一般的netTCP套接字错误。我们现在正在查看perfmon,但还没有什么明显的问题。请使用新错误的详细信息更新您的问题(您以前没有提到),并澄清它何时出错以及何时以您最初描述的方式“暂时挂起”。此外,还提供了服务功能的详细信息(例如,它是否执行IO;调用其他服务或数据库;使用COM互操作等)。