Author: chirino Date: Fri Nov 17 12:17:15 2006 New Revision: 476297 URL: http://svn.apache.org/viewvc?view=rev&rev=476297 Log: Made PerfRate a more thread safe.
Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/PerfConsumer.java incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/PerfProducer.java incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/PerfRate.java incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/SimpleTopicTest.java Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/PerfConsumer.java URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/PerfConsumer.java?view=diff&rev=476297&r1=476296&r2=476297 ============================================================================== --- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/PerfConsumer.java (original) +++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/PerfConsumer.java Fri Nov 17 12:17:15 2006 @@ -51,7 +51,7 @@ } public void start() throws JMSException{ connection.start(); - rate.getRate(); + rate.reset(); } public void stop() throws JMSException{ connection.stop(); Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/PerfProducer.java URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/PerfProducer.java?view=diff&rev=476297&r1=476296&r2=476297 ============================================================================== --- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/PerfProducer.java (original) +++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/PerfProducer.java Fri Nov 17 12:17:15 2006 @@ -59,10 +59,10 @@ synchronized public void start() throws JMSException{ if( !running ) { + rate.reset(); running = true; connection.start(); new Thread(this).start(); - rate.reset(); } } public void stop() throws JMSException, InterruptedException{ Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/PerfRate.java URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/PerfRate.java?view=diff&rev=476297&r1=476296&r2=476297 ============================================================================== --- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/PerfRate.java (original) +++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/PerfRate.java Fri Nov 17 12:17:15 2006 @@ -21,9 +21,11 @@ * @version $Revision: 1.3 $ */ public class PerfRate{ + protected int totalCount; protected int count; protected long startTime=System.currentTimeMillis(); + /** * @return Returns the count. */ @@ -31,7 +33,7 @@ return totalCount; } - public void increment(){ + synchronized public void increment(){ totalCount++; count++; } @@ -41,6 +43,19 @@ long totalTime=endTime-startTime; int result=(int) ((count*1000)/totalTime); return result; + } + + /** + * Resets the rate sampling. + */ + synchronized public PerfRate cloneAndReset() { + PerfRate rc = new PerfRate(); + rc.totalCount = totalCount; + rc.count=count; + rc.startTime=startTime; + count=0; + startTime=System.currentTimeMillis(); + return rc; } /** Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/SimpleTopicTest.java URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/SimpleTopicTest.java?view=diff&rev=476297&r1=476296&r2=476297 ============================================================================== --- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/SimpleTopicTest.java (original) +++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/perf/SimpleTopicTest.java Fri Nov 17 12:17:15 2006 @@ -43,10 +43,10 @@ //protected String bindAddress="vm://localhost"; protected PerfProducer[] producers; protected PerfConsumer[] consumers; - protected String DESTINATION_NAME=getClass().toString(); + protected String DESTINATION_NAME=getClass().getName(); protected int SAMPLE_COUNT = 30; protected long SAMPLE_INTERVAL = 2000; - protected int NUMBER_OF_CONSUMERS=1; + protected int NUMBER_OF_CONSUMERS=10; protected int NUMBER_OF_PRODUCERS=1; protected int PAYLOAD_SIZE=1024; protected byte[] array=null; @@ -163,27 +163,23 @@ int totalRate=0; int totalCount=0; for(int i=0;i<producers.length;i++){ - totalRate+=producers[i].getRate().getRate(); - totalCount+=producers[i].getRate().getTotalCount(); + PerfRate rate = producers[i].getRate().cloneAndReset(); + totalRate+=rate.getRate(); + totalCount+=rate.getTotalCount(); } int avgRate = totalRate/producers.length; log.info("Avg producer rate = "+avgRate+" msg/sec | Total rate = "+totalRate+", sent = "+totalCount); - for(int i=0;i<producers.length;i++){ - producers[i].getRate().reset(); - } } protected void dumpConsumerRate(){ int totalRate=0; int totalCount=0; for(int i=0;i<consumers.length;i++){ - totalRate+=consumers[i].getRate().getRate(); - totalCount+=consumers[i].getRate().getTotalCount(); + PerfRate rate = consumers[i].getRate().cloneAndReset(); + totalRate+=rate.getRate(); + totalCount+=rate.getTotalCount(); } int avgRate = totalRate/consumers.length; log.info("Avg consumer rate = "+avgRate+" msg/sec | Total rate = "+totalRate+", received = "+totalCount); - for(int i=0;i<consumers.length;i++){ - consumers[i].getRate().reset(); - } } }