Author: burton Date: Fri Mar 18 15:07:31 2005 New Revision: 158157 URL: http://svn.apache.org/viewcvs?view=rev&rev=158157 Log: Fixed a bug due to a threading issue corrupting a HashSet.. we now use a mutex...
Modified: jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/rrd/GraphTask.java Modified: jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/rrd/GraphTask.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/rrd/GraphTask.java?view=diff&r1=158156&r2=158157 ============================================================================== --- jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/rrd/GraphTask.java (original) +++ jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/rrd/GraphTask.java Fri Mar 18 15:07:31 2005 @@ -37,6 +37,13 @@ public class GraphTask extends Thread { /** + * RRD 1.4 has a bug where they use a HashSet internall to keep track of + * open writers which causes threads to screw up so we need to synchronize a + * mutex. Since this is just disk IO it should be OK. + */ + public static final Object RRD_MUTEX = new Object(); + + /** * True when we should generate tasks within the current process. */ public static boolean ENABLE_GENERATE_GRAPHS=true; @@ -208,7 +215,8 @@ graph.saveAsPNG( path ); System.out.println( "Generating graph: " + path + " ...done" ); - + //graph.close(); + } /** @@ -219,56 +227,60 @@ */ private void doCreateRRD() throws Exception { - new File( ROOT ).mkdirs(); + synchronized( RRD_MUTEX ) { - System.out.println( "Creating rrd file: " + rrd_path ); + new File( ROOT ).mkdirs(); - RrdDef rrdDef = new RrdDef( rrd_path ); - rrdDef.setStartTime( begin ); + System.out.println( "Creating rrd file: " + rrd_path ); + + RrdDef rrdDef = new RrdDef( rrd_path ); + rrdDef.setStartTime( begin ); - rrdDef.addDatasource( "speed", - "GAUGE", - GraphTaskRunner.COUNTER_INTERVAL_SECONDS, - Double.NaN, - Double.NaN ); + rrdDef.addDatasource( "speed", + "GAUGE", + GraphTaskRunner.COUNTER_INTERVAL_SECONDS, + Double.NaN, + Double.NaN ); - //set the step to 1 minute (the default is 5 minutes). - rrdDef.setStep( GraphTaskRunner.COUNTER_INTERVAL_SECONDS ); + //set the step to 1 minute (the default is 5 minutes). + rrdDef.setStep( GraphTaskRunner.COUNTER_INTERVAL_SECONDS ); - //keep one measurement for every single poll. + //keep one measurement for every single poll. - //rrdDef.addArchive( "AVERAGE", 0.5, 1, 3600 ); + //rrdDef.addArchive( "AVERAGE", 0.5, 1, 3600 ); - //rrdDef.addArchive( "AVERAGE", 0.5, 1, 60 ); + //rrdDef.addArchive( "AVERAGE", 0.5, 1, 60 ); - //FIXME: increase this to about 400... because this would yield a much - //higher density image. + //FIXME: increase this to about 400... because this would yield a much + //higher density image. - //6 hours (6 minute intervals... with 60 measurements which yields 360 - //minutes which is 6 hours). + //6 hours (6 minute intervals... with 60 measurements which yields 360 + //minutes which is 6 hours). - rrdDef.addArchive( "AVERAGE", 0.5, 1, 360 ); + rrdDef.addArchive( "AVERAGE", 0.5, 1, 360 ); - //12 hours - rrdDef.addArchive( "AVERAGE", 0.5, 2, 360 ); + //12 hours + rrdDef.addArchive( "AVERAGE", 0.5, 2, 360 ); - //24 hours - rrdDef.addArchive( "AVERAGE", 0.5, 4, 360 ); + //24 hours + rrdDef.addArchive( "AVERAGE", 0.5, 4, 360 ); - //1 week - rrdDef.addArchive( "AVERAGE", 0.5, 28, 360 ); + //1 week + rrdDef.addArchive( "AVERAGE", 0.5, 28, 360 ); - //1 month - rrdDef.addArchive( "AVERAGE", 0.5, 120, 360 ); + //1 month + rrdDef.addArchive( "AVERAGE", 0.5, 120, 360 ); - //1 year - rrdDef.addArchive( "AVERAGE", 0.5, 1460, 360 ); + //1 year + rrdDef.addArchive( "AVERAGE", 0.5, 1460, 360 ); - //FIXME: don't we need additional archives here? + //FIXME: don't we need additional archives here? - RrdDb rrdDb = new RrdDb( rrdDef ); - rrdDb.close(); + RrdDb rrdDb = new RrdDb( rrdDef ); + rrdDb.close(); + } + } /** @@ -281,33 +293,38 @@ if ( file.exists() == false ) { doCreateRRD(); } + + synchronized( RRD_MUTEX ) { - RrdDb rrdDb = new RrdDb( rrd_path ); - Sample sample = rrdDb.createSample(); + RrdDb rrdDb = new RrdDb( rrd_path ); + Sample sample = rrdDb.createSample(); - try { + try { - long v = source.getValue(); + long v = source.getValue(); - //NOTE: this is the correct mechanism but it might be off by a bit due - //to skew with running getValue() from diff impls... - //lastUpdatedSeconds = currentTimeSeconds(); + //NOTE: this is the correct mechanism but it might be off by a bit due + //to skew with running getValue() from diff impls... + //lastUpdatedSeconds = currentTimeSeconds(); - lastUpdatedSeconds += GraphTaskRunner.COUNTER_INTERVAL_SECONDS; + lastUpdatedSeconds += GraphTaskRunner.COUNTER_INTERVAL_SECONDS; - String time = formatTime( lastUpdatedSeconds ); + String time = formatTime( lastUpdatedSeconds ); - System.out.println( "time: " + time + " , " + unit_name + " value: " + v ); - System.out.println( "lastUpdated: " + lastUpdatedSeconds ); + System.out.println( "time: " + time + " , " + unit_name + " value: " + v ); + System.out.println( "lastUpdated: " + lastUpdatedSeconds ); - sample.setAndUpdate( lastUpdatedSeconds + ":" + v ); + sample.setAndUpdate( lastUpdatedSeconds + ":" + v ); + //sample.close(); + + } finally { - } finally { + rrdDb.sync(); + rrdDb.close(); + } - rrdDb.sync(); - rrdDb.close(); } - + } /** @@ -336,5 +353,4 @@ } } } - } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]