ASP.NET性能调整之解决Server Too Busy错误

来源:http://www.cnblogs.com/bccu/archive/2008/12/10/1351775.html
    最近公司的一个ASP.NET站点频繁出现Server Too Busy错误,具体表现为页面响应慢、经常出现Server Too Busy异常;但实际上服务器的资源消耗却很低,CPU使用只有10%左右,非常奇怪。

    该站点运行环境为Windows 2000,IIS5.0.NET Framework 1.1,站点压力约为每秒10个连接,峰值时约为30。

    从网上查找相关资料后,从表现出的情况来看(响应慢,抛出Server Too Busy异常),初步判断为同时连接过多引起的线程阻塞引起。修改web.config中的httpRuntime配置节中的appRequestQueueLimit参数后,Server Too Busy 的错误得到解决。此参数默认从machine.config中继承,默认值为100,改为1000后Server Too Busy的错误不再出现。

    虽然服务器忙的错误解决了,但是站点响应还是很慢,有时候要等上5—10秒才能打开页面。分析原因应该是同时请求过多,而IIS工作线程不足的原因引起,修改machine.config中processModel配置节maxWorkerThreads参数为200后站点响应速度慢的问题得到解决。此参数默认值为20,可根据服务器硬件配置于压力大小适当调整。

     分析原因,是因为站点程序中使用了HttpWebRequest请求外部服务器的页面,而这个操作是相当耗时的(外部服务器响应慢是主要原因)。当访问者的请求到达ASP.NET工作进程后,ASP.NET首先会检查是否有空余的工作线程(WorkerThread),如果有的话,就交给一个空闲的工作线程去处理,如果没有空闲的工作线程,那么这个请求就会被放到请求队列(RequestQueue)中,这个时候的表现就是响应很慢。当访问量过大导致请求队列也满了的时候,ASP.NET就会抛出Server Too Busy异常了。在.NET 1.1中,默认的工作线程和请求队列分别为20和100,当运行的代码比较费时而访问量又较大的时候,这两个默认值显然就太小了。(现在的服务器硬件便宜了,一般PC服务器的吞吐量都应该远超过这个数)。这两个值可以根据服务器压力大小来进行合理配置。以调整站点吞吐量。

阅读更多
换一批

server is too busy继续探讨,大家帮帮忙

05-27

现在我给些代码看下 ,,帮我分析 有什么不足 rnrn[code=C#]rnrnrn/*鑷姩鐢熸垚绫?rn *鐢熸垚鏃ユ湡锛?009-5-11rn */rnusing System;rnusing System.Data;rnusing System.Data.SqlClient;rnrnnamespace Businessrnrn public class ShopPic:CSBase.DataRead.DataHandlern rn private int picId;rn private string memberNo;rn private string picName;rn private string picUrl;rn private string piceInfo;rn public string PicIdrn rn getrn rn return picId.ToString();rn rn setrn rn if (value == "")return;rn tryrn rn picId = int.Parse(value);rn rn catchrn rn CSBase.DataRead.ErrorMessage.Message = "PicId 鏁版嵁绫诲瀷鍑洪敊!";rn rn rn rn public string MemberNorn rn getrn rn return memberNo.Trim();rn rn setrn rn memberNo = value;rn rn rn public string PicNamern rn getrn rn return picName.Trim();rn rn setrn rn picName = value;rn rn rn public string PicUrlrn rn getrn rn return picUrl.Trim();rn rn setrn rn picUrl = value;rn rn rn public string PiceInforn rn getrn rn return piceInfo.Trim();rn rn setrn rn piceInfo = value;rn rn rn public ShopPic()rn rn rn public int DelShopPic()rn rn ////if (CSBase.DataRead.ErrorMessage.Message != "") return -1;rn Data.ShopPic shopPic = new Data.ShopPic();rn return shopPic.DelShopPic(picId);rn rn public int InsShopPic()rn rn ////if (CSBase.DataRead.ErrorMessage.Message != "") return -1;rn Data.ShopPic shopPic = new Data.ShopPic();rn return picId = shopPic.InsShopPic(memberNo,picName,picUrl,piceInfo) > 0 ? (int)CSBase.DataRead.DataBase.LastAutoKey:0;rn rn public DataTable SelShopPicByAll()rn rn Data.ShopPic shopPic = new Data.ShopPic();rn return Table = shopPic.SelShopPicByAll();rn rn public DataTable SelShopPicByCount()rn rn Data.ShopPic shopPic = new Data.ShopPic();rn return Table = shopPic.SelShopPicByCount(memberNo);rn rn public DataTable SelShopPicByMemberNoPageSize(int pageSize,int pageIndex)rn rn Data.ShopPic shopPic = new Data.ShopPic();rn return Table = shopPic.SelShopPicByMemberNoPageSize(memberNo,pageSize,pageIndex);rn rn public DataTable SelShopPicByMemberNoPageSizePageIndex(int pageSize,int pageIndex)rn rn Data.ShopPic shopPic = new Data.ShopPic();rn return Table = shopPic.SelShopPicByMemberNoPageSizePageIndex(memberNo,pageSize,pageIndex);rn rn public DataTable SelShopPicByMemberNotop5()rn rn Data.ShopPic shopPic = new Data.ShopPic();rn return Table = shopPic.SelShopPicByMemberNotop5(memberNo);rn rn public DataTable SelShopPicByPicId()rn rn Data.ShopPic shopPic = new Data.ShopPic();rn return Table = shopPic.SelShopPicByPicId(picId);rn rn public int UpdShopPic()rn rn ////if (CSBase.DataRead.ErrorMessage.Message != "") return -1;rn Data.ShopPic shopPic = new Data.ShopPic();rn return shopPic.UpdShopPic(picId,memberNo,picName,picUrl,piceInfo);rn rn public int UpdShopPicByIsOne(bool isOne)rn rn ////if (CSBase.DataRead.ErrorMessage.Message != "") return -1;rn Data.ShopPic shopPic = new Data.ShopPic();rn return shopPic.UpdShopPicByIsOne(picId,isOne);rn rn public int UpdShopPicByIsOne0(bool isOne)rn rn ////if (CSBase.DataRead.ErrorMessage.Message != "") return -1;rn Data.ShopPic shopPic = new Data.ShopPic();rn return shopPic.UpdShopPicByIsOne0(picId,memberNo,isOne);rn rn public override bool GetValues(DataRow dataRow)rn rn if (dataRow == null)return false;rn tryrn rn if (Table.Columns.IndexOf("PicId")>=0)rn rn picId = dataRow["PicId"]==System.DBNull.Value?0:(int)dataRow["PicId"];rn rn if (Table.Columns.IndexOf("MemberNo")>=0)rn rn memberNo = dataRow["MemberNo"]==System.DBNull.Value?"":(string)dataRow["MemberNo"];rn rn if (Table.Columns.IndexOf("PicName")>=0)rn rn picName = dataRow["PicName"]==System.DBNull.Value?"":(string)dataRow["PicName"];rn rn if (Table.Columns.IndexOf("PicUrl")>=0)rn rn picUrl = dataRow["PicUrl"]==System.DBNull.Value?"":(string)dataRow["PicUrl"];rn rn if (Table.Columns.IndexOf("PiceInfo")>=0)rn rn piceInfo = dataRow["PiceInfo"]==System.DBNull.Value?"":(string)dataRow["PiceInfo"];rn rn return true;rn rn catch (Exception e)rn rn CSBase.DataRead.ErrorMessage.Message = e.Message;rn return false;rn rn rn public override void GetKeyPrimarys(ref object[] keyPrimarys)rn rn if (PicId == null)return;rn keyPrimarys = new object[Table.PrimaryKey.Length];rn keyPrimarys[0] = PicId;rn rn rnrnrnrnrnrn[/code]

没有更多推荐了,返回首页