我正在下载位于一个驱动器服务器上的大文件。
通常在Windows 7上>下载速度达到1500kb / s max。
在Windows XP上,下载速度达到500kb / s。
这可能是什么原因?
private void DownloadFileRange(string sSourceURL, string sDestinationPath)
{
long iFileSize = 0;
int iBufferSize = 8192;
long tamanioArchivoExistente = 0;
System.IO.FileStream saveFileStream;
System.Net.HttpWebRequest hwRq;
System.Net.HttpWebResponse hwRes;
try
{
if (System.IO.File.Exists(sDestinationPath))
{
System.IO.FileInfo fINfo = new System.IO.FileInfo(sDestinationPath);
tamanioArchivoExistente = fINfo.Length;
}
if (tamanioArchivoExistente > 0)
saveFileStream = new System.IO.FileStream(sDestinationPath, System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);
else
saveFileStream = new System.IO.FileStream(sDestinationPath, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);
hwRq = (HttpWebRequest)HttpWebRequest.Create(sSourceURL);
hwRq.Proxy = null;
//Esto funciona con NET 3.5
if (tamanioArchivoExistente > 0)
{
hwRq.AddRange(tamanioArchivoExistente);
}
hwRes = (HttpWebResponse)hwRq.GetResponse();
iFileSize = hwRes.ContentLength + tamanioArchivoExistente;
System.IO.Stream smRespStream;
smRespStream = hwRes.GetResponseStream();
if (tamanioArchivoExistente > 0)
{
bytesDescargados = tamanioArchivoExistente;
}
int iByteSize;
byte[] downBuffer = new byte[iBufferSize];
while ((iByteSize = smRespStream.Read(downBuffer, 0, downBuffer.Length)) > 0)
{
saveFileStream.Write(downBuffer, 0, iByteSize);
}
}
}
答案 0 :(得分:-1)
Windows XP已有近15年的历史。 T1被认为是快速的,速度为1.5mbps(187kB / s) - 因此内部TCP堆栈似乎可能针对这些条件进行了优化 - 例如较小的缓冲区,以帮助延迟和内存使用。我希望它不会像更现代的迭代那样处理更高的带宽。
所有这一切,你的8K缓冲区看起来确实有点小。您是否尝试将iBufferSize
增加到更大的位置,例如262,144字节?