gpt4 book ai didi

.net - WCF服务路由,瓶颈?

转载 作者:行者123 更新时间:2023-12-03 03:17:42 28 4
gpt4 key购买 nike

我们的应用程序服务器架构经过设置,以便每个服务调用都经过自定义构建的 WCF 服务路由器 - 这是一个使用请求消息 header 中嵌入的信息将传入请求分发到适当服务的服务。

我们在使用此 WCF 服务路由器时遇到性能问题(对并发用户进行负载测试时超时)。我们想知道这是否是由于路由器中的错误、我们错误地配置了服务/IIS,或者是否是预期的情况 - 每个通过单个服务的调用听起来都像是一个潜在的瓶颈。

如果没有路由,我们可以在出现超时错误之前处理大约 120 个并发用户,尽管出现超时,但 IIS 仍会继续处理请求。使用路由器,IIS 将停止处理大约 20 个并发用户的请求,并且在负载测试的其余部分中永远不会恢复处理任何请求。

我们的主要问题是,在使用服务路由器时是否会出现这种情况,或者 IIS 是否能够按照我们设置的方式处理此负载?

<小时/>

路由服务如下所示:

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

实现:

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

ProcessMessage 操作:

    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)
{
// ...
}
}
}
}

最佳答案

不,不应期望 WCF 服务会给您带来如此大的瓶颈,但是当我们不确切知道您的 WCF 服务的作用或配置方式时,很难给出准确的答案,但作为你说:

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.

我认为您已经回答了有关 WCF 服务导致问题的问题。显然,您需要检查它的配置、运行方式以及它对“路由”的作用。

编辑

看看here一些可能影响 WCF 性能的问题。

关于.net - WCF服务路由,瓶颈?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8725247/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com