我们的应用服务器体系结构被设置,这样每个服务调用都经过一个自定义构建的WCF服务路由器--一个使用嵌入在请求消息头中的信息将传入的请求分配给适当服务的单个服务。
我们在使用这个WCF服务路由器时遇到了性能问题(对并发用户进行负载测试时超时)。我们想知道这是因为路由器中的一个bug,我们配置的服务/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 : IServiceRouterProcessMessage操作:
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)
{
// ...
}
}
}
}发布于 2012-01-04 10:43:39
不应该期望WCF服务会给您带来如此大的瓶颈,但当我们不知道WCF服务的确切功能,也不知道如何配置WCF服务时,很难给出确切的答案,但正如您所说的:
没有路由,我们可以在获得超时错误之前处理大约120个并发用户,尽管我们得到超时,IIS仍然在处理请求。使用路由器,IIS将停止处理大约20个并发用户的请求,并且不会在整个负载测试的其余部分恢复处理任何请求。
我认为您已经回答了您自己关于WCF服务引起问题的问题。显然,您需要检查它是如何配置、运行的,以及它对“路由”做了什么。
编辑
请看一下这里中可能影响WCF性能的一些问题。
发布于 2012-02-09 12:58:11
看起来我们的问题在于IIS上的应用程序池,因为路由服务和它所路由到的服务使用的是相同的应用程序池,因此发生了以下情况: IIS为发送到路由器服务的请求创建了线程。路由服务向路由到IIS创建新线程的服务发出请求,直到没有更多的线程可用,以及等待IIS处理其请求的所有路由服务请求的所有线程,即IIS陷入僵局。
https://stackoverflow.com/questions/8725247
复制相似问题