通过可靠的会话,WCF服务运行速度非常慢

时间:2015-05-19 09:31:12

标签: c# wcf tcp

服务器托管在WPF应用程序上,并使用net.tcp绑定进行双工通道。我们有客户端(.NET 4.0)向服务器发送一串异步请求。在可靠的会话开启后,服务变得非常慢(大约50-100个呼叫/秒),并且回叫消息不会发送到客户端。

问题发生在两种情况下。

  1. 我们发送约。每秒1000条消息到服务器。如果我们发送300-500条消息就行了。

  2. 我们向服务器发送一条大小为10-20 MB的邮件。在这种情况下,来自服务器回调的消息将一直等到大消息发送。

  3. 以下是服务器和客户端的代码。

    服务器绑定:

    (另外我们尝试使用标准的net.tcp绑定而不是自定义但没有帮助)

    var customBinding= new CustomBinding()
                        {
                            CloseTimeout = new TimeSpan(0, 1, 10),
                            OpenTimeout = new TimeSpan(0, 1, 10),
                            ReceiveTimeout = new TimeSpan(0, 5, 30),
                            SendTimeout = new TimeSpan(0, 2, 0)
                        };
                           customBinding.Elements.Add(new BinaryMessageEncodingBindingElement()
                             {
                                 MessageVersion = MessageVersion.Default,
                                 ReaderQuotas =
                                 {
                                     MaxBytesPerRead = int.MaxValue,
                                     MaxDepth = int.MaxValue,
                                     MaxNameTableCharCount = int.MaxValue,
                                     MaxStringContentLength = int.MaxValue,
                                     MaxArrayLength = int.MaxValue
                                 }
                             });
                           customBinding.Elements.Add(new ReliableSessionBindingElement()
                                {
                                    AcknowledgementInterval = TimeSpan.FromMilliseconds(1),
                                    FlowControlEnabled = true,
                                    InactivityTimeout = new TimeSpan(0, 30, 0),
                                    MaxPendingChannels = 1000,
                                    MaxRetryCount = 10,
                                    MaxTransferWindowSize = 4096,
                                    Ordered = true,
                                    ReliableMessagingVersion = ReliableMessagingVersion.Default
                                });
            var tcpTransport = new TcpTransportBindingElement()
                           {
                               ChannelInitializationTimeout = TimeSpan.FromSeconds(30),
                               ConnectionBufferSize =8192,
                               ListenBacklog = 10000000,
                               MaxBufferPoolSize = int.MaxValue,
                               MaxBufferSize = int.MaxValue,
                               MaxOutputDelay= TimeSpan.FromMilliseconds(1000),
                               MaxPendingAccepts = int.MaxValue,
                               MaxPendingConnections = 40000,
                               MaxReceivedMessageSize = int.MaxValue,
                               PortSharingEnabled = true,
                               TransferMode = TransferMode.Buffered,
                           };
                           tcpTransport.ConnectionPoolSettings.GroupName = "OnlineList";
                           tcpTransport.ConnectionPoolSettings.IdleTimeout = TimeSpan.FromMinutes(5);
                           tcpTransport.ConnectionPoolSettings.LeaseTimeout = TimeSpan.FromMinutes(5);
                           tcpTransport.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint = 40000;
                           customBinding.Elements.Add(tcpTransport);
    

    客户端配置:

    BaseTimeout = 7000;
            int.MaxValue = 2147483647;
            ///Common
                    CloseTimeout = new TimeSpan(0, 0, BaseTimeout),
                    OpenTimeout = new TimeSpan(0, 0, BaseTimeout),
                    ReceiveTimeout = new TimeSpan(0, 0, BaseTimeout*4),
                   SendTimeout = new TimeSpan(0, 0, BaseTimeout),
                    ///Security
                    Security = { Mode = SecurityMode.None },
                    ///Session
                    ReliableSession =
                    {
                        Enabled = true,
                        InactivityTimeout = new TimeSpan(1, 10, 0),
                        Ordered = true
                    },
                    ///Buffer and message
                    MaxBufferPoolSize = int.MaxValue,
                    MaxBufferSize = int.MaxValue,
                    MaxReceivedMessageSize = int.MaxValue,
                    ///ReaderQuotas
                    ReaderQuotas =
                    {
                        MaxBytesPerRead = int.MaxValue,
                        MaxDepth = int.MaxValue,
                        MaxNameTableCharCount = int.MaxValue,
                        MaxStringContentLength = int.MaxValue,
                        MaxArrayLength = int.MaxValue
                    },
                    //Other
                    PortSharingEnabled = true,
                    MaxConnections = 1000,
                    TransactionFlow = true,
                    TransferMode = TransferMode.Buffered,
    

0 个答案:

没有答案