gpt4 book ai didi

WCF 吞吐量低于预期

转载 作者:行者123 更新时间:2023-12-04 18:22:45 27 4
gpt4 key购买 nike

对于帖子的长度,我深表歉意,但有很多事情可能会导致我的情况,我已尝试将我根据其他帖子所做的所有设置更改包括在内。简而言之,我的 WCF 服务似乎一次被限制为 3 或 4 个并发客户端请求。如果我将应用程序池 Maximum Worker Processes 设置得更高(大约 10 个)或将服务行为 ConcurrencyMode 设置为 Multiple,我会获得更好的吞吐量(快几倍)。然而,这些似乎是解决实际问题的方法,带来了他们自己的问题。我错了,还是 IIS 应该能够在一个工作进程中启动我的 WCF 服务的许多实例(数十个或更多)来处理负载?我只知道我在某处缺少一个设置,但我找不到它。

编辑:到目前为止,在尝试这些建议时,我意识到我的数学与吞吐量有关。使用 ForEach 循环,我可以在 20 秒的时间内在服务器上获得估计的并发处理(每个任务持续时间 * 任务数/总运行时间)。对于正在完成的实际工作( sleep 10 秒),这似乎仍然很低,但不再低得离谱。

第二次编辑:我将@Pablo 的评论标记为答案,因为他的答案加上他的链接为我提供了显着提高性能的信息(我认为是 3 倍)。但是,我想提出后续问题-在 WCF/IIS 中处理并发请求的合理期望是什么?假设 CPU、内存和 IO 不是瓶颈,处理请求的实际限制/期望(每个 CPU)是多少?我正在寻找的是一个经验法则,它告诉我,如果不添加 CPU(或工作进程),我可能不会获得任何更大的提升。再次感谢。

(在 Windows 2008 Server 上,由 IIS 托管,1 个处理器)
WCF 服务配置(缩写):

<?xml version="1.0"?>
<configuration>
<configSections>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<services>
<service name="FMHIRWCFSvc.IRService" behaviorConfiguration="IRServiceBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="Binding1" contract="FMHIRWCFSvc.IIRService" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="Binding1" maxReceivedMessageSize="104857600">
<readerQuotas maxArrayLength="104857600"/>
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="IRServiceBehavior">
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling
maxConcurrentCalls = "500"
maxConcurrentSessions = "500"
maxConcurrentInstances = "500"
/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<applicationSettings>
<FMHIRWCFSvc.Properties.Settings>
<setting name="FMHIRWCFSvc_ir_dev_websvc_IRWebService40" serializeAs="String">
<value>http://ir-dev-websvc/imageright.webservice/IRWebService40.asmx</value>
</setting>
</FMHIRWCFSvc.Properties.Settings>
</applicationSettings>
<system.net>
<connectionManagement>
<add address="*" maxconnection="500"/>
</connectionManagement>
</system.net>
</configuration>

客户端配置(缩写):
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IIRService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://{myserveraddress}/FMHIRWCFSvc/IRService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IIRService"
contract="wcf_local.IIRService" name="BasicHttpBinding_IIRService" />
</client>
</system.serviceModel>
<system.net>
<connectionManagement>
<add address="*" maxconnection="500"/>
</connectionManagement>
</system.net>
</configuration>

客户端方法调用:
static void WCFTesting()
{
ConcurrentQueue<Exception> exceptionList = new ConcurrentQueue<Exception>();
int[] taskList = new int[250];
Parallel.ForEach(taskList, theTask =>
{
try
{
// Create the WCF client
BasicHttpBinding binding = new BasicHttpBinding {
Security = { Mode = BasicHttpSecurityMode.Transport },
SendTimeout = TimeSpan.FromSeconds(20)
};
EndpointAddress endpointAddress = new EndpointAddress("https://{myserveraddress}/FMHIRWCFSvc/IRService.svc");
IRServiceClient wcfClient = new IRServiceClient(binding, endpointAddress);

// Call wcf service method that sleeps 10 seconds and returns
wcfClient.TestCall();
}
catch (Exception exception) {
// Store off exceptions for later processing
exceptionList.Enqueue(exception);
}
});
}

WCF 服务代码:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
...
public string TestCall()
{
Thread.Sleep(10000);
return null;
}

感谢您的任何见解或建议!

最佳答案

您使用的测试机制可能并不完全正确。

使用 Parallel.For()并不意味着它将并行创建 250 个工作人员。在这种情况下,您似乎将基准测试限制在最适合您的客户端处理器配置的范围内,而不是实际测试服务器可以处理的内容。

如果您真的想调用 250 个并行线程并查看它的 react ,您可以手动创建所有线程。如:

        var exceptionList = new ConcurrentQueue<Exception>();
const int max = 250;
int numberOfTasks = max;
var signal = new ManualResetEvent(false);
for (var i = 0; i < max; i++)
{
var thread = new Thread(() =>
{
try
{
// Create the WCF client
BasicHttpBinding binding = new BasicHttpBinding
{
Security = { Mode = BasicHttpSecurityMode.Transport },
SendTimeout = TimeSpan.FromSeconds(20)
};
EndpointAddress endpointAddress = new EndpointAddress("https://{myserveraddress}/FMHIRWCFSvc/IRService.svc");
IRServiceClient wcfClient = new IRServiceClient(binding, endpointAddress);

// Call wcf service method that sleeps 10 seconds and returns
wcfClient.TestCall();
}
catch (Exception exception)
{
// Store off exceptions for later processing
exceptionList.Enqueue(exception);
}

if (Interlocked.Decrement(ref numberOfTasks) == 0) signal.Set();
});
thread.Start();
}
signal.WaitOne();

关于WCF 吞吐量低于预期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11456076/

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