开发者

HttpWebRequest introduces significant latency when the Expect100Continue header is disabled

开发者 https://www.devze.com 2023-03-10 06:20 出处:网络
On disabling the Expect100Continue header for HttpWebRequests coming out of my WCF hosted client, by adding the following to the settings section of the config file:

On disabling the Expect100Continue header for HttpWebRequests coming out of my WCF hosted client, by adding the following to the settings section of the config file:

ServicePointManager.Expect100Continue=false 

I noticed that the client waits for about 开发者_如何学C150 milliseconds between sending the HTTP POST Request and the following TCP packet that contains the actual payload.

Any Clue why this could be happening? It is unexpected because on disabling this header I'm expecting the payload to be sent immediately after the initial request with no latency.


So it turns out that .NET by default uses the Naggle Algorithm to group chunked payload for TCP efficiency. This was causing the latency, to get rid of this latency we had to set:

ServicePointManager.UseNaggleAlgorithm=false.                       

This changes latency from 150 milliseconds to just a few milliseconds.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号