netTcpBinding 怎么会比 wsHttpBinding 慢呢?
我已经实现了一个场景,使用 netTcpBinding 和 WsHttpBinding 以及传输安全(https)作为 WCF 中的通信绑定类型。然后我比较了性能结果。有趣的是,netTcpBinding 比 wsHttpBinding 慢。我阅读了很多有关绑定性能的文档,并且我知道 netTcpBinding 由于二进制编码而提供了最快的通信。
您能解释一下在我的测试中可能导致这种情况的原因是什么吗?谢谢。
测试环境:IIS 7
public static WSHttpBinding GetWSHttpForSSLBinding()
{
WSHttpBinding binding = new WSHttpBinding();
binding.TransactionFlow = true;
binding.MaxReceivedMessageSize = 2147483647;
binding.MessageEncoding = WSMessageEncoding.Text;
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.ReaderQuotas.MaxStringContentLength = 2147483647;
binding.OpenTimeout = TimeSpan.MaxValue;
binding.CloseTimeout = TimeSpan.MaxValue;
binding.SendTimeout = TimeSpan.MaxValue;
binding.ReceiveTimeout = TimeSpan.MaxValue;
return binding;
}
public static NetTcpBinding GetTcpBinding()
{
NetTcpBinding binding = new NetTcpBinding();
binding.TransactionFlow = true;
binding.MaxReceivedMessageSize = 2147483647;
binding.PortSharingEnabled = true;
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
binding.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign;
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
binding.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.TripleDesSha256;
binding.ReaderQuotas.MaxStringContentLength = 2147483647;
binding.ReaderQuotas.MaxArrayLength = 2147483647;
binding.OpenTimeout = TimeSpan.MaxValue;
binding.CloseTimeout = TimeSpan.MaxValue;
binding.SendTimeout = TimeSpan.MaxValue;
binding.ReceiveTimeout = TimeSpan.MaxValue;
return binding;
}
I have implemented a scenario which uses netTcpBinding and WsHttpBinding with Transport Security(https) as communication binding type in WCF. Then I compared the performance results. Interestingly, netTcpBinding was slower than wsHttpBinding. I have read a a lot of documents about binding performance and I know that the netTcpBinding provides the fastest communication because of binary encoding.
Can you explain what may cause this situation in my tests? Thanks.
Test environment: IIS 7
public static WSHttpBinding GetWSHttpForSSLBinding()
{
WSHttpBinding binding = new WSHttpBinding();
binding.TransactionFlow = true;
binding.MaxReceivedMessageSize = 2147483647;
binding.MessageEncoding = WSMessageEncoding.Text;
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.ReaderQuotas.MaxStringContentLength = 2147483647;
binding.OpenTimeout = TimeSpan.MaxValue;
binding.CloseTimeout = TimeSpan.MaxValue;
binding.SendTimeout = TimeSpan.MaxValue;
binding.ReceiveTimeout = TimeSpan.MaxValue;
return binding;
}
public static NetTcpBinding GetTcpBinding()
{
NetTcpBinding binding = new NetTcpBinding();
binding.TransactionFlow = true;
binding.MaxReceivedMessageSize = 2147483647;
binding.PortSharingEnabled = true;
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
binding.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign;
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
binding.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.TripleDesSha256;
binding.ReaderQuotas.MaxStringContentLength = 2147483647;
binding.ReaderQuotas.MaxArrayLength = 2147483647;
binding.OpenTimeout = TimeSpan.MaxValue;
binding.CloseTimeout = TimeSpan.MaxValue;
binding.SendTimeout = TimeSpan.MaxValue;
binding.ReceiveTimeout = TimeSpan.MaxValue;
return binding;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 net.tcp 绑定使用身份验证,但 ws http 绑定不使用身份验证。还可以使用来自单个代理的多个操作调用和更大的消息负载来重复您的测试。由于通道创建和连接建立,第一次调用总是很慢。
Your net.tcp binding uses authentication but ws http binding doesn't. Alse repeat your test with several operation calls from single proxy and with bigger message load. First call is always slow because of channel creation and connection establishment.
你说的是延迟还是吞吐量。客户端是否创建连接然后立即关闭它,或者是否跨越多个调用。
NetTcp 对相同的连接进行了优化,并且有效负载大小会更小,因为它对 wshttp 使用 BinaryEncoding 与 TextEncoding。
如果您正在查看延迟 - NetTcp 执行 Windows 身份验证会导致 AD 查找,而在 wshttp 上则使用 SSL 身份验证。
Are you talking about latency or throughput. Does a client create a connection and then immediately close it or does it span over multiple calls.
NetTcp has optimization over a same connection and payload size would be smaller since it uses BinaryEncoding vs TextEncoding for wshttp.
If you are looking at latency - NetTcp does windows auth with causes an AD lookup vs on wshttp you are using SSL auth.