dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #17131
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6720: Data mart, minor memory optimization
------------------------------------------------------------
revno: 6720
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-04-24 14:14:22 +0200
message:
Data mart, minor memory optimization
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitHierarchy.java
dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitHierarchyTest.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitHierarchy.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitHierarchy.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitHierarchy.java 2012-04-24 12:14:22 +0000
@@ -45,6 +45,9 @@
*/
public class OrganisationUnitHierarchy
{
+ /**
+ * Contains mappings between parent and immediate children.
+ */
private Map<Integer, Set<Integer>> relationships = new HashMap<Integer, Set<Integer>>();
private Map<Integer, Set<Integer>> subTrees = new HashMap<Integer, Set<Integer>>();
@@ -148,7 +151,7 @@
List<Integer> children = new ArrayList<Integer>();
- children.add( 0, parentId );
+ children.add( 0, parentId ); // Adds parent id to beginning of list
int childCounter = 1;
@@ -169,8 +172,10 @@
public Set<Integer> getChildren( Collection<Integer> parentIds )
{
- Set<Integer> children = new HashSet<Integer>();
+ int capacity = parentIds.size() + 5;
+ Set<Integer> children = new HashSet<Integer>( Math.max( capacity, 16 ) );
+
for ( Integer id : parentIds )
{
children.addAll( getChildren( id ) );
@@ -218,7 +223,9 @@
return getChildren( parentIds );
}
- Set<Integer> children = new HashSet<Integer>();
+ int capacity = ( parentIds.size() * groups.size() ) + 5;
+
+ Set<Integer> children = new HashSet<Integer>( Math.max( capacity, 16 ) );
for ( Integer id : parentIds )
{
=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitHierarchyTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitHierarchyTest.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitHierarchyTest.java 2012-04-24 12:14:22 +0000
@@ -30,6 +30,7 @@
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.assertNotNull;
import java.util.ArrayList;
import java.util.HashMap;
@@ -112,6 +113,35 @@
}
@Test
+ public void testGetChildren()
+ {
+ Set<Integer> parentIds = new HashSet<Integer>();
+
+ List<OrganisationUnitRelationship> relations = new ArrayList<OrganisationUnitRelationship>();
+
+ int parentMax = 1000; // Increase to stress-test
+ int childMax = 4;
+ int childId = 0;
+
+ for ( int parentId = 0; parentId < parentMax; parentId++ )
+ {
+ parentIds.add( parentId );
+
+ for ( int j = 0; j < childMax; j++ )
+ {
+ relations.add( new OrganisationUnitRelationship( parentId, ++childId ) );
+ }
+ }
+
+ OrganisationUnitHierarchy hierarchy = new OrganisationUnitHierarchy( relations );
+
+ Set<Integer> children = hierarchy.getChildren( parentIds );
+
+ assertNotNull( children );
+ assertEquals( ( parentMax * childMax ) + 1, children.size() );
+ }
+
+ @Test
public void testGetChildrenA()
{
List<OrganisationUnitRelationship> relationships = new ArrayList<OrganisationUnitRelationship>();
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java 2012-04-12 12:39:47 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java 2012-04-24 12:14:22 +0000
@@ -217,6 +217,8 @@
organisationUnitIds = organisationUnitIds != null ? organisationUnitIds : new ArrayList<Integer>();
organisationUnitGroupIds = organisationUnitGroupIds != null ? organisationUnitGroupIds : new ArrayList<Integer>();
+ clock.logTime( "Data elements: " + dataElementIds.size() + ", indicators: " + indicatorIds.size() + ", periods: " + periodIds.size() + ", org units: " + organisationUnitIds.size() );
+
// ---------------------------------------------------------------------
// Get objects
// ---------------------------------------------------------------------