这次在测试新系统的时候竟然发现运行到一段时间会cpu性能上升到100%,下面是exception的列表:
OptionsPlay.Web.ViewModels.Providers.AsyncUpdater.OptionQuoteUpdater UpdateCachedValues 1-3-1 (ThreadID = 97) exception = System.InvalidOperationException: The operation cannot be completed because the DbContext has been disposed.
՚ System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
՚ System.Data.Entity.Internal.LazyInternalContext.get_ObjectContext()
՚ System.Data.Entity.Internal.Linq.InternalSet`1.Find(Object[] keyValues)
՚ System.Data.Entity.DbSet`1.Find(Object[] keyValues)
՚ OptionsPlay.DAL.EF.Repositories.EFRepository`2.GetById(TId id)
՚ OptionsPlay.DAL.EF.Repositories.CacheStatusesRepository.GetCacheStatus(CacheEntity entity)
՚ OptionsPlay.BusinessLogic.Cache.DatabaseCacheService.Get[TDbEntity](DBCacheStatus& status)
՚ OptionsPlay.BusinessLogic.MarketData.MarketDataProviderCache.GetOptionBasicInformation(String underlyingCode, String optionNumber)
՚ OptionsPlay.BusinessLogic.MarketData.MarketDataService.GetOptionInformation(String optionNo)
՚ OptionsPlay.BusinessLogic.MarketData.MarketDataService.GetOptionQuotes(List`1 optionNumbers)
՚ OptionsPlay.Web.ViewModels.Providers.AsyncUpdater.OptionQuoteUpdater.<<get_GetItems>b__0>d__4.MoveNext()
--- ӽעӬӣքʏһλ׃אבջٺؙքĩβ ---
՚ System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
՚ System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
՚ OptionsPlay.Cache.AsyncUpdate.KeyCachedUpdater`1.<UpdateCachedValues>d__2.MoveNext()
22.05.2015 13:17:58 DEBUG OptionsPlay.Cache.AsyncUpdate.KeyCachedUpdater`1+<UpdateCachedValues>d__2.MoveNext(:0) OptionsPlay.Web.ViewModels.Providers.AsyncUpdater.OptionQuoteUpdater UpdateCachedValues 1-3-1 (ThreadID = 97) exception = ՚ System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
՚ System.Data.Entity.Internal.LazyInternalContext.get_ObjectContext()
՚ System.Data.Entity.Internal.Linq.InternalSet`1.Find(Object[] keyValues)
՚ System.Data.Entity.DbSet`1.Find(Object[] keyValues)
՚ OptionsPlay.DAL.EF.Repositories.EFRepository`2.GetById(TId id)
՚ OptionsPlay.DAL.EF.Repositories.CacheStatusesRepository.GetCacheStatus(CacheEntity entity)
՚ OptionsPlay.BusinessLogic.Cache.DatabaseCacheService.Get[TDbEntity](DBCacheStatus& status)
՚ OptionsPlay.BusinessLogic.MarketData.MarketDataProviderCache.GetOptionBasicInformation(String underlyingCode, String optionNumber)
՚ OptionsPlay.BusinessLogic.MarketData.MarketDataService.GetOptionInformation(String optionNo)
՚ OptionsPlay.BusinessLogic.MarketData.MarketDataService.GetOptionQuotes(List`1 optionNumbers)
՚ OptionsPlay.Web.ViewModels.Providers.AsyncUpdater.OptionQuoteUpdater.<<get_GetItems>b__0>d__4.MoveNext()
--- ӽעӬӣքʏһλ׃אבջٺؙքĩβ ---
՚ System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
՚ System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
՚ OptionsPlay.Cache.AsyncUpdate.KeyCachedUpdater`1.<UpdateCachedValues>d__2.MoveNext()
这个问题其实codeplex上web api 2.0网站上有解释:
http://aspnetwebstack.codeplex.com/workitem/1797
只要增加下面的supress的代码就行:
config.MessageHandlers.Add(new CancelledTaskBugWorkaroundMessageHandler()); class CancelledTaskBugWorkaroundMessageHandler : DelegatingHandler { protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { HttpResponseMessage response = await base.SendAsync(request, cancellationToken); // Try to suppress response content when the cancellation token has fired; ASP.NET will log to the Application event log if there's content in this case. if (cancellationToken.IsCancellationRequested) { return new HttpResponseMessage(HttpStatusCode.InternalServerError); } return response; } }