You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2007/12/19 22:03:29 UTC
svn commit: r605695 - in /portals/jetspeed-2/branches/JETSPEED-2.1.3:
components/prefs/src/java/org/apache/jetspeed/prefs/impl/PersistenceBrokerPreferencesProvider.java
etc/schema/prefs-schema.xml src/webapp/WEB-INF/assembly/prefs.xml
Author: taylor
Date: Wed Dec 19 13:03:28 2007
New Revision: 605695
URL: http://svn.apache.org/viewvc?rev=605695&view=rev
Log:
https://issues.apache.org/jira/browse/JS2-786
Addressing preferences performance with:
1. indexes: see prefs-schema.xml. With tests of 10,000 prefs, this sped up retrieval 700%
2. preload feature: see prefs.xml, ability to preload prefs into cache by Portlet App or by entities (all or none)
Modified:
portals/jetspeed-2/branches/JETSPEED-2.1.3/components/prefs/src/java/org/apache/jetspeed/prefs/impl/PersistenceBrokerPreferencesProvider.java
portals/jetspeed-2/branches/JETSPEED-2.1.3/etc/schema/prefs-schema.xml
portals/jetspeed-2/branches/JETSPEED-2.1.3/src/webapp/WEB-INF/assembly/prefs.xml
Modified: portals/jetspeed-2/branches/JETSPEED-2.1.3/components/prefs/src/java/org/apache/jetspeed/prefs/impl/PersistenceBrokerPreferencesProvider.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/components/prefs/src/java/org/apache/jetspeed/prefs/impl/PersistenceBrokerPreferencesProvider.java?rev=605695&r1=605694&r2=605695&view=diff
==============================================================================
--- portals/jetspeed-2/branches/JETSPEED-2.1.3/components/prefs/src/java/org/apache/jetspeed/prefs/impl/PersistenceBrokerPreferencesProvider.java (original)
+++ portals/jetspeed-2/branches/JETSPEED-2.1.3/components/prefs/src/java/org/apache/jetspeed/prefs/impl/PersistenceBrokerPreferencesProvider.java Wed Dec 19 13:03:28 2007
@@ -18,13 +18,19 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
import java.util.Vector;
import org.apache.jetspeed.cache.CacheElement;
import org.apache.jetspeed.cache.DistributedCacheObject;
import org.apache.jetspeed.cache.JetspeedCache;
import org.apache.jetspeed.components.dao.InitablePersistenceBrokerDaoSupport;
+import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
+import org.apache.jetspeed.om.common.portlet.MutablePortletEntity;
import org.apache.jetspeed.prefs.FailedToCreateNodeException;
import org.apache.jetspeed.prefs.NodeAlreadyExistsException;
import org.apache.jetspeed.prefs.NodeDoesNotExistException;
@@ -48,7 +54,7 @@
public class PersistenceBrokerPreferencesProvider extends InitablePersistenceBrokerDaoSupport implements
PreferencesProvider
{
-
+
private static class NodeCache implements DistributedCacheObject
{
/** The serial uid. */
@@ -165,15 +171,12 @@
}
private JetspeedCache preferenceCache;
-
+ private List preloadedApplications;
+ private boolean preloadEntities = false;
/**
- * @param repository
+ * @param repositoryPath
* Location of repository mapping file. Must be available within the classpath.
- * @param prefsFactoryImpl
- * <code>java.util.prefs.PreferencesFactory</code> implementation to use.
- * @param enablePropertyManager
- * Whether or not we chould be suing the property manager.
* @throws ClassNotFoundException
* if the <code>prefsFactoryImpl</code> argument does not reperesent a Class that exists in the
* current classPath.
@@ -183,8 +186,10 @@
{
super(repositoryPath);
NodeImplProxy.setProvider(this);
+ this.preloadedApplications = new LinkedList();
}
+
/**
* @param repository
* Location of repository mapping file. Must be available within the classpath.
@@ -203,6 +208,15 @@
this.preferenceCache = preferenceCache;
}
+ public PersistenceBrokerPreferencesProvider(String repositoryPath, JetspeedCache preferenceCache, List apps, boolean preloadEntities)
+ throws ClassNotFoundException
+ {
+ this(repositoryPath);
+ this.preferenceCache = preferenceCache;
+ this.preloadedApplications = apps;
+ this.preloadEntities = preloadEntities;
+ }
+
protected void addToCache(NodeCache content)
{
CacheElement cachedElement = preferenceCache.createElement(content.getCacheKey(), content);
@@ -522,6 +536,104 @@
public Property createProperty(Node node, String name, Object value)
{
return new PropertyImpl(node.getNodeId(), name, value);
+ }
+
+ public void init() throws Exception
+ {
+ super.init();
+ Iterator apps = this.preloadedApplications.iterator();
+ while (apps.hasNext())
+ {
+ String appName = (String)apps.next();
+ preloadApplicationPreferences(appName);
+ }
+ if (preloadEntities)
+ preloadAllEntities();
+ }
+
+ public void preloadApplicationPreferences(String portletApplicationName) throws NodeDoesNotExistException
+ {
+ String portletDefPrefPath = "/" + MutablePortletApplication.PREFS_ROOT + "/" + portletApplicationName + "/";
+// + PortletDefinitionComposite.PORTLETS_PREFS_ROOT + "/" + portlet.getName() + "/"
+// + MutablePortletApplication.PORTLET_PREFERENCES_ROOT;
+// NodeCache key = new NodeCache(portletDefPrefPath, 1);
+// NodeCache hit = getNode(key.getCacheKey());
+// if (hit != null)
+// {
+// return 1;
+// //return hit.getNode();
+// }
+ long start = System.currentTimeMillis();
+ int count = loadNodeAndAllChildren(portletDefPrefPath);
+ long elapsed = System.currentTimeMillis() - start;
+ System.out.println("++++ PREFS:PA loaded " + count + " pref nodes for app " + portletDefPrefPath + " in " + elapsed + " milliseconds.");
+ }
+
+ protected int loadNodeAndAllChildren(String path)
+ {
+ int count = 0;
+ NodeCache root = null;
+ Criteria c = new Criteria();
+ c.addLike("fullPath", path + "%");
+ //c.addOrderBy("fullPath");
+ Query query = QueryFactory.newQuery(NodeImpl.class, c);
+ Collection result = getPersistenceBrokerTemplate().getCollectionByQuery(query);
+ // TODO: ensure that we always get the first node back first
+ if (result == null || result.isEmpty())
+ {
+ return count;
+ }
+ Iterator ri = result.iterator();
+ if (ri.hasNext())
+ {
+ Node n = (Node)ri.next();
+ NodeImplProxy proxy = new NodeImplProxy(n);
+ root = new NodeCache(proxy);
+ addToCache(root);
+ count++;
+ }
+ else
+ {
+ return count;
+ }
+ Map parents = new HashMap();
+ parents.put(new Long(root.getNode().getNodeId()), root);
+ while (ri.hasNext())
+ {
+ // build children and subchildren
+ Node subNode = (Node)ri.next();
+ //System.out.println("*** Preloading: " + subNode.getFullPath());
+ // add to current node
+ NodeCache nodeKey = new NodeCache(subNode.getFullPath(), subNode.getNodeType());
+ NodeCache lookup = getNode(nodeKey.getCacheKey());
+ if (lookup == null)
+ {
+ NodeImplProxy proxy = new NodeImplProxy(subNode);
+ nodeKey.setNode(proxy);
+ addToCache(nodeKey);
+ lookup = nodeKey;
+ }
+ NodeCache parent = (NodeCache)parents.get(subNode.getParentNodeId());
+ if (parent != null)
+ {
+ if (parent.getChildren() == null)
+ parent.setChildren(new ArrayList());
+ parent.getChildren().add(lookup.getCacheKey());
+ count += parent.getChildren().size();
+ }
+ parents.put(new Long(subNode.getNodeId()), lookup);
+ count++;
+ }
+ return count;
+ }
+
+ public void preloadAllEntities() throws NodeDoesNotExistException
+ {
+ String entitiesRoot = "/" + MutablePortletEntity.PORTLET_ENTITY_ROOT + "/";
+ long start = System.currentTimeMillis();
+ int count = loadNodeAndAllChildren(entitiesRoot);
+ long elapsed = System.currentTimeMillis() - start;
+ System.out.println("++++ PREFS:ENTITIES loaded " + count + " total entity pref nodes in " + elapsed + " milliseconds.");
}
}
Modified: portals/jetspeed-2/branches/JETSPEED-2.1.3/etc/schema/prefs-schema.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/etc/schema/prefs-schema.xml?rev=605695&r1=605694&r2=605695&view=diff
==============================================================================
--- portals/jetspeed-2/branches/JETSPEED-2.1.3/etc/schema/prefs-schema.xml (original)
+++ portals/jetspeed-2/branches/JETSPEED-2.1.3/etc/schema/prefs-schema.xml Wed Dec 19 13:03:28 2007
@@ -18,23 +18,6 @@
<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_2.dtd">
<!-- Autogenerated by JDBCToXMLSchema! -->
<database name="j2">
-
- <!--
- prefs_property_value
- -->
- <table name="PREFS_PROPERTY_VALUE">
- <column name="PROPERTY_VALUE_ID" primaryKey="true" required="true" type="INTEGER"/>
- <column name="NODE_ID" type="INTEGER"/>
- <column name="PROPERTY_NAME" size="100" type="VARCHAR"/>
- <column name="PROPERTY_VALUE" size="254" type="VARCHAR"/>
- <column name="CREATION_DATE" type="TIMESTAMP"/>
- <column name="MODIFIED_DATE" type="TIMESTAMP"/>
- <!-- Still an issue with OJB 1.0.3 when deleting M-N. Foreign Key Violation.
- <foreign-key foreignTable="PREFS_NODE">
- <reference foreign="NODE_ID" local="NODE_ID"/>
- </foreign-key>
- -->
- </table>
<!--
pref_node
@@ -47,9 +30,36 @@
<column name="FULL_PATH" size="254" type="VARCHAR"/>
<column name="CREATION_DATE" type="TIMESTAMP"/>
<column name="MODIFIED_DATE" type="TIMESTAMP"/>
- <foreign-key foreignTable="PREFS_NODE" name="FK_PREFS_NODE_1">
+ <foreign-key foreignTable="PREFS_NODE" name="FK_PREFS_NODE_1" onDelete="cascade">
<reference foreign="NODE_ID" local="PARENT_NODE_ID"/>
- </foreign-key>
+ </foreign-key>
+ <index name="IX_PREFS_NODE_1">
+ <index-column name="PARENT_NODE_ID"/>
+ </index>
+ <index name="IX_PREFS_NODE_2">
+ <index-column name="FULL_PATH"/>
+ </index>
</table>
-
+ <!--
+ prefs_property_value
+ -->
+ <table name="PREFS_PROPERTY_VALUE">
+ <column name="PROPERTY_VALUE_ID" primaryKey="true" required="true" type="INTEGER"/>
+ <column name="NODE_ID" type="INTEGER"/>
+ <column name="PROPERTY_NAME" size="100" type="VARCHAR"/>
+ <column name="PROPERTY_VALUE" size="254" type="VARCHAR"/>
+ <column name="CREATION_DATE" type="TIMESTAMP"/>
+ <column name="MODIFIED_DATE" type="TIMESTAMP"/>
+ <!-- Still an issue with OJB 1.0.3 when deleting M-N. Foreign Key Violation.
+ 2007/12/13 - DST - I've been testing with this index enabled on Oracle, MySQL
+ and experiencing no issues. I think the index on should be the default case,
+ and inferior databases will have to turn it off as part of the integration process
+ -->
+ <foreign-key foreignTable="PREFS_NODE" onDelete="cascade">
+ <reference foreign="NODE_ID" local="NODE_ID" />
+ </foreign-key>
+ <index name="IX_FKPPV_1">
+ <index-column name="NODE_ID"/>
+ </index>
+ </table>
</database>
Modified: portals/jetspeed-2/branches/JETSPEED-2.1.3/src/webapp/WEB-INF/assembly/prefs.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/src/webapp/WEB-INF/assembly/prefs.xml?rev=605695&r1=605694&r2=605695&view=diff
==============================================================================
--- portals/jetspeed-2/branches/JETSPEED-2.1.3/src/webapp/WEB-INF/assembly/prefs.xml (original)
+++ portals/jetspeed-2/branches/JETSPEED-2.1.3/src/webapp/WEB-INF/assembly/prefs.xml Wed Dec 19 13:03:28 2007
@@ -26,6 +26,14 @@
<constructor-arg index="1">
<ref bean="preferencesCache" />
</constructor-arg>
+ <!-- list of portlet applications default preferences to preload, leave list empty to not preload -->
+ <constructor-arg index='2'>
+ <list>
+ <value>j2-admin</value>
+ </list>
+ </constructor-arg>
+ <!-- preload ALL Entities: warning this can chew up lots of memory -->
+ <constructor-arg index='3'><value type="boolean">false</value></constructor-arg>
</bean>
<bean id="org.apache.jetspeed.prefs.PreferencesProvider" parent="baseTransactionProxy" name="prefsProvider">
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org