Get Umbraco Certified in October
5 courses in 4 different countries across 2 continents leaves no excuse.
Attend courses in the Netherlands, UK, USA and at Umbraco HQ in Denmark.
See the schedule and read more about our training here.
Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
We have a site that we built in Umbraco 4.5.2 that has over 1000 nodes, and we discovered that any time we were using Linq to Umbraco, it would easily add a second to the load time and quickly max out the CPU on the server with multiple people hitting the site. We had a bit of code that was using Linq to Umbraco on every page load (not smart, I know...), and it was causing the site to be extremely slow and peg the CPU at 100% during "high" traffic times (1000 hits an hour?).
Needless to say, we've looking at other ways of doing things, but has anyone else ran into this problem?
Are you disposing of the DataContext when you're done or are you keeping it active for the life of the app pool?
You really should be keeping it alive as a singleton so that the cache is used within LINQ to Umbraco.
Right now we're using a new one every time. Definitely is not taking advantage of any caching then... I'll give it a try.
I've never used a singleton in a web app before, but I assume it works like any other, just needs to be thread safe. Looks like http://msdn.microsoft.com/en-us/library/ms998558 has a good example of one, i'll see if that does the trick.
I don't make my own singletons, I use a dependency injection framework for that. My one of choice is Autofac - http://code.google.com/p/autofac
Tried out the singleton for the DataContext, and it's improved the site performance in a lot of areas of the site. Thanks again!
Oh man, this thread helped me a lot!
I was using Singleton with HttpContext.Current.Items, which means no cache.Now using HttpContent.Current.Cache and it's very fast! :D
I was doing the same thing. I think I got that from Aaron's video? But if we use cache instead of items, then don't we run the risk of having stale data? Would that mean Linq to Umbraco isn't appropriate for large sites where you need it to have the most current data?
Well, I hooked into the Document's event model to clear the Linq2Umbraco cache item when updates are done, for these events:
Perfect, thanks. A little extra wiring to remember, but that should make a big difference in performance.
Do you just clear the cache or do you also fill the cache with the new Linq2Umbraco data? Do you have a sample?
P.s. do you use HttpRuntime.Cache or HttpContext.Current.Cache?
I'm only clearing the cache. The cache will be filled automatically again when someone requests the page (and the L2U singleton is used).For that, we're using a custom cache prefix (static readonly string), and use the Cache.GetEnumerator() to enumerate the keys in the cache and remove the ones which start with the custom prefix.I'm using HttpContent.Current.Cache, but I think it's exactly the same as HttpRuntime.Cache... (http://forums.asp.net/t/1551370.aspx)
Thanks for the info. I already did a setup myself. In the event I don't just clear the cache but also fill it by simply calling the L2U singleton again. This way the newest data is always cached when someone requests the page. So far that also seems to work :).
I also used the caching method of the DataContext like Aaron Powell descibed. But I'm encountering strange behavior, I clear the cache and the next time my DataContext is called, it creates a new DataContext but it doesn't contain any new items, just the same items it contained before the update.I checked that the Umbraco.config file was updated before the new DataContext was created, so the issue seems to be in creating the new DataContext or some way of caching inside the DataContext.
Did anyone encounter this issue and know a way to resolve this? (Other then forcing a AppRecycle by setting a LastWriteTime on the web.confg :( )
I'm doing this at the end of my nightly import routine to force my website to display the most recent data.
Write your reply to:
Image will be uploaded when post is submitted