.net – HttpWebRequest 64位Windows上的GetResponse延迟
我最近尝试在64位版本的Windows上运行.NET应用程序,并惊讶地发现我所有的HttpWebRequest.GetResponse()对本地网络上的Web服务的调用都在谈论巨大(约500ms)的时间来完成.以下是有关我的测试设置的几个信息:
> .NET 3.5 测试代码是MSDN’s article on using System; using System.Diagnostics; using System.Net; using System.Text; using System.IO; public class Program { // Specify the URL to receive the request. public static void Main (string[] args) { CredentialCache crCache = null; Stopwatch s = new Stopwatch(); for (int i = 0; i < 10; i++) { s.Reset(); s.Start(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create (args[0]); // Set some reasonable limits on resources used by this request request.MaximumAutomaticRedirections = 4; request.MaximumResponseHeadersLength = 4; // Set credentials to use for this request. if (crCache == null) { crCache = new CredentialCache(); crCache.Add(new Uri(args[0]),"Basic",new NetworkCredential("user","password")); } request.Credentials = crCache; request.PreAuthenticate = true; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Console.WriteLine("Content length is {0}",response.ContentLength); Console.WriteLine("Content type is {0}",response.ContentType); // Get the stream associated with the response. Stream receiveStream = response.GetResponseStream(); // Pipes the stream to a higher level stream reader with the required encoding format. StreamReader readStream = new StreamReader(receiveStream,Encoding.UTF8); Console.WriteLine("Response stream received."); //Console.WriteLine (readStream.ReadToEnd ()); response.Close(); readStream.Close(); s.Stop(); Console.WriteLine("Request took: " + s.ElapsedMilliseconds); } } } 我编译了针对Windows Vista Home Premium的x86和64位Windows机器的x64.这三个机器与托管Web服务的机器连接在同一个网络交换机上.以下是我得到的结果: > Windows Vista Home Premium 32bit,x86程序集:GetResponse()的第一次调用在大约150ms内完成,而所有连续的调用大概需要10ms. 有没有人有一个线索的原因,我得到这样长的GetResponse延迟64位版本的Windows? 编辑 有关问题的其他信息: >当使用Firefox 3.5执行请求时,我测量了响应时间(通过firebug),并且所有机器的请求 – 响应延迟是相同的,即不会重现问题. 32bit:tcp对话如下: > host->服务器新的Web请求HTTP GET / HTTP / 1.1 64位:tcp对话如下: > host->服务器新的Web请求HTTP GET / HTTP / 1.1 在64位机器上获得的500ms主要发生在最后两个步骤中.请注意,这绝对不是与TCP堆栈相关(因为一切都可以用firefox).我们在最后两个步骤中得到不同TCP Ack模式的原因(捎带在32位,而64位分开的TCP Ack帧)是64位情况下新的Web请求延迟了309 96ms(因此TCP堆栈输出一个单独的Ack框架,它不能等待应用程序层). 所以,它似乎是: >问题是由完成Web请求和发出新请求之间的增量时间引起的. 任何线索?
只是遇到这个线程的任何人,并有问题.
64位系统延迟的原因是WebClient等待Windows返回代理值. 编写这样的代码来克服这个问题. WebClient wc = New WebClient; wc.Proxy = null; 这将消除一些用户(包括我自己:)看到的延迟) 很高兴我终于可以回馈社区帮助我这么多:) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 字体 – Windows字体明确地消除字母O中的零号ZERO
- .net – 如何从Windows服务调用Webservice?
- Windows VPN安全吗?
- 使用带Stretch的图像控制= UniformToFill – WP7
- windows-server-2008-r2 – 如何从Powershell的Hyper-V 200
- Windows 7 QueryPerformanceFrequency返回2.4 MHz-ish?
- _asm int 3 软件中断
- windows – 为什么这会阻止我安装MSI:系统管理员已设置策略
- 命令行界面 – Microsoft设置命令行快捷方式的详尽列表是什
- 在Windows 8 metro应用程序中启动进程