gpt4 book ai didi

c# - 当应用程序创建大量 WCF 连接器类时,与服务器的所有连接都会超时

转载 作者:太空宇宙 更新时间:2023-11-03 11:09:39 24 4
gpt4 key购买 nike

我有一个 WCF net.tcp 服务器,它使用两种方法公开服务:

string Get(location);
void Put(location);

maxConnections 设置为 int.MaxValue。在客户端,maxConnections 设置为 800。服务器上没有引发异常

我有一个客户端应用程序,它有时会创建 100 多个线程,每个线程都可能随时连接到服务器。

当线程共享连接器类时,应用程序可以正常工作。当我让每个线程创建它自己的连接器时,当我使用 20-30 个线程时,每个线程都可以正常工作。但是当应用程序创建 50 多个线程时,所有连接突然开始超时。

System.TimeoutException: The open operation did not complete within the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout. ---> System.TimeoutException: The socket transfer timed out after 00:01:00. You have exceeded the timeou
t set on your binding. The time allotted to this operation may have been a portion of a longer timeout. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected
host has failed to respond
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
--- End of inner exception stack trace ---
at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
at System.ServiceModel.Channels.SocketConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
at System.ServiceModel.Channels.DelegatingConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper& timeoutHelper)
at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper& timeoutHelper)
at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)
at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
--- End of inner exception stack trace ---

Server stack trace:
at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at MySource.Get(String account)
at MyService.Get(String account) in d:\Users\menkaur\Documents\Expression\Blend 4\Projects\Service References\MySourceService\Reference.cs:line 99
at auto_liker_bot.Program.<>c__DisplayClass58.<>c__DisplayClass60.<Main>b__4c(IMySource _mySource) in d:\Users\menkaur\Documents\Expression\Blend 4\Projects\my-project\Program.cs:line 473
at auto_liker_bot.Program.PerformAction(UInt64 threadId, IMySource& mySource, Action`1 action) in d:\Users\menkaur\Documents\Expression\Blend 4\Projects\my-project\Program.cs:line 919

这不是我第一次注意到 WCF 类发生类似情况。

这是 WCF 的硬性限制,还是有我可以更改的设置来摆脱这种行为?

最佳答案

您遇到的是客户端到主机的连接数限制。它不是由 WCF 设置的,但 WCF 也不能幸免。您将需要增加它。查看:

默认情况下,基本上您只有 2 个连接到同一主机。随着线程数量的增加,连接请求增加并排队,但由于只有 2 个可用,在某些时候您开始超时。

关于c# - 当应用程序创建大量 WCF 连接器类时,与服务器的所有连接都会超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14537457/

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