WCF服务的路由,瓶颈?路由、瓶颈、WCF

2023-09-03 22:19:15 作者:泪水中成长@

我们的应用服务器体系结构设置,使每一个服务调用经历了一个定制的WCF服务路由器 - 传入的请求分发到使用嵌入在请求的邮件头信息的适当服务的单个服务

我们正经历着用这个WCF服务路由器的性能问题(超时当负载测试并发用户)。我们不知道这是因为在路由器中的一个错误,我们配置的服务/ IIS错误,或者如果它是可以预料的 - 每次调用会通过一个单一的服务听起来像一个潜在的瓶颈。

没有路由,我们可以处理大约120个并发用户收到超时错误之前,虽然我们得到超时的IIS一直处理请求。与路由器的IIS将停止处理请求大约20个并发用户,从来没有恢复处理整个负载测试的其他任何请求。

让网速没有瓶颈 企业级路由器腾达W15E体验分享

我们的主要问题是,如果这是可以预料的使用服务路由器还是应该在IIS能够处理这种负荷我们已经在路上,当它安装?

路由服务是这样的:

  ///<总结>
///它可以接受任何WCF消息,通用的服务合同。
///< /总结>
[的ServiceContract]
公共接口IServiceRouter
{
    [OperationContract的(行动=*,ReplyAction =*,AsyncPattern = FALSE)]
    消息ProcessMessage的(消息requestMessage);
}
 

执行:

  [ServiceBehavior(
    InstanceContextMode = InstanceContextMode.PerCall,
    ConcurrencyMode = ConcurrencyMode.Multiple,
    AddressFilterMode = AddressFilterMode.Any,
    ValidateMustUnderstand = FALSE)]
公共密封类ServiceRouter:IServiceRouter
 

在ProcessMessage的操作:

 公共信息ProcessMessage的(消息requestMessage)
    {
        //找出下游服务的URL
        字符串的服务名= requestMessage.Headers.GetHeader<字符串>(ServiceNameMessageHeader,的String.Empty);
        字符串URL =的String.Format(_destinationUrlFormat,_destinationAppName,_destinationAppVersion,服务名);
        的EndpointAddress的EndpointAddress =新的EndpointAddress(URL);

        使用(的ChannelFactory< IServiceRouter>厂=新的ChannelFactory< IServiceRouter>(_结合,的EndpointAddress))
        {
            factory.Endpoint.Behaviors.Add(新MustUnderstandBehavior(假));
            IServiceRouter代理= factory.CreateChannel();

            使用(代理为IDisposable接口)
            {
                尝试
                {
                    IClientChannel clientChannel =代理为IClientChannel;

                    //调用服务
                    消息responseMessage = proxy.ProcessMessage(requestMessage);

                    返回responseMessage;
                }
                赶上(例外前)
                {
                    // ...
                }
            }
        }
    }
 

解决方案

没有一个WCF服务,不应期望给你造成这么重大的瓶颈,但它是很难给出一个确切的答案的时候,我们不知道到底你的WCF服务呢,还是它的配置,但正如你所说的:

  

不选路,我们可以前处理大约120个并发用户   得到超时错误,虽然我们得到超时的IIS保持   处理请求。与路由器的IIS将停止处理请求   大约20个并发用户,从来没有恢复处理任何请求   整个负载测试的剩余部分。

我觉得你就WCF服务造成的问题回答了你自己的问题。你显然需要检查它的配置,运行和它做什么的路由。

修改的

看一看此处在可能会影响WCF性能的一些问题。

Our application server architecture is setup so that every service call goes through a custom built WCF service router - a single service that distributes the incoming requests to an appropriate service using information embedded in the message header of requests.

We are experiencing performance problems using this WCF service router (timeouts when load-testing with concurrent users). We wonder if this is because of a bug in the router, that we configured the services/IIS wrong or if it is to be expected - every call going through a single service sounds like a potential bottle-neck.

Without routing we can handle about 120 concurrent users before getting timeout errors and although we get timeouts the IIS keeps handling requests. With the router the IIS stops handling requests with about 20 concurrent users and never resumes handling any requests throughout the rest of the load-testing.

Our main question is if this is to be expected when using a service router or should the IIS be able to handle this load the way we have it setup?

The routing service looks like this:

/// <summary>
/// Generic service contract which can accept any WCF message.
/// </summary>
[ServiceContract]
public interface IServiceRouter
{
    [OperationContract(Action = "*", ReplyAction = "*", AsyncPattern=false)]
    Message ProcessMessage(Message requestMessage);
}

The implementation:

[ServiceBehavior( 
    InstanceContextMode = InstanceContextMode.PerCall,
    ConcurrencyMode = ConcurrencyMode.Multiple,
    AddressFilterMode = AddressFilterMode.Any, 
    ValidateMustUnderstand = false)]
public sealed class ServiceRouter : IServiceRouter

The ProcessMessage operation:

    public Message ProcessMessage(Message requestMessage)
    {            
        //Figure out the url of the downstream service             
        string serviceName = requestMessage.Headers.GetHeader<String>(ServiceNameMessageHeader, String.Empty);
        string url = String.Format(_destinationUrlFormat, _destinationAppName, _destinationAppVersion, serviceName);
        EndpointAddress endpointAddress = new EndpointAddress(url);

        using (ChannelFactory<IServiceRouter> factory = new ChannelFactory<IServiceRouter>(_binding, endpointAddress))
        {
            factory.Endpoint.Behaviors.Add(new MustUnderstandBehavior(false));
            IServiceRouter proxy = factory.CreateChannel();

            using (proxy as IDisposable)
            {
                try
                {
                    IClientChannel clientChannel = proxy as IClientChannel;

                    // invoke service
                    Message responseMessage = proxy.ProcessMessage(requestMessage);

                    return responseMessage;
                }
                catch (Exception ex)
                {
                    // ...
                }
            }
        }
    }

解决方案

No a WCF service shouldn't be expected to cause you such a major bottle neck, but it's difficult to give an exact answer when we don't know exactly what your WCF service does, nor how it is configured, but as you said:

Without routing we can handle about 120 concurrent users before getting timeout errors and although we get timeouts the IIS keeps handling requests. With the router the IIS stops handling requests with about 20 concurrent users and never resumes handling any requests throughout the rest of the load-testing.

I think that you've answered your own question with regard to the WCF service causing problems. You'll obviously need to check how it is configured, run and what it does with the "routing".

edit

Have a look here at some issues that can affect WCF performance.