Improve performance 20%

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
8/16/2006 10:46:15 PM
kwa
Gravatar
Total Posts 23

Improve performance 20%

Just want to share what I got. This little code modification help improve performance up to 20%:

SiteSettings

 

{

setting =

Context.Cache.Insert(

}

 

{

Context.Items[

setting = (SiteSettings)Context.Cache[SiteUtils.GetHostName()];if (setting == null)new SiteSettings(SiteUtils.GetHostName(), pageIndex, pageID);SiteUtils.GetHostName(), setting, null, DateTime.Now.AddMinutes(2), System.Web.Caching.Cache.NoSlidingExpiration);if(Context.Items.Contains("SiteSettings"))"SiteSettings"] = setting;//new SiteSettings(SiteUtils.GetHostName(),pageIndex, pageID);

}

 

else

{

Context.Items.Add(

"SiteSettings", setting);//new SiteSettings(SiteUtils.GetHostName(),pageIndex, pageID));

}

8/17/2006 3:37:40 AM
Gravatar
Total Posts 18439

Re: Improve performance 20%

That might seem like a good idea but siteSettings has different internal state for different pages (note the pageid in the constructor) so caching it would mean a chance of showing the wrong content for the selected page.

If you are looking for ways to improve performance that is great but first identify where bad performance is happening if there is bad performance. If you are doing load testing and you can show me a baseline and a performance improvement with before and after laod test results and the change doesn't break anything I'm glad to make the change. I think the suggestion about siteSettings does break functionality.

Joe
8/17/2006 9:04:41 AM
kwa
Gravatar
Total Posts 23

Re: Improve performance 20%

You are right, I run into the problem of caching the same page. Now I'm going to find another way.

And it did improve from 3.72 to 4.63. If the forum allow file attachement I could have upload performance chart here.

 

8/17/2006 3:58:32 PM
Gravatar
Total Posts 18439

Re: Improve performance 20%

Another thing that won't work if siteSettings is cached is hosting multiple sites on a single installation.

One thing you could try with your load tests that I'd be interested to find out if it improves performance would be to add this to the top of Default.aspx:

<%@ OutputCache Duration="120" VaryByParam="*"  %>

I have  MS Application Center Test and have done some load testing myself in the past but I'm focused on some other things at the moment so your efforts to find performance improvements are appreciated.

If you have time to experiment with the above and see whether it helps and whether any side effects I'd be glad to hear your findings. If you have a file attachment results you can email it to me at joe_audette [at] yahoo dotcom

Thanks for your efforts.

Cheers,

Joe
8/17/2006 4:47:41 PM
Gravatar
Total Posts 148

Re: Improve performance 20%

If I understand that correctly, then I might not immediately see a forum post that takes me less than 2 minutes to create.  That could be pretty confusing to users and would probably create a fair number of support calls.

Isn't there a way to explicitly remove something from the cache?  Seems like that would provide the best performance boost.  Cache aggressively, but whenever content is added/deleted/changed, remove the affected URLs from the cache.

--Dean
8/17/2006 4:59:18 PM
Gravatar
Total Posts 18439

Re: Improve performance 20%

Hmm, your're right Dean it might be a problem in some cases though I think you would see your forum post because its on a different page, ForumThreadView.aspx, but the page that holds the forum module might not show your response right away as far as the most recent post info.

Looks like there is a sqldependency that can be used
http://msdn2.microsoft.com/en-us/library/hdxfb6cy.aspx

Not sure if we can make that work with other dbs, my guess is not.

Maybe we should focus on caching of modules instead of at the page level. There actually is already a cache duration setting in module settings but I haven't reallt done any measuring of its benefits and its set to 0 by default which is no cache at all.

Would be good to get some measurements on that. We could leave it at 0 for forum module.

So, kwa, for example, you could put an html module, blog etc on a page and set them to have a cache time > 0 and see what the load tester has to tell us.
8/17/2006 5:02:47 PM
Gravatar
Total Posts 18439

Re: Improve performance 20%

Dean,

I'd also be interested in your thoughts on whether hosting companies might not like heavy caching, while it improves user performance experience it also consumes more server memory the more things we cache.

My friend David who runs ChristianASP hosting told me that mojoPortal uses less server resources than the couple of DotNetNuke sites he hosts and Community Server is such a resource hog he would only run it if it were the only thing on his server.
I don't know whether its the caching that causes the load he's talking about but its seems like a possibility.


Joe
8/17/2006 7:12:04 PM
Gravatar
Total Posts 148

Re: Improve performance 20%

I suspect that hosting companies would actually love caching.  It would greatly reduce CPU and disk load and could even reduce network load.  The amount of memory used could be controlled by changing the expiration time, but even with no expiration (i.e. just explicit removal), I suspect the memory requirement wouldn't be too large.  For example, I just did a quick estimate that it would currently take < 12M to cache every page associated with the mojoportal.com Forums.

Now that I think of it, the trickiest issues with caching are security and personalization.  Those features mean that different users often get different views of the same URL  The simplest way to address that is to use VaryByHeader="Cookie", but that would result in an extra copy in the cache for each user which probably would use too much memory.  The best solution is probably to use VaryByCustom and base the custom string on the user's role most of the time.  Of course if the page being requested contains content that is specific to an individual user (e.g. Logged in as: Username), that isn't going to be sufficient.  Dynamic substituion would help in some cases.

In general, I think caching is probably the best way to improve performance but I think it is a large and relatively complex feature to add.  Basic outline:

  • Maintain a last-modified time (preferably in memory) for each module or at least the entire site.  Everytime a module is modified (either content or metadata like permissions), update the last-modified time and invalidate cached pages that depend on that module.
  • For each module, maintain (preferably in memory) a list of the sets of roles and users that will see different content.  For example, admins might see one thing, content authors and Bob might see another, and anonymous users might see something else.  So the list would contain 3 sets of roles/users.
  • Write Global.GetVaryByCustomString() to get the above information for each of the modules on the requested page, concatenate the last-modified time of each of the modules and the number of the set in each module to which the requesting user belongs, and return a cryptographic hash of the result.
  • Allow admins to turn off the display of "Logged in as: Username", or use javascript to extract the username from a cookie or from the server.  That would mean that the server wouldn't have to generate a new copy of the page for each user. 
  • Use Location="Any" so that pages can be cached on the client as well as the server, to reduce network bandwidth.
Hope that makes sense...

--Dean
8/18/2006 4:14:03 AM
Gravatar
Total Posts 18439

Re: Improve performance 20%

Here are the results from tests done by bo (aka kwa) using the Output Cache directive

As expected, significant improvements but also as Dean pointed out and testing shows there are significant issues to be solved before we can use this technique.

With no cache 4.92 RPS


With cache 7.37 RPS


We will have to come up with a way to vary the cache and invalidate the cache correctly in all situations.
For example if the cache gets created based on a request from a user in Admins role, then the next request by an anonymous user sees the edit links that should only be visible to admin.

The logged in as control will have to be reworked, could probably use javascript and store the user name in a cookie.

Localization will be another problem as labels and buttons won't adapt to the user's browser language unless we use that as an element to vary the cache and so on... lots of issues to solve before we coud take advantage of this.

Joe
8/18/2006 4:29:25 AM
Gravatar
Total Posts 18439

Re: Improve performance 20%

Dean,

in follow up about memory usage, if a cached item is invalidated is the memory recovered immediately or when garbage collection occurs? I've seen .NET web apps consume 500MB+ of memory when its available and thats in an app not using heavy caching. I think what happens is that a lot of whats in memory is not needed but garbage colection is lazy unless overall memory is getting low.

Joe
8/18/2006 6:42:28 AM
Gravatar
Total Posts 148

Re: Improve performance 20%

The amount of memory used for caching and the timing of reclamation might be controllable via the <cache> configuration section.  I'm not sure whether those settings only apply to items added to the application cache programatically or whether they also apply to the output cache.

--Dean
8/18/2006 8:05:33 AM
Gravatar
Total Posts 18439

Re: Improve performance 20%

Good link, thanks. I was thinking after my last post that its possible caching would have reduced memory usage in the apps I've seen due to less objects being instantiated but I do think we need to keep an eye on the memory usage as we implement caching and make sure it doesn't get excessive the more things we cache and the more things we vary cache instances by.

Joe
8/24/2006 4:16:23 PM
Gravatar
Total Posts 18439

Re: Improve performance 20%

Just read an interesting blog post
http://blogs.msdn.com/tess/archive/2006/08/11/695268.aspx

http://blogs.msdn.com/tess/archive/2006/01/23/516139.aspx

Some good insights about things that can cause memory consumption/leak problems in ASP.NET
You must sign in to post in the forums. This thread is closed to new posts.