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?