Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

In the context of memory profile analsysis we are documenting the current bahavior of some caches in UserIstance class.

Abstract:

A cache is a repository used to store previously fetched resources, also known as objects. Caching provides two main benefits to a web application

  • Your web application will be more responsive to the user because the interpreter will get access to your content more quickly. A responsive application is a key facet to increased customer satisfaction.
  • The load on your Web servers is theoretically reduced at least in terms of CPU utilization. It might put more pressure on the memory utilization.

Caching Strategy:

To implement a successful caching mechanism a very well planned caching strategy is a key factor. The key issues that needs to be resolved are as follows

  • Which pages should be cached
  • Cache whole pages or page fragments
  • Where caching should take place
  • How to invalidate the cached data

UserInstance Cache:

Two member variables of UserInstance class are used to maintain this cache implementation (a home grown cache implementation). 1-

...

  • systemCharacterCache

If caching is enabled and character caching is NOT enabled then the SAX that represents the user's layout for the folder (tab) they are requesting will be attempted to be cached in the systemCache. If character caching is enabled, the serialized form of that layout will be stored in systemCharacterCache. Both indexed by the cacheKey from constructCacheKey(), which incidentally, has a bad side effect. If you look in processUserLayoutParameters() it manually binds the username to the theme preferences. This guarantees that no two users can share any cache entries. If the character cache is enabled, the system cache is not used.

...

  1. If user clicks on any channel to minimize, it will be cache miss.
  2. If user clicks on same channel to restore it to its original size, it will be cache miss.
  3. If user interacts with one channel within the tab then it is a character cache hit.
  4. Channel that tends to go in focus mode (e.g email) will have cache miss.
  5. After that if you interact with the channel it will be cache hit. Eg. If you navigate through pages of the channels it will be cache hit.

Cache key dissection

The following is a dissection of the cache key.

Code Block
titleAn example of a cache key

...


399820,userLayoutRootNode,system1activeTab=1userLayoutRoot=rootnewNodeID=authenticated=true(folder:s10087:

...


50%,)(folder:s10057:50%,)(folder:s10083:50%,)(folder:s10101:50%,)(folder:s10080:50%,)(folder:s10075:50%,)(

...


folder:s10099:50%,)(folder:s10097:50%,)(folder:s10070:50%,)(folder:s10095:50%,)(folder:s10064:50%,)(folder:

...


s10091:50%,)userName=JohnDoeskin=spring(channel:n10077:false,)(channel:n10058:false,)7885417921252830597 
Code Block
xml
xml
titleCache Key, made up of 4 top-level components

<person-id><comma><req-method-node-id><comma><upref-cache-key><ulayout-mgr-cache-key>

...

 

Key component

Value

<person-id>

...

399820

<comma>

...

,

<req-method-node-id>

...

userLayoutRootNode

<comma>

...

,

<upref-cache-key>

...

system1activeTab=1userLayoutRoot=rootnewNodeID=authenticated=true(folder:s10087:50%,)(folder:s10057:50%,)(

...

folder:s10083:50%,)(folder:s10101:50%,)(folder:s10080:50%,)(folder:s10075:50%,)(folder:s10099:50%,)(folder:

...

s10097:50%,)(folder:s10070:50%,)(folder:s10095:50%,)(folder:s10064:50%,)(folder:s10091:50%,)userName=John Doeskin=spring(channel:n10077:false,)(channel:n10058:false,)

<ulayout-mgr-cache-key>

...

7885417921252830597

How each value is obtained:

1. <person-id>: 399820

  • an integer identifier - obtained from the UserInstance instance:
    getPerson().getID()

2. <req-method-node-id>: userLayoutRootNode

  • obtained as follows:
    (new UPFileSpec(req)).getMethodNodeId()

where the req is the HttpServletRequest. For example:

...

3. <upref-cache-key>: system1activeTab=1userLayoutRoot=rootnewNodeID=authenticated=true(folder:s10087:50%,)(folder:s10057:50%,)(fold
er:s10083:50%,)(folder:s10101:50%,)(folder:s10080:50%,)(folder:s10075:50%,)(folder:s10099:50%,)(folder:s10097:
50%,)(folder:s10070:50%,)(folder:s10095:50%,)(folder:s10064:50%,)(folder:s10091:50%,)userName=John Doeskin=spring(channel:n10077:false,)(channel:n10058:false,)

  • definition in UserPreferences.java, obtained by:
    uPreferencesManager.getUserPreferences().getCacheKey()

defined as follows:
[UPC:system]<profile-id><structure-upref><theme-upref>

For the example above:
[UPC:system]: system

<profile-id>: 1

...

<theme-upref>: userName=JohnDoeskin=spring(channel:n10077:false,)(channel:n10058:false,)

a. [UPC:system] an optional String value ("system") prepended to System profiles

b. <profile-id>

  • integer defined in UserProfile.getProfileId()

c. <structure-upref>

  • a concatentation of cache keys from StructureStylesheetUserPreferences.getCacheKey()
    and it's super-classes:

<str-stylesh-upref><str-theme-stylesh-upref><str-struct-stylesh-upref>

i. <str-stylesh-upref>: activeTab=1userLayoutRoot=rootnewNodeID=authenticated=true

  • defined in: StylesheetUserPreferences.getCacheKey()

ii. <str-theme-stylesh-upref>: (None found in example: otherwise, would look like (channel:nnnnn:false,)

  • defined in: ThemeStylesheetUserPreferences.getCacheKey()

iii. <str-struct-stylesh-upref>:
(folder:s10087:50%,)(folder:s10057:50%,)(folder:s10083:50%,)(folder:s10101:50%,)(folder:s10080:50%,)(folder:
s10075:50%,)(folder:s10099:50%,)(folder:s10097:50%,)(folder:s10070:50%,)(folder:s10095:50%,)(folder:s10064:
50%,)(folder:s10091:50%,)

  • defined in: StructureStylesheetUserPreferences.getCacheKey()

d. <theme-upref>

  • a concatenation of cache keys from ThemeStylesheetUserPreferences.getCacheKey()

<thm-stylesh-upref><thm-theme-stylesh-upref>

i. <thm-stylesh-upref>: userName=John Doeskin=spring

  • defined in: StylesheetUserPreferences.getCacheKey()

ii. <thm-theme-stylesh-upref>: (channel:n10077:false,)(channel:n10058:false,)

  • defined in: ThemeStylesheetUserPreferences.getCacheKey()

4. <ulayout-mgr-cache-key>: 7885417921252830597

  • defined in SimpleUserLayoutManager.getCacheKey() - it is a random long

Notes

I believe there are thread contention issues with these two variables (systemCache UP-1145 and systemCharacterCache) since both are not synchronized and reads and updates are not made within the synchronized blocks either.

...

Code Block
xml
xml
titleExample systemCharacterCache markup

...


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

...


<html lang="en" xml:lang="en"

...

><head><title>myRutgers</title><meta content="text/html; charset=iso-8859-1" http-equiv="content-type" /

...

><link type="image/x-icon" href="favicon.ico" rel="Shortcut Icon" /

...

><link type="text/css" href="media/edu/rutgers/acs/portal/layout/tab-column/rutgers-theme/myrutgers1/skin/myrutgers1.css" rel="stylesheet" /

...

></head><body><div id="portal-page-header"

...

><div id="logo"

...

><img alt="myRutgers Logo" src="media/edu/rutgers/acs/portal/layout/tab-column/rutgers-theme/myrutgers1/institutional/uportal_logo_grid.gif" height="60" width="255" /

...

></div>

...



<div id="tabs"

...

><ul><li><a href="tag.90299c0feb91b440.render.userLayoutRootNode.uP?uP_root=root&amp;uP_sparam=activeTab&amp;activeTab=1"

...

><span>Everyday</span></a></li><li><a href="tag.90299c0feb91b440.render.userLayoutRootNode.uP?uP_root=root&amp;uP_sparam=activeTab&amp;activeTab=2"

...

><span>Libraries</span></a></li><li id="active-tab"

...

><a href="tag.90299c0feb91b440.render.userLayoutRootNode.uP?uP_root=root&amp;uP_sparam=activeTab&amp;activeTab=3"

...

><span>Campus Life</

...

span></a></li><li><a href="tag.90299c0feb91b440.render.userLayoutRootNode.uP?uP_root=root&amp;uP_sparam=activeTab&amp;activeTab=4"

...

><span>Administration</span></a></li><li><a href="tag.90299c0feb91b440.render.userLayoutRootNode.uP?uP_root=root&amp;uP_sparam=activeTab&amp;activeTab=5"

...

><span>Reporting Tools</

...

span></a></li><li><a href="tag.90299c0feb91b440.render.userLayoutRootNode.uP?uP_root=root&amp;uP_sparam=activeTab&amp;activeTab=6"

...

><span>myTab</span></a></li></ul></div></div><div id="portal-page-body"

...

><table width="100%" cellspacing="15" cellpadding="0"

...

><tr><td valign="top" width="50%"

...

><div class="portlet-toolbar"

...

><div><a href="tag.90299c0feb91b440.render.userLayoutRootNode.uP?uP_tcattr=minimized&amp;minimized_channelId=n10081&amp;minimized_n10081_value=true#n10081"

...

><img title="shade" alt="shade" height="19" width="19" src="media/edu/rutgers/acs/portal/layout/tab-column/rutgers-theme/myrutgers1/controls/max.gif" /

...

></a><a href="tag.90299c0feb91b440.render.userLayoutRootNode.uP?uP_root=n10081"

...

><img title="maximize" alt="maximize" height="19" width="19" src="media/edu/rutgers/acs/portal/layout/tab-column/rutgers-theme/myrutgers1/controls/focus.gif" /

...

></a><a onclick="return confirm('Are you sure you want to remove this channel?')" href="tag.90299c0feb91b440.render.userLayoutRootNode.uP?uP_remove_target=n10081"

...

><img title="remove" alt="remove" height="19" width="19" src="media/edu/rutgers/acs/portal/layout/tab-column/rutgers-theme/myrutgers1/controls/remove.gif" /

...

></a></div><a name="n10081"

...

><h2 id="n10081">Maps and Buildings</

...

h2></a></div><div class="portlet clearfix">

...


</

...

div><div class="portlet-toolbar"

...

><div><a href="tag.90299c0feb91b440.render.userLayoutRootNode.uP?uP_tcattr=minimized&amp;minimized_channelId=n10082&amp;minimized_n10082_value=true#n10082"

...

><img title="shade" alt="shade" height="19" width="19" src="media/edu/rutgers/acs/portal/layout/tab-column/rutgers-theme/myrutgers1/controls/max.gif" /

...

></a><a href="tag.90299c0feb91b440.render.userLayoutRootNode.uP?uP_root=n10082"

...

><img title="maximize" alt="maximize" height="19" width="19" src="media/edu/rutgers/acs/portal/layout/tab-column/rutgers-theme/myrutgers1/controls/focus.gif" /

...

></a><a onclick="return confirm('Are you sure you want to remove this channel?')" href="tag.90299c0feb91b440.render.userLayoutRootNode.uP?uP_remove_target=n10082"

...

><img title="remove" alt="remove" height="19" width="19" src="media/edu/rutgers/acs/portal/layout/tab-column/rutgers-theme/myrutgers1/controls/remove.gif" /

...

></a></div><a name="n10082"

...

><h2 id="n10082">Athletics</

...

h2></a></div><div class="portlet clearfix">

...


</

...

div></td><td valign="top" width="50%"

...

><div class="portlet-toolbar"

...

><div><a href="tag.90299c0feb91b440.render.userLayoutRootNode.uP?uP_tcattr=minimized&amp;minimized_channelId=n10084&amp;minimized_n10084_value=true#n10084"

...

><img title="shade" alt="shade" height="19" width="19" src="media/edu/rutgers/acs/portal/layout/tab-column/rutgers-theme/myrutgers1/controls/max.gif" /

...

></a><a href="tag.90299c0feb91b440.render.userLayoutRootNode.uP?uP_root=n10084"

...

><img title="maximize" alt="maximize" height="19" width="19" src="media/edu/rutgers/acs/portal/layout/tab-column/rutgers-theme/myrutgers1/controls/focus.gif" /

...

></a><a onclick="return confirm('Are you sure you want to remove this channel?')" href="tag.90299c0feb91b440.render.userLayoutRootNode.uP?uP_remove_target=n10084"

...

><img title="remove" alt="remove" height="19" width="19" src="media/edu/rutgers/acs/portal/layout/tab-column/rutgers-theme/myrutgers1/controls/remove.gif" /

...

></a></div><a name="n10084"

...

><h2 id="n10084">Parking/Transportation</

...

h2></a></div><div class="portlet clearfix">

...


</

...

div><div class="portlet-toolbar"

...

><div><a href="tag.90299c0feb91b440.render.userLayoutRootNode.uP?uP_tcattr=minimized&amp;minimized_channelId=n10085&amp;minimized_n10085_value=true#n10085"

...

><img title="shade" alt="shade" height="19" width="19" src="media/edu/rutgers/acs/portal/layout/tab-column/rutgers-theme/myrutgers1/controls/max.gif" /

...

></a><a href="tag.90299c0feb91b440.render.userLayoutRootNode.uP?uP_root=n10085"

...

><img title="maximize" alt="maximize" height="19" width="19" src="media/edu/rutgers/acs/portal/layout/tab-column/rutgers-theme/myrutgers1/controls/focus.gif" /

...

></a><a onclick="return confirm('Are you sure you want to remove this channel?')" href="tag.90299c0feb91b440.render.userLayoutRootNode.uP?uP_remove_target=n10085"

...

><img title="remove" alt="remove" height="19" width="19" src="media/edu/rutgers/acs/portal/layout/tab-column/rutgers-theme/myrutgers1/controls/remove.gif" /

...

></a></div><a name="n10085"

...

><h2 id="n10085">Buses/Shuttles</

...

h2></a></div><div class="portlet clearfix">

...



</

...

div></td></tr></table></div><div id="portal-page-footer"

...

><div><a href="http://www.rutgers.edu/" target="_blank"

...

><img src="media/edu/rutgers/acs/portal/layout/tab-column/rutgers-theme/myrutgers/institutional/rutgers_footer_logo.gif" title="Go to Rutgers home page" alt="Rutgers Logo" height="30" width="99" /

...

></a></div><p>
					Links to campus web sites:
					<a href="http://camden-www.rutgers.edu/" target="_blank">Camden</a>

...

,
					<a href="http://rutgers-newark.rutgers.edu/" target="_blank">Newark</a>

...

,
					<a href="http://nbp.rutgers.edu/" target="_blank">New Brunswick/Piscataway</a>

...

,
					<a href="http://www.rutgers.edu/" target="_blank">Rutgers University</a>

...

.
<br />

...

.
					<br />
					For assistance, contact the Help Desks in:
					<a href="http://rucs.camden.rutgers.edu/" target="_blank">Camden</a>

...

,
					<a href="http://www.ncs.rutgers.edu/helpdesk/" target="_blank">Newark</a>

...

,

...

 or
					<a href="http://www.nbcs.rutgers.edu/helpdesk/hdnew/" target="_blank">New Brunswick/Piscataway</a>

...

.
				</

...

p></div></body></html>