为什么iis的一个线程池占了100%cpu

新手上路,请多包涵

为什么iis的一个线程池占了快100%cpu,

这个站点是跑asp.net web api的,大多是数据库的操作。

当回收这个线程池后几分钟,cpu使用率就降下来了。

可是隔一天半天的再去服务器看,cpu又会飙升到快100%。

为什么会这样,这个web api访问量其实不是很大的。

    //我沾过来一些示例代码,看看是不是有些地方没注意啊。
      public class GoodController : ApiController
       {   
         Entity entity = new Entity();
            public GoodController()
            {
                entity.Configuration.ValidateOnSaveEnabled = false;
            }
    
            [HttpPost]
    
            public int GoodPingjia()
            {
                HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
                HttpRequestBase request = context.Request;
     
                Authentication authentication = new Authentication(request);
                if (!string.IsNullOrEmpty(authentication.state))
                {
                    return 0;
                }
                string orderID = request["orderID"];
                Order order = entity.Order.Find(orderID);
                GoodEvaluate goodEvaluate = new GoodEvaluate();
                goodEvaluate.GoodID = order.GoodID;
                goodEvaluate.GoodGategoryID = entity.Good.Find(order.GoodID).GoodGategoryID;
                goodEvaluate.Detail = request["Detail"];
                goodEvaluate.UserID = authentication.userID;
                goodEvaluate.State = 1;
                goodEvaluate.Time = DateTime.Now;
                entity.GoodEvaluate.Add(goodEvaluate);
                order.State |= 16;
                return entity.SaveChanges();
            }
    
            ~GoodController()
    
            {
                entity.Dispose();
            }
      }
  
    //这是那个webapi的代码示例, 这个webapi基本都是这种写法,是不是不能在析构函数里去做  entity.Dispose();啊。
阅读 4.2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进