SiteSetting class need redesign

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/27/2006 5:45:22 AM
Gravatar
Total Posts 148

Re: SiteSetting class need redesign

I agree that output caching will probably provide better performance if caching PageSettings doesn't eliminate all the DB calls.  An intermediate option would be caching in the business object layer so that you wouldn't need to load the modules and content from the DB each time.  That would allow you to avoid the security issues but you'd still need to implement logic to remove objects from the cache when they are updated.  You'll need that logic to do output caching anyway so it wouldn't be wasted effort.

Proposed plan:

  1. Measure current performance.
  2. Measure performance with "dumb" output caching (i.e. neglecting security and cache invalidation issues).  This would give you an upper-bound on the effect of output caching.
  3. Measure performance of "dumb" business object caching (i.e. neglecting cache invalidation issues).  This would give you an upper-bound on the effect of business object caching.
  4. Measure performance of both types of caching using simplest possible cache invalidation logic (ie. any change to anything on the site invalidates the entire cache.).
  5. If it is worth the extra effort, implement more sophisticated invalidation logic and/or handle the security issues associated with output caching.
  6. If it is worth the extra effort, implement browser caching.  If you handled the output caching security issues in step 5, this is a no-brainer.  If not, you need to decide whether the reduced network bandwidth and server load is worth the effort to do that.

is there a way to make the browser reload the page when the content changes or if the user logs in and has edit permission?

I believe so.  I think there is a property you can set to force the browser to always revalidate it's cache entry with a HEAD request.  So, you'd just need to implement Global.GetVaryByCustomString() to generate a different strings for users with different permissions and for changed content.

--Dean
8/27/2006 1:32:03 PM
Gravatar
Total Posts 18439

Re: SiteSetting class need redesign

Alright I've refactored SiteSettings moving the pagecollection and the current page out of its internals so it could be cached.
I've also done a little minor tweaking to the Cache feature that is already built into SiteModule.

I ran a baseline test this morning before making any changes to SiteSettings

Baseline Before Site Settings refactoring




After Refactoring SiteSettings




Then I tried setting a cache time of 360 seconds in the module settings of each module on the test pages.
The next test I ran was actually a little slower so I reviewed the CachedSiteModuleControl.cs and noticed it was using Context.Cache rather than Httpruntime.Cache, wasn't sure if changing that would help but it apparently did. I also made a few other tweaks so that the cache key would be different for users that can edit vs thos that can't and by current culture.

After Applying Tweaked SiteModule cache



Pretty good improvements!
8/27/2006 1:50:59 PM
Gravatar
Total Posts 18439

Re: SiteSetting class need redesign

And here are the results using "dumb output caching" like this:
<%@ OutputCache Duration="120" VaryByParam="*"  %>

with no handling for roles, culture etc.



8/27/2006 5:06:19 PM
Gravatar
Total Posts 148

Re: SiteSetting class need redesign

Nice!  A couple questions:

To ensure that the test machine wasn't the bottleneck, can you confirm that ACT was running on a machine other than the server and that the ACT machine's CPU was substantially less than 100% during the tests?

To ensure that the network wasn't the bottleneck, can you confirm that the total bandwidth consumed during the test (i.e. average response size times requests/sec) was substantially less than the bandwith of the connection between the ACT machine and the server?

Was the server CPU usage at roughly 100% during all the tests?  If not, a more realistic test would probably use a larger number of simultaneous browser connections.  By only using one browser connection I think you might be forcing the requests to occur sequentially.  If the server CPU is idle waiting for a DB call associated with the only outstanding request, you will see less requests/sec than you would expect in a the real world where the server handles requests from multiple browsers on different threads.

--Dean
8/27/2006 5:33:32 PM
Gravatar
Total Posts 18439

Re: SiteSetting class need redesign

ACT was running on the same machine as the web. I'm not positive whether the machine was pegged but I was watching and asp.net was using 50-60% of the processor and memory use was between 45 and 60MB. Memory probably can be reduced but not horrible I think.
machine is my laptop, a Dell Precision M70, 2.13GHz Pentium M with 2Gigs of RAM

Also was using debug compilation and debug build, results should be better on a remote machine in release mode.
I have another machine I could test on (and probably will soon) but I figured since all the tests were run in the same environment, relative results would still be meaningful.

My test was just using the ACT defaults and ACT recorded a browser session to create the test, just an anonymous session clicking all the pages in the menu. The output is all VB Script so probably very extenable, just haven't learned all the bells and whistles of ACT yet so started out with something basic
8/27/2006 5:51:17 PM
Gravatar
Total Posts 18439

Re: SiteSetting class need redesign

Its going to be challenging to come up with a strategy that really works for the Global.GetVaryByCustomString
The problem is a user may have page edit permission in which case they can edit any module on the page regardless of module specific permission. But a user may also have just edit permission on a module and not all modules on a page so showing the correct edit links for authenticated users could get very complicated.

Still, if its possible to gain 82 requests/sec, that is substantial

Short of that the current caching of siteModule is probably better than caching business objects since it is caching the actual rendered content.

I don't know yet if  ACT can show us the benefit of browser caching. I'll look into it.

Joe
8/29/2006 5:10:19 PM
Gravatar
Total Posts 148

Re: SiteSetting class need redesign

I agree that writing an effective GetVaryByCustomString() is not going to be easy.  For my proposal, see the first 3 bullets of my 8/18/2006 12:12:04 AM post on the "Improve performance 20%" thread.  To handle page-specific permissions in addition to module-specific permissions, just treat the page like another module for the purposes of my proposal.

--Dean
8/30/2006 2:30:06 PM
Gravatar
Total Posts 18439

Re: SiteSetting class need redesign

I did some thinking about this last night and it just seemed like it would get too complicated to make sure the right cache copy gets shown to each user without having an explosion of cached copies.
Your suggestions seemed on the right track but thinking through how to implement them my train of thought couldn't quite pull the load ;-). I get the feeling I could spend a lot of time on it and it may not really improve performance as much as the dumb outputcaching does. I think calculating the vary string would not be too bad at the time when the page is being rendered from the db but once its in the cache the logic of having to calculate it correctly based on the user's role cookie, the requested path and all these variables in memory makes my brain hurt.

I think for now I'm going to punt on the page output cache strategy and work on other things, though I'd certainly welcome if anyone else wants to explore implementation of this.

I think the gains we have now are pretty good. I'm going to do some more testing using a remote machine and try to find a few other low hanging fruit performance improvements and then maybe try and ship a minor release before I get back to working on the  SiteOffice features.
8/30/2006 2:53:55 PM
Gravatar
Total Posts 148

Re: SiteSetting class need redesign

Sounds like a good plan.  I agree that the implementation would be quite hairy and it's not at all clear it would be worth the effort.
8/30/2006 3:47:42 PM
Gravatar
Total Posts 18439

Re: SiteSetting class need redesign

It just occurred to me that the way to track the variables needed would be to go the other way from what I just did and add more things to SiteSettings and put it in the cache.

We would need the PageSettings for all the pages within the site (which I just removed ;-)) but in addition to the ModuleCollection for the ActivePage which we had before we would need it for every PageSettings in the collection, this would enable us to do what Bo (kwa) suggested earlier in this thread and just choose the active page from the collection. This would basically be a dictionary of the site pages and modules with roles and with this and the user cookies we would have everything we would need to calculate some kind of string for GetVaryByCustomString()

We could set a timestamp or create a guid string on the SiteSettings object when it is first instantiated and use it as part of the vary string too. This way any dependency that causes the siteSettings cache to be refreshed would start creating a new set of pages.

The formula for the string might be something like
HasPageEditPermission.ToString()
If the user has page edit permision we calculate true for each module in sequence and add it to the string
else we call Module.HasEditPermision in sequence and add that to the string

What do you think Dean? Any flys in the ointment?

Would it be too much to store in memory for very large sites? Other problems? or do you think its worth experimenting with it? Might make initial loads slow when the application starts.
8/30/2006 4:54:13 PM
Gravatar
Total Posts 148

Re: SiteSetting class need redesign

Sounds about right to me.  We should probably also provide a way for modules to indicate cache expiration time.  The expiration time for the page should be computed as the earliest expiration time of any module on the page.  As an example consider a blog module which displays a calendar.  Strictly speaking, a page containing that module should not be cached past midnight.

On a related note, you might want to look into techniques to reduce the overall size of pages.  The mojoportal.com homepage currently weighs in at about 100Kbytes (not counting external files like images, styles, etc).  Since your earlier benchmarks seem to imply that about 80% of time is spent just sending bytes to the browser, anything we could do to reduce page sizes could have a large impact on performance.  For comparison if I convert the HTML to plain text, the resulting size is only 18Kbytes.  So, roughly speaking,  we are sending 100Kbytes of HTML to display 18Kbytes of text.  Looking at the HTML source the 2 things that jumped out at me were 1) ViewState accounts for about 7700 bytes, and 2) the HTML for the calendar accounts for over 15KBytes.  The calendar size could be reduced alot by eliminating the inline styles.  Inline styles are taking up a lot of space elsewhere on the page too.  It wouldn't suprise me if you could get a 20% performance increase just by trimming some of these kinds of fat.



You must sign in to post in the forums. This thread is closed to new posts.