Intermittent high CPU when calling ContentService.GetByID
Hello all. I have a site running Umbraco version 7.1.8 assembly: 1.0.5394.16131 on IIS 7.5. It is experiencing an intermittent high CPU condition, which I think I have tracked down to a call to ContentService.GetByID. I cannot force the conditon to happen, but I have a process dump taken during the condition. In that dump, I have three requests from the same client, with the same session id, for the same page. I assume the user requested the page, it hung, and he tried two more times.
The page the user was requesting is a uBlogsy post. In uBlogsyPost.cshtml I am doing the following, in order to only render content on pages which have been published.
var content = ApplicationContext.Current.Services.ContentService.GetById(Model.Content.Id);
bool isPublished = content.Published;
The thread with 00:17:50.730 CPU time had the following (truncated) call stack:
So, I have a couple of questions. 1) Is it unsafe to call ContentService.GetByID for the current Model.Content in a view? Is there some other way to figure out if the current node is published? 2) Is this a known bug in ContentService.GetByID? I haven't reviewed the source yet, but I was surprised to see this call making any kind of changes to a dictionary. The page that was being requested was last saved and published December 1, so I would have expected this call to just fetch from the existing disk cache, without changing anything.
Thanks for any help anyone can offer. I've been puzzling over this for a while.
Thanks Sebastiaan, that's good to know. I don't want to do that even if I weren't having issues. Is there a good way to know if the current page has been published? I can check if the page has a preview url, which is probably good enough for my purposes, but I can't see anything equivalent to Content.Published.
You can only get a page from the cache if it is published, so if Model.Content.TypedContent(yourId) doesn't return a page, it's not in the cache.
And the "current" page cannot be shown on the frontend if it isn't published, so checking if the "current" page is publish would be superfluous.. you either get a 404 (not published) or a page.
Sorry for adding my problem to this post but really need help to make sense out of everything. I was having similar sort of issues where CPU would jump upto 100% I didnt use GetByID anywhere however I did use CurrentPage.HasValue and Umbraco.Field to read data directly in the template.
I deleted two newly created pages did a publish of the whole site and removed everything under recycle node and after that haven't experienced the high CPU issue.
I am still trying to make sense as to why I was getting the issue in the first place and why deleting and republishing the site could potentially be the solution.
When the CPU was quite high I created a dump file of w3wp and found the following when debugging through windb
Using windebug found at least 4-5 threads that were taking up to 10 min each all these threads were similar and looking at the stack trace I got the following. Any help or explanation is much appreciated
I've been experiencing an issue very similar to yours, I get very high CPU usage when calling the content service. There are threads hanging when calling content service GetContentType. When I've analysed a memory dump, I've found a stack trace like the one you've posted here.
Intermittent high CPU when calling ContentService.GetByID
Hello all. I have a site running Umbraco version 7.1.8 assembly: 1.0.5394.16131 on IIS 7.5. It is experiencing an intermittent high CPU condition, which I think I have tracked down to a call to ContentService.GetByID. I cannot force the conditon to happen, but I have a process dump taken during the condition. In that dump, I have three requests from the same client, with the same session id, for the same page. I assume the user requested the page, it hung, and he tried two more times.
The page the user was requesting is a uBlogsy post. In uBlogsyPost.cshtml I am doing the following, in order to only render content on pages which have been published.
The thread with 00:17:50.730 CPU time had the following (truncated) call stack:
So, I have a couple of questions. 1) Is it unsafe to call ContentService.GetByID for the current Model.Content in a view? Is there some other way to figure out if the current node is published? 2) Is this a known bug in ContentService.GetByID? I haven't reviewed the source yet, but I was surprised to see this call making any kind of changes to a dictionary. The page that was being requested was last saved and published December 1, so I would have expected this call to just fetch from the existing disk cache, without changing anything.
Thanks for any help anyone can offer. I've been puzzling over this for a while.
The ContentService goes straight to the database so yeas, it is unsafe to call if you are expecting to read from cached content.. :-)
When querying for content always use the Model.Content calls or dynamic versions of that. Here's some cheat sheets (they say Umbraco 6 but are also valid for v7): http://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets
Thanks Sebastiaan, that's good to know. I don't want to do that even if I weren't having issues. Is there a good way to know if the current page has been published? I can check if the page has a preview url, which is probably good enough for my purposes, but I can't see anything equivalent to Content.Published.
You can only get a page from the cache if it is published, so if
Model.Content.TypedContent(yourId)
doesn't return a page, it's not in the cache.And the "current" page cannot be shown on the frontend if it isn't published, so checking if the "current" page is publish would be superfluous.. you either get a 404 (not published) or a page.
Perfect, thanks, but the current page can be unpublished if you're in preview mode.
Hi Guys,
Sorry for adding my problem to this post but really need help to make sense out of everything. I was having similar sort of issues where CPU would jump upto 100% I didnt use GetByID anywhere however I did use CurrentPage.HasValue and Umbraco.Field to read data directly in the template.
I deleted two newly created pages did a publish of the whole site and removed everything under recycle node and after that haven't experienced the high CPU issue.
I am still trying to make sense as to why I was getting the issue in the first place and why deleting and republishing the site could potentially be the solution.
When the CPU was quite high I created a dump file of w3wp and found the following when debugging through windb
Using windebug found at least 4-5 threads that were taking up to 10 min each all these threads were similar and looking at the stack trace I got the following. Any help or explanation is much appreciated
OS Thread Id: 0x1008 (38) Child SP IP Call Site 000000db9a9dcac0 00007ffb14611fbc System.Collections.Generic.Dictionary2[[System.__Canon, mscorlib],[System.Boolean, mscorlib]].Insert(System.__Canon, Boolean, Boolean) 000000db9a9dcb50 00007ffab7d1d45e Umbraco.Core.Models.EntityBase.TracksChangesEntityBase.OnPropertyChanged(System.Reflection.PropertyInfo) 000000db9a9dcba0 00007ffab7d16f2c Umbraco.Core.Models.EntityBase.TracksChangesEntityBase.SetPropertyValueAndDetectChanges[[System.__Canon, mscorlib]](System.Func2, System.Canon, System.Reflection.PropertyInfo) 000000db9a9dcc38 00007ffb15a1f0b7 [StubHelperFrame: 000000db9a9dcc38] 000000db9a9dcee0 00007ffb15a1f0b7 [DebuggerU2MCatchHandlerFrame: 000000db9a9dcee0] 000000db9a9dd1f8 00007ffb15a1f0b7 [HelperMethodFramePROTECTOBJ: 000000db9a9dd1f8] System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean) 000000db9a9dd370 00007ffb14553b4c System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[]) 000000db9a9dd3e0 00007ffb14551273 System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo) 000000db9a9dd460 00007ffb146182cc System.Reflection.RuntimePropertyInfo.SetValue(System.Object, System.Object, System.Object[]) 000000db9a9dd4b0 00007ffab7d2f3bd Umbraco.Core.Models.DeepCloneHelper.DeepCloneRefProperties(Umbraco.Core.Models.IDeepCloneable, Umbraco.Core.Models.IDeepCloneable) 000000db9a9dd560 00007ffab7d4281d Umbraco.Core.Models.ContentTypeCompositionBase.DeepClone() 000000db9a9dd5b0 00007ffab7ba62ad Umbraco.Core.Persistence.Caching.RuntimeCacheProvider.GetByIds(System.Type, System.Collections.Generic.List1<System.Guid>) 000000db9a9dd6a0 00007ffab7ba4895 Umbraco.Core.Persistence.Repositories.RepositoryBase2[[System.Int32, mscorlib],[System.Canon, mscorlib]].GetAll(Int32[]) 000000db9a9dd710 00007ffab7d37950 Umbraco.Core.Persistence.Repositories.ContentTypeBaseRepository1+ContentTypeQueryMapper[[System.__Canon, mscorlib]].MapContentTypeChildren[[System.__Canon, mscorlib]](Umbraco.Core.Models.IContentTypeComposition[], Umbraco.Core.Persistence.Database, System.__Canon, System.Collections.Generic.IDictionary2<>1<Int32>>) 000000db9a9dd7d0 00007ffab7d20d3c Umbraco.Core.Persistence.Repositories.ContentTypeBaseRepository1+ContentTypeQueryMapper[[System.Canon, mscorlib]].GetContentTypes[[System.Canon, mscorlib]](Int32[], Umbraco.Core.Persistence.Database, System.Canon, Umbraco.Core.Persistence.Repositories.ITemplateRepository) 000000db9a9dd830 00007ffab7d208e8 Umbraco.Core.Persistence.Repositories.ContentTypeRepository.PerformGetAll(Int32[]) 000000db9a9dd8a0 00007ffab7ba4e52 Umbraco.Core.Persistence.Repositories.RepositoryBase2[[System.Int32, mscorlib],[System.__Canon, mscorlib]].GetAll(Int32[]) 000000db9a9dd910 00007ffab7d1f4af Umbraco.Core.Persistence.Repositories.ContentTypeRepository.PerformGetByQuery(Umbraco.Core.Persistence.Querying.IQuery1) 000000db9a9dd970 00007ffab7d1f1cc Umbraco.Core.Persistence.Repositories.RepositoryBase2[[System.Int32, mscorlib],[System.__Canon, mscorlib]].GetByQuery(Umbraco.Core.Persistence.Querying.IQuery1) 000000db9a9dd9c0 00007ffab7b8d484 Umbraco.Core.Services.ContentTypeService.GetContentType(System.String) 000000db9a9dda50 00007ffab7b8c7a7 Umbraco.Core.Models.PublishedContent.PublishedContentType.CreatePublishedContentType(Umbraco.Core.Models.PublishedItemType, System.String) 000000db9a9ddab0 00007ffab7b8c6af Umbraco.Core.Cache.CacheProviderExtensions+<>cDisplayClass91[[System.__Canon, mscorlib]].<GetCacheItem>b__8() 000000db9a9ddae0 00007ffab7b8c67f Umbraco.Core.Cache.StaticCacheProvider+<>c__DisplayClass1a.<GetCacheItem>b__19(System.String) 000000db9a9ddb10 00007ffb14e7aae3 System.Collections.Concurrent.ConcurrentDictionary2[[System.Canon, mscorlib],[System.Canon, mscorlib]].GetOrAdd(System.Canon, System.Func2<System.__Canon,System.__Canon>) 000000db9a9ddb70 00007ffab7b8c642 Umbraco.Core.Cache.StaticCacheProvider.GetCacheItem(System.String, System.Func1) 000000db9a9ddbc0 00007ffab7b8bda4 Umbraco.Core.Cache.CacheProviderExtensions.GetCacheItem[[System.Canon, mscorlib]](Umbraco.Core.Cache.ICacheProvider, System.String, System.Func1<System.__Canon>) 000000db9a9ddc40 00007ffab7b8bcbc Umbraco.Core.Models.PublishedContent.PublishedContentType.Get(Umbraco.Core.Models.PublishedItemType, System.String) 000000db9a9ddca0 00007ffab7b8b4f6 Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedContent.Initialize() 000000db9a9ddd30 00007ffab7d2fd5b Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedContent.get_DocumentTypeAlias() 000000db9a9ddd60 00007ffab7d2fcb4 Umbraco.Core.Models.PublishedContent.PublishedContentModelFactory.CreateModel(Umbraco.Core.Models.IPublishedContent) 000000db9a9dddb0 00007ffab7d2fbbd Umbraco.Core.Models.PublishedContent.PublishedContentExtensionsForModels.CreateModel(Umbraco.Core.Models.IPublishedContent) 000000db9a9dddf0 00007ffab7d48907 Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedContent.InitializeChildren() 000000db9a9dde60 00007ffab7b898aa Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache.ConvertToDocument(System.Xml.XmlNode, Boolean) 000000db9a9ddeb0 00007ffab7b890a0 Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache.DetermineIdByRoute(Umbraco.Web.UmbracoContext, Boolean, System.String, Boolean) 000000db9a9ddf40 00007ffab7b88cf4 Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache.GetByRoute(Umbraco.Web.UmbracoContext, Boolean, System.String, System.Nullable1) 000000db9a9ddfc0 00007ffab7b88b17 Umbraco.Web.Routing.ContentFinderByNiceUrl.FindContent(Umbraco.Web.Routing.PublishedContentRequest, System.String) 000000db9a9de050 00007ffab7b889e4 Umbraco.Web.Routing.ContentFinderByNiceUrl.TryFindContent(Umbraco.Web.Routing.PublishedContentRequest) 000000db9a9de0c0 00007ffb113a1095 System.Linq.Enumerable.Any[[System.Canon, mscorlib]](System.Collections.Generic.IEnumerable1<System.__Canon>, System.Func2) 000000db9a9de110 00007ffab7b87e06 Umbraco.Web.Routing.PublishedContentRequestEngine.FindPublishedContent() 000000db9a9de170 00007ffab7b87c42 Umbraco.Web.Routing.PublishedContentRequestEngine.FindPublishedContentAndTemplate() 000000db9a9de1c0 00007ffab7b835d7 Umbraco.Web.Routing.PublishedContentRequestEngine.PrepareRequest() 000000db9a9de200 00007ffab7b7eabd Umbraco.Web.UmbracoModule.ProcessRequest(System.Web.HttpContextBase) 000000db9a9de280 00007ffb0e02cccc System.Web.HttpApplication+SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 000000db9a9de2e0 00007ffb0e00d495 System.Web.HttpApplication.ExecuteStep(IExecutionStep, Boolean ByRef) 000000db9a9de380 00007ffb0e02ab8a System.Web.HttpApplication+PipelineStepManager.ResumeSteps(System.Exception) 000000db9a9de4d0 00007ffb0e00d6a3 System.Web.HttpApplication.BeginProcessRequestNotification(System.Web.HttpContext, System.AsyncCallback) 000000db9a9de520 00007ffb0e0075de System.Web.HttpRuntime.ProcessRequestNotificationPrivate(System.Web.Hosting.IIS7WorkerRequest, System.Web.HttpContext) 000000db9a9de5c0 00007ffb0e010561 System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr, IntPtr, IntPtr, Int32) 000000db9a9de7d0 00007ffb0e00ff92 System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr, IntPtr, IntPtr, Int32) 000000db9a9de820 00007ffb0e765a81 DomainNeutralILStubClass.ILSTUBReversePInvoke(Int64, Int64, Int64, Int32) 000000db9a9df038 00007ffb1597b42e [InlinedCallFrame: 000000db9a9df038] System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr, System.Web.RequestNotificationStatus ByRef) 000000db9a9df038 00007ffb0e0b959b [InlinedCallFrame: 000000db9a9df038] System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr, System.Web.RequestNotificationStatus ByRef) 000000db9a9df010 00007ffb0e0b959b DomainNeutralILStubClass.ILSTUBPInvoke(IntPtr, System.Web.RequestNotificationStatus ByRef) 000000db9a9df0e0 00007ffb0e01074f System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr, IntPtr, IntPtr, Int32) 000000db9a9df2f0 00007ffb0e00ff92 System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr, IntPtr, IntPtr, Int32) 000000db9a9df340 00007ffb0e765a81 DomainNeutralILStubClass.ILSTUB_ReversePInvoke(Int64, Int64, Int64, Int32) 000000db9a9df538 00007ffb1597b683 [ContextTransitionFrame: 000000db9a9df538]
..Many thanks A
Hi Bilal,
I've been experiencing an issue very similar to yours, I get very high CPU usage when calling the content service. There are threads hanging when calling content service GetContentType. When I've analysed a memory dump, I've found a stack trace like the one you've posted here.
Did you ever find a resolution to the issue?
Many thanks, Sam
Hi Sam,
What version of Umbraco you are using? My issue was related to a bug in 7.2.2 where the thread was hanging and I was getting High CPU.
After upgrading to 7.2.8 I haven't seen the High CPU issue!
Thanks A
Hi
I'm running 7.2.1, I'm going to try an upgrade and see if it helps,
Thanks for your advice, Sam
@Bilal See: http://issues.umbraco.org/issue/U4-6292 and http://knowledge-base.havit.cz/2015/03/19/debugging-story-race-condition-v-umbraco-cms-deepclone/
is working on a reply...