.net WCF服务路由,瓶颈?
我们的应用服务器体系结构是这样设置的:每个服务调用都经过一个定制的WCF服务路由器——一个使用嵌入在请求消息头中的信息将传入请求分发到适当服务的单一服务 我们使用此WCF服务路由器时遇到性能问题(与并发用户进行负载测试时超时)。我们想知道这是因为路由器中的一个bug,是因为我们配置了错误的服务/IIS,还是因为这是意料之中的——通过单个服务进行的每个呼叫听起来都像是一个潜在的瓶颈 在没有路由的情况下,在出现超时错误之前,我们可以处理大约120个并发用户,尽管我们有超时,IIS仍会继续处理请求。使用路由器,IIS会停止处理大约20个并发用户的请求,并且在负载测试的其余部分中不会恢复处理任何请求 我们的主要问题是,在使用服务路由器时是否会出现这种情况,或者IIS是否能够以我们设置的方式处理这种负载.net WCF服务路由,瓶颈?,.net,wcf,iis,routing,.net,Wcf,Iis,Routing,我们的应用服务器体系结构是这样设置的:每个服务调用都经过一个定制的WCF服务路由器——一个使用嵌入在请求消息头中的信息将传入请求分发到适当服务的单一服务 我们使用此WCF服务路由器时遇到性能问题(与并发用户进行负载测试时超时)。我们想知道这是因为路由器中的一个bug,是因为我们配置了错误的服务/IIS,还是因为这是意料之中的——通过单个服务进行的每个呼叫听起来都像是一个潜在的瓶颈 在没有路由的情况下,在出现超时错误之前,我们可以处理大约120个并发用户,尽管我们有超时,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);
}
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)
{
// ...
}
}
}
}
公共消息处理消息(消息请求消息)
{
//找出下游服务的url
string serviceName=requestMessage.Headers.GetHeader(ServiceNameMessageHeader,string.Empty);
字符串url=string.Format(_destinationUrlFormat、_destinationAppName、_destinationAppVersion、serviceName);
EndpointAddress EndpointAddress=新的EndpointAddress(url);
使用(ChannelFactory工厂=新的ChannelFactory(_绑定,端点地址))
{
factory.Endpoint.Behaviors.Add(new MustUnderstandBehavior(false));
IServiceRouter代理=factory.CreateChannel();
使用(代理作为IDisposable)
{
尝试
{
IClientChannel clientChannel=代理为IClientChannel;
//调用服务
Message responseMessage=proxy.ProcessMessage(requestMessage);
返回响应消息;
}
捕获(例外情况除外)
{
// ...
}
}
}
}
不,WCF服务不应该给您带来如此大的瓶颈,但当我们不知道您的WCF服务的具体功能和配置方式时,很难给出准确的答案,但正如您所说:
没有路由,我们以前可以处理大约120个并发用户
获取超时错误,尽管我们获得超时,IIS仍保持
处理请求。通过路由器,IIS停止处理请求
大约有20个并发用户,从不恢复处理任何请求
在负载测试的其余部分
我认为您已经回答了自己关于WCF服务引起问题的问题。显然,您需要检查它是如何配置、运行的,以及它对“路由”的作用
编辑
请看一些可能影响WCF性能的问题。看起来我们的问题是IIS上的应用程序池,因为路由服务及其路由到的服务使用相同的应用程序池。发生了以下情况:IIS为发送到路由器服务的请求创建了线程。。路由服务向路由到IIS为其创建新线程的服务发出请求-工作正常,直到没有更多可用线程,以及路由服务请求等待IIS处理其请求的所有线程,即IIS死锁。服务路由器不是一个非常精确的描述。显示它的源代码,更详细地解释它是如何工作的,等等。。。这将大大提高你获得帮助的机会。我们不可能知道这个服务路由器是如何实现的,更不可能知道它为什么慢。我理解,但我们的第一步只是知道路由服务呼叫的总体思路是否是问题所在,或者是我们的具体实现有问题。我已经在上面的帖子中添加了关于实现的更多细节。您考虑过在WCF 4.0中使用吗?我在生产使用中有很好的性能体验。谢谢,我将查看内置的路由服务。是的,路由的执行方式似乎有问题。我已经发布了一个博客链接,可能会对您有所帮助。
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)
{
// ...
}
}
}
}