积极答复者
大文件并发下载时iis停止响应

问题
-
请教:asp.net做了一个断点下载的的页面,主要代码为
byte[] buffer = new byte[StaticConfig.BufferSize];
while (length > 0 && this.Response.IsClientConnected)
{
//buffer = new byte[StaticConfig.BufferSize];
count = fs.Read(buffer, 0, StaticConfig.BufferSize);
this.Response.OutputStream.Write(buffer, 0, count);
this.Response.Flush();
}
因为下载的文件都是大文件,所以传输需要几十分钟,但一般运行几分钟后,在访问就没有响应或者响应很慢,在下载没有断开,包括访问该网站的其他页面(简单asp页面)都没有响应或者响应很慢,但在该服务器上还能正常下载,其他的机器要不不能访问,要不访问很慢,感觉像自我保护一样,但是回收应用程序池或者重启IIS就都恢复了,郁闷中...同时在线下载的才有二十多个。 中间有些限速和状态管理的代码,注释了效果一样,就没有贴出来了。因为后面的请求根本没有到page_load方法
日志显示,在卡死后,任然会有正常的访问,隔几分钟就有三四个访问被允许,而且访问时间是相同的,其实中间还有很多请求没有响应。
在卡死一段时间后,运行到后面netstat -an 显示大量“CLOSE_WAIT”。
各位大侠,请指教,也可以告诉我大概的问题在哪里,谢谢。
答案
-
在加入
Context.ApplicationInstance.CompleteRequest();
this.Response.Close();
代码后,问题基本解决,谢谢围观!
- 已标记为答案 LeoTangModerator 2012年4月16日 9:53
全部回复
-
问题仍然没有解决,时间越久,就没有任何响应了,而且CPU使用很高,
所有其他的代码都已经基本删除了,下面是主要代码 环境 win 2k3 iis6.0 .net 2.0
this.Response.Cache.SetCacheability(HttpCacheability.Public);
this.Response.Cache.SetLastModified(DateTime.Now);
this.Response.AppendHeader("Content-Length", length.ToString());using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
{
if (pos > 0)
{
this.Response.StatusCode = 206;
fs.Position = pos;
}
this.Response.AppendHeader("Accept-Ranges", "bytes");
this.Response.ContentType = "application/octet-stream";
this.Response.AppendHeader("Connection", "Keep-Alive");
this.Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8)));byte[] buffer = new byte[StaticConfig.BufferSize];
while (length > 0 && this.Response.IsClientConnected)
{
count = fs.Read(buffer, 0, StaticConfig.BufferSize);
this.Response.OutputStream.Write(buffer, 0, count);
this.Response.Flush();//buffer = new byte[StaticConfig.BufferSize];
}}
this.Response.Close();
buffer = new byte[StaticConfig.BufferSize];注释掉内存图形如下,不注释则是平的,而且w3wp.exe使用100左右
-
在加入
Context.ApplicationInstance.CompleteRequest();
this.Response.Close();
代码后,问题基本解决,谢谢围观!
- 已标记为答案 LeoTangModerator 2012年4月16日 9:53