gpt4 book ai didi

performance - Server 2008上HTTPWebRequest的性能问题(在xp上精细)

转载 作者:行者123 更新时间:2023-12-02 04:11:02 27 4
gpt4 key购买 nike

我已经开发了一个.net 3.5应用程序,该应用程序使用HTTPWebRequest从供应商的Web服务器获取数据,然后返回XML文档。在我自己的xp(32位)工作站上,它的运行速度非常快。

在服务器上,它要慢得多。供应商的16k响应最多需要20-30秒,而在我的PC上则需要1秒。

该服务器是在ESX上以64位模式运行Windows Server 2008的虚拟机。我在服务器上安装了Internet Explorer,并在IE中提出了相同的请求,与我的应用程序不同,该页面的加载时间与在工作站上的加载时间相似。

代码如下:

private static XElement FetchXml(string uri)
{
int retryInterval = 500;

for (int retry = 1; retry < RETRY_MAX; ++retry)
{
Stopwatch stopWatch = Stopwatch.StartNew();

try
{
var request = HttpWebRequest.Create(uri);

request.Proxy = new WebProxy("<the corporate proxy>", 8080);

// 3 minute timeout on individual web requests
request.Timeout = 1000 * 60 * 3;

using (var response = request.GetResponse())
{
using (var stream = response.GetResponseStream())
{
using (var reader = new StreamReader(stream))
{
XElement xml = XElement.Load(reader);
//log.InfoFormat("Fetched (Uri={0}, Size={1} bytes, Elapsed={2:N2}s).", uri, xml.ToString().Length, stopWatch.Elapsed.TotalSeconds);
return xml;
}
}
}
}
catch (Exception ex)
{
//log.ErrorFormat("Error fetching Xml (Uri={0}) : {1}", uri, ex.Message);
}
//log.InfoFormat("Retrying fetch after interval (Attempt#={0}, Interval={1}s)",
// retry, (double)retryInterval/1000);

System.Threading.Thread.Sleep(retryInterval);

// Back off for next retry if it occurs.
retryInterval *= 2;
}

string msg = String.Format("Error fetching Xml - exhausted maximum retries (Uri={0}, MaxRetries={1}).",
uri,
RETRY_MAX);

throw new ApplicationException(msg);
}

经过昨天的研究,我已经测试了以下所有内容:
ServicePointManager.CheckCertificateRevocationList = false;
ServicePointManager.DefaultConnectionLimit = 65000;
ServicePointManager.Expect100Continue = false;

这些都没有帮助。我还看到它暗示代理可能会导致这些问题,并且可以绕过该代理,但不幸的是,在这种环境下不会出现这种情况,而且我认为这可能是代理错误,因为我在工作站上使用了同一代理。

我还获取了一些Microsoft Network Monitor跟踪,有趣的是,从远程站点到我的应用程序的服务器上的数据包大小要小得多。在我的工作站上,它们大约为1400个字节,而在服务器上,它们更像是300个字节,尽管我对TCP不太熟悉,但似乎有很多of不休让http延续来构建完整消息。因此,在我的工作站上,其约4个入站消息占总有效负载的3个出站,而在服务器上则是19个入站消息,具有相同的出站数目。这可能解释了性能问题,但我不明白为什么会发生。当我在服务器上的IE中加载页面时,它会收到少量带有大数据包大小的请求。

我的XP工作站上的网络监视器:
HTTP:Request, GET http://xml.vendor.com/datapage/, Query:version=6.0
HTTP:Response, HTTP/1.1, Status: Ok, URL: http://xml.vendor.com/datapage/
HTTP:HTTP Payload, URL: http://xml.vendor.com/datapage/
TCP:Flags=...A...., SrcPort=2192, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3206279401, Ack=33242842, Win=64512 (scale factor 0x0) = 64512
TCP:[Continuation to #915]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=2192, PayloadLen=1360, Seq=33242842 - 33244202, Ack=3206279401, Win=65535 (scale factor 0x0) = 65535
TCP:[Continuation to #915]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=2192, PayloadLen=1360, Seq=33244202 - 33245562, Ack=3206279401, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=2192, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3206279401, Ack=33245562, Win=64512 (scale factor 0x0) = 64512
TCP:[Continuation to #915]Flags=...AP..., SrcPort=HTTP Alternate(8080), DstPort=2192, PayloadLen=557, Seq=33245562 - 33246119, Ack=3206279401, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=2192, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3206279401, Ack=33246119, Win=63955 (scale factor 0x0) = 63955

服务器上运行的相同代码+请求:
HTTP:Request, GET http://xml.vendor.com/datapage/, Query:version=6.0
HTTP:Response, HTTP/1.1, Status: Ok, URL: http://xml.vendor.com/datapage/
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24013122, Win=255 (scale factor 0x8) = 65280
TCP:[Continuation to #192]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=255, Seq=24013122 - 24013377, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24013377, Win=254 (scale factor 0x8) = 65024
TCP:[Continuation to #192]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=254, Seq=24013377 - 24013631, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24013631, Win=253 (scale factor 0x8) = 64768
TCP:[Continuation to #192]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=253, Seq=24013631 - 24013884, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24013884, Win=252 (scale factor 0x8) = 64512
TCP:[Continuation to #192]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=252, Seq=24013884 - 24014136, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24014136, Win=251 (scale factor 0x8) = 64256
TCP:[Continuation to #192]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=251, Seq=24014136 - 24014387, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24014387, Win=256 (scale factor 0x8) = 65536
TCP:[Continuation to #192]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=256, Seq=24014387 - 24014643, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24014643, Win=255 (scale factor 0x8) = 65280
TCP:[Continuation to #192]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=255, Seq=24014643 - 24014898, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24014898, Win=254 (scale factor 0x8) = 65024
TCP:[Continuation to #192]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=254, Seq=24014898 - 24015152, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24015152, Win=253 (scale factor 0x8) = 64768
TCP:[Continuation to #192]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=253, Seq=24015152 - 24015405, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24015405, Win=252 (scale factor 0x8) = 64512
TCP:[Continuation to #192]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=252, Seq=24015405 - 24015657, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24015657, Win=251 (scale factor 0x8) = 64256
TCP:[Continuation to #192]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=251, Seq=24015657 - 24015908, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24015908, Win=256 (scale factor 0x8) = 65536
TCP:[Continuation to #192]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=256, Seq=24015908 - 24016164, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24016164, Win=255 (scale factor 0x8) = 65280
TCP:[Continuation to #192]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=255, Seq=24016164 - 24016419, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24016419, Win=254 (scale factor 0x8) = 65024
TCP:[Continuation to #192]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=254, Seq=24016419 - 24016673, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24016673, Win=253 (scale factor 0x8) = 64768
TCP:[Continuation to #192]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=253, Seq=24016673 - 24016926, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24016926, Win=252 (scale factor 0x8) = 64512
TCP:[Continuation to #192]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=252, Seq=24016926 - 24017178, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24017178, Win=251 (scale factor 0x8) = 64256
TCP:[Continuation to #192]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=251, Seq=24017178 - 24017429, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24017429, Win=256 (scale factor 0x8) = 65536
TCP:[Continuation to #192]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=256, Seq=24017429 - 24017685, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24017685, Win=255 (scale factor 0x8) = 65280
TCP:[Continuation to #192]Flags=...AP..., SrcPort=HTTP Alternate(8080), DstPort=58401, PayloadLen=181, Seq=24017685 - 24017866, Ack=3779234716, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=58401, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=3779234716, Ack=24017866, Win=254 (scale factor 0x8) = 65024

服务器上的IE提取相同的页面:
HTTP:Request, GET http://xml.vendor.com/datapage/, Query:version=6.0
TCP:Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=53132, PayloadLen=0, Seq=20851875, Ack=2273238303, Win=65535 (scale factor 0x0) = 65535
HTTP:Response, HTTP/1.1, Status: Ok, URL: http://xml.vendor.com/datapage/
HTTP:HTTP Payload, URL: http://xml.vendor.com/datapage/
TCP:[Continuation to #345]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=53132, PayloadLen=1360, Seq=20853598 - 20854958, Ack=2273238303, Win=65535 (scale factor 0x0) = 65535
TCP:[Continuation to #345]Flags=...A...., SrcPort=HTTP Alternate(8080), DstPort=53132, PayloadLen=1360, Seq=20854958 - 20856318, Ack=2273238303, Win=65535 (scale factor 0x0) = 65535
TCP:[Continuation to #345]Flags=...AP..., SrcPort=HTTP Alternate(8080), DstPort=53132, PayloadLen=557, Seq=20856318 - 20856875, Ack=2273238303, Win=65535 (scale factor 0x0) = 65535
TCP:Flags=...A...., SrcPort=53132, DstPort=HTTP Alternate(8080), PayloadLen=0, Seq=2273238303, Ack=20856875, Win=16425 (scale factor 0x2) = 65700

有趣的一点是,对于缓慢的请求,跟踪永远不会捕获“HTTP有效负载”。那里发生了什么奇怪的事情吗?一旦请求最终在服务器上完成,尽管如此,数据仍然格式正确。

最佳答案

这个答案看起来可能是相关的...也许.net在阅读您可能为使IE正常工作而设置的默认代理设置时感到king恼:HTTPWebResponse + StreamReader Very Slow

就像在代码中设置代理一样,您可以跳过检测。

关于performance - Server 2008上HTTPWebRequest的性能问题(在xp上精细),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5194121/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com