如何创建高效的 Http,Wcf 网络通信
2012-02-01 15:23
183 查看
用HttpWebRequest去Call别的Service,怎样才能提高并发量和性能?
因为建立一个TCP连接要三次握手,.Net 默认使用 keepAlive = Ture 去重用连接,避免重建Connection的开销,还有一些设置我们也要注意:
DefaultConnectionLimit
description: Maximum number of concurrent connections to a single ServicePoint
default: 2
suggested: 12*N, N is the number of CPU
MaxServicePointIdleTime
description: Maximum idle time of ServicePoint object, but in the testing, i found it's the maximum idle time of the TCP connection in connection pool, http://msdn.microsoft.com/en-US/library/system.net.servicepointmanager.maxservicepointidletime.aspx
default: 100000ms
suggested: 3600000ms, 1 hour, set a long time to keep the connection, avoid creating connection every call.
ConnectionLeaseTimeout
description: A Int32 that specifies the number of milliseconds that an active ServicePoint connection remains open. The default is -1, which allows an active ServicePoint connection to stay connected indefinitely. Set this property to 0 to force ServicePoint connections to close after servicing a request.
default: -1
suggested: -1
MaxServicePoints
description: Maximum number of concurrent ServicePoint objects
default: 0, means no limited.
suggested: 0
TcpKeepAliveTimeInMillis
description: after idle more than n ms, a keepalive tcp package will be send by client, to verify the connection is still available or not.
default: 7200000ms, 2 hours
suggested: 10000ms, 10s, recyle the bad connections in time, reduce the burden of the server.
TcpKeepAliveIntervalInMillis
description: between when successive keep-alive packets are sent if no acknowledgement is received, until received a response, if 5 packages were sent, and no any response, this connection will be drop, http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.settcpkeepalive.aspx
default: 1000ms
suggested: 1000ms
ServicePointManager.Expect100Continue = false;
ServicePointManager.UseNagleAlgorithm = false;
MaxWorkerThreads 100
MaxIOThreads 100
MaxConnection 12*N
MinfreeThreads 88*N
MinLocalRequestfreeThreads 88*N
MinWorkerThreds 50 (MaxWorkerThreads/2)
参考资料:
http://support.microsoft.com/kb/821268 http://social.msdn.microsoft.com/Forums/en-US/windowsazuredata/thread/d84ba34b-b0e0-4961-a167-bbe7618beb83 http://blogs.msdn.com/b/jpsanders/archive/2009/05/20/understanding-maxservicepointidletime-and-defaultconnectionlimit.aspx http://blogs.msdn.com/b/adarshk/archive/2005/01/02/345411.aspx
因为建立一个TCP连接要三次握手,.Net 默认使用 keepAlive = Ture 去重用连接,避免重建Connection的开销,还有一些设置我们也要注意:
DefaultConnectionLimit
description: Maximum number of concurrent connections to a single ServicePoint
default: 2
suggested: 12*N, N is the number of CPU
MaxServicePointIdleTime
description: Maximum idle time of ServicePoint object, but in the testing, i found it's the maximum idle time of the TCP connection in connection pool, http://msdn.microsoft.com/en-US/library/system.net.servicepointmanager.maxservicepointidletime.aspx
default: 100000ms
suggested: 3600000ms, 1 hour, set a long time to keep the connection, avoid creating connection every call.
ConnectionLeaseTimeout
description: A Int32 that specifies the number of milliseconds that an active ServicePoint connection remains open. The default is -1, which allows an active ServicePoint connection to stay connected indefinitely. Set this property to 0 to force ServicePoint connections to close after servicing a request.
default: -1
suggested: -1
MaxServicePoints
description: Maximum number of concurrent ServicePoint objects
default: 0, means no limited.
suggested: 0
TcpKeepAliveTimeInMillis
description: after idle more than n ms, a keepalive tcp package will be send by client, to verify the connection is still available or not.
default: 7200000ms, 2 hours
suggested: 10000ms, 10s, recyle the bad connections in time, reduce the burden of the server.
TcpKeepAliveIntervalInMillis
description: between when successive keep-alive packets are sent if no acknowledgement is received, until received a response, if 5 packages were sent, and no any response, this connection will be drop, http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.settcpkeepalive.aspx
default: 1000ms
suggested: 1000ms
ServicePointManager.Expect100Continue = false;
ServicePointManager.UseNagleAlgorithm = false;
MaxWorkerThreads 100
MaxIOThreads 100
MaxConnection 12*N
MinfreeThreads 88*N
MinLocalRequestfreeThreads 88*N
MinWorkerThreds 50 (MaxWorkerThreads/2)
参考资料:
http://support.microsoft.com/kb/821268 http://social.msdn.microsoft.com/Forums/en-US/windowsazuredata/thread/d84ba34b-b0e0-4961-a167-bbe7618beb83 http://blogs.msdn.com/b/jpsanders/archive/2009/05/20/understanding-maxservicepointidletime-and-defaultconnectionlimit.aspx http://blogs.msdn.com/b/adarshk/archive/2005/01/02/345411.aspx
相关文章推荐
- android HttpClient网络通信工具类基于XML
- C++网络编程 如何使用SOCKET 发送HTTP1.1 GET POST请求包
- 如何创建和使用XMLHttpRequest对象?
- Android网络编程之Http通信
- 如何在Android开发中高效使用Volley网络框架
- 手机客户端和服务器通信时如何安全高效的进行身份验证
- Android HttpClient(Get,Post方式)进行网络通信
- Android网络编程之Http通信
- 聊聊如何设计千万级吞吐量的.Net Core网络通信!
- Http进行网络通信
- WCF后续之旅(1): WCF是如何通过Binding进行通信的
- 《Android开发卷——HTTP网络通信,HTTP网络连接》
- 网络层、传输层、应用层、端口通信协议编程接口 - http,socket,tcp/ip 网络传输与通讯知识总结
- android 网络通信 方案1 httpclient
- Android网络编程之Http通信
- OL 2000: 如何以编程方式创建一个窗体 http://support.microsoft.com/kb/238755/zh-cn
- 不能启动 Easy Config时如何创建一个新的网络服务
- wcf入门教程之在.net471中创建一个使用tcp网络协议的wcf windows服务进程
- VS2010 创建WCF以及SL的客户端如何调用WCF服务 教程(二): 创建调用WCF的SilverLight客户端