← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4905: Finer control over buffering the output of mydatamart export

 

------------------------------------------------------------
revno: 4905
committer: Bob Jolliffe bobjolliffe@xxxxxxxxx
branch nick: dhis2
timestamp: Wed 2011-10-12 10:47:13 +0100
message:
  Finer control over buffering the output of mydatamart export
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.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-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java	2011-03-22 17:29:14 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/synchronous/ExportPivotViewService.java	2011-10-12 09:47:13 +0000
@@ -61,6 +61,11 @@
 {
     private static final Log log = LogFactory.getLog( ExportPivotViewService.class );
 
+    // The number of values to buffer before forcing attempt to flush
+    // Ideally this value should be set to a number of bytes say twice the size of the underlying buffer
+    // 500 is just a conservative thumbsuck
+    private static final int CHUNK = 500;
+
     // service can export either aggregated datavalues or aggregated indicator values
     public enum RequestType
     {
@@ -185,6 +190,9 @@
         AggregatedDataValue adv = Iterator.next();
 
         writer.write( "# period, orgunit, dataelement, catoptcombo, value\n" );
+        
+        int values = 0;
+
         while ( adv != null )
         {
             int periodId = adv.getPeriodId();
@@ -196,6 +204,14 @@
             writer.write( adv.getCategoryOptionComboId() + "," );
             writer.write( adv.getValue() + "\n" );
 
+            // defend against expanding the writer buffer uncontrollably
+            values = ++values % CHUNK;
+
+            if (values == 0)
+            {
+                writer.flush();
+            }
+
             adv = Iterator.next();
         }
 
@@ -211,6 +227,8 @@
 
         writer.write( "# period, orgunit, indicator, factor, numerator, denominator\n" );
         
+        int values = 0;
+
         while ( aiv != null )
         {
             int periodId = aiv.getPeriodId();
@@ -223,6 +241,14 @@
             writer.write( MathUtils.roundToString( aiv.getNumeratorValue(), PRECISION ) + "," );
             writer.write( MathUtils.roundToString( aiv.getDenominatorValue(), PRECISION ) + "\n" );
 
+            // defend against expanding the writer buffer uncontrollably
+            values = ++values % CHUNK;
+
+            if (values == 0)
+            {
+                writer.flush();
+            }
+
             aiv = Iterator.next();
         }