[jboss-svn-commits] JBL Code SVN: r15557 - labs/jbossesb/trunk/product/samples/quickstarts/load_generator/scripts.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Oct 3 16:40:14 EDT 2007


Author: james.williams at jboss.com
Date: 2007-10-03 16:40:14 -0400 (Wed, 03 Oct 2007)
New Revision: 15557

Modified:
   labs/jbossesb/trunk/product/samples/quickstarts/load_generator/scripts/LoadReport.groovy
Log:
changed logic so it is less groovy hack-ish and more POJO friendly. Also switched to xml based config so more options
can be supported.

Modified: labs/jbossesb/trunk/product/samples/quickstarts/load_generator/scripts/LoadReport.groovy
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/load_generator/scripts/LoadReport.groovy	2007-10-03 20:40:05 UTC (rev 15556)
+++ labs/jbossesb/trunk/product/samples/quickstarts/load_generator/scripts/LoadReport.groovy	2007-10-03 20:40:14 UTC (rev 15557)
@@ -4,61 +4,177 @@
 import javax.naming.NamingException
 
 /**
- * Simple Groovy load script that will provide TPS statistics for a ESB service call.
+ * Simple Groovy load script that will provide TPS statistics for a ESB service call and JMS Queues.
  *
  * @author <a href="mailto:james.williams at redhat.com">james.williams at redhat.com</a>
  */
-def Properties props = new Properties()
-props.load(new File("load_generator_classes/load.properties").newInputStream())
-def File reportLog = new File(props.getProperty("logLocation") + "/esb-load-generator-" + new Date().getTime() + ".csv");
-def fastestServiceQueue = props.getProperty("fastestServiceQueue") 
-def serviceList = props.getProperty("serviceList").split(',')
-def esbArchive = props.getProperty("esbArchive")
-def tpsInterval = props.getProperty("tpsInterval").toInteger()
-def msgCount = props.getProperty("msgCount").toLong() * props.getProperty("batchCount").toLong()
-boolean done = false
-def statsMap = [:]
-def seconds = tpsInterval
+ 
+class ServiceMetricsBean 
+{
+	def tps
+	def tpsAvg
+	def duration	
+}
 
-serviceList.each {
-	service ->
-	statsMap."$service-TPS" = 0
-	statsMap."$service-TPSSum" = 0
+class QueueMetricsBean 
+{
+	def queueFactor
+	def queueFactorAvg
+	def queueFactorTotal
+	def duration
 }
 
-InitialContext ctx = new InitialContext(); // From jndi.properties
-MBeanServerConnection server = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor")
-reportLog.getParentFile().mkdirs()
-reportLog.append("Service, TPS, AVG TPS, Sample Count, Duration\n")
- 	
-while(!done) {	
-    println ""
-    serviceList.each {
- 		service ->
-		processedMsgsBefore = server.getAttribute(new ObjectName("jboss.esb:service-name=$service,deployment=$esbArchive,category=MessageCounter"), "overall service message count").toLong()
- 		sleep(tpsInterval*1000)
- 		processedMsgsAfter = server.getAttribute(new ObjectName("jboss.esb:service-name=$service,deployment=$esbArchive,category=MessageCounter"), "overall service message count").toLong()
- 		statsMap."$service-TPS" = processedMsgsAfter - processedMsgsBefore
- 		statsMap."$service-TPSSum" += statsMap."$service-TPS" 
- 		statsMap."$service-TPSAvg" = statsMap."$service-TPSSum" * tpsInterval / seconds
- 		
- 		long tps = statsMap."$service-TPS"
- 		long avgTPS = statsMap."$service-TPSAvg"
- 		long tpsSum = statsMap."$service-TPSSum" 		
- 		
- 		long duration =  seconds / 60
- 		println "Svc: $service, TPS: $tps, AVG TPS: $avgTPS, Samples: $tpsSum, Duration: $duration" 
- 		reportLog.append("$service, $tps, $avgTPS, $tpsSum, $duration \n")
- 		seconds += tpsInterval
- 		
- 		if (fastestServiceQueue != null)
- 		{
- 			queueDepthCheck = server.getAttribute(new ObjectName("$fastestServiceQueue"), "QueueDepth").toLong()
- 			if (queueDepthCheck == 0){
- 				done = true
- 			} 
- 		}				
- 	} 	 	
-}  
+class ReporterBean
+{
+	def fastestQueue
+	def tpsIntervalSeconds
+}
+
+class JmsReporterBean extends ReporterBean
+{
+	def queue
+}
+
+class ServiceReporterBean extends ReporterBean
+{
+	def serviceName
+	def esbArchiveName	
+}
+
+class LoadReport
+{
+	LoadUtil util = new LoadUtil()
+	def loadConfigFile
+	InitialContext ctx
+	MBeanServerConnection server
+	def svcStatsMap = [:]
+	def qStatsMap = [:]
+	def svcReportLog
+	def queueReportLog
+		
+	LoadReport(aLoadConfigFile)
+	{
+		loadConfigFile = aLoadConfigFile
+		ctx = new InitialContext(); // From jndi.properties
+		server = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor")
+	}
+
+   public generateMetrics()
+   {
+   		def loadScript = new XmlParser().parse(new File(loadConfigFile))
+   		createReportFiles(loadScript.'@log-directory')
+		boolean done = false
+		def startTime = new Date().getTime()
+		def qAggregateMap = [:]
+		def svcAggregateMap = [:]
+		def times = 0
+		while(!done)
+		{					
+			times++	
+			
+			loadScript.'reporters'.'jms-reporters'.'jms-reporter'.each
+			{
+				jmsReporter ->
+				QueueMetricsBean qBean = new QueueMetricsBean()
+				JmsReporterBean reportBean = new JmsReporterBean()
+				reportBean.queue = jmsReporter.'@queue-mbean-name'
+				qBean.queueFactor = util.getQueueDepthFactor(reportBean.queue) / 100					
+								
+				if (times == 1)
+				{
+					qAggregateMap."$reportBean.queue-FactorTotal" = 0					
+				}
+				
+				
+				qAggregateMap."$reportBean.queue-FactorTotal" += qBean.queueFactor 
+				qAggregateMap."$reportBean.queue-FactorAvg" =  qAggregateMap."$reportBean.queue-FactorTotal" / times
+				
+				qBean.queueFactorTotal =  qAggregateMap."$reportBean.queue-FactorTotal" 
+				qBean.queueFactorAvg = qAggregateMap."$reportBean.queue-FactorAvg"
+				qBean.duration = ( new Date().getTime() - startTime ) / 1000 / 60
+				
+				qStatsMap[reportBean.queue] = qBean								
+			}
+			
+			loadScript.'reporters'.'service-reporters'.'service-reporter'.each
+			{
+				serviceReporter ->	
+				ServiceMetricsBean svcMetricsBean = new ServiceMetricsBean()
+				ServiceReporterBean svcReportBean = new ServiceReporterBean()
+				svcReportBean.serviceName = serviceReporter.'@service-name'
+				svcReportBean.esbArchiveName =  serviceReporter.'@esb-archive-name'
+				
+				if (times == 1)
+				{
+					svcAggregateMap."$svcReportBean.serviceName-TPSTotal" = 0
+					svcAggregateMap."$svcReportBean.serviceName-TPSAvg" = 0
+				}
+				
+				svcMetricsBean.tps = util.getEsbServiceTps(svcReportBean)							
+				svcAggregateMap."$svcReportBean.serviceName-TPSTotal" += svcMetricsBean.tps	
+				svcAggregateMap."$svcReportBean.serviceName-TPSAvg" =  svcAggregateMap."$svcReportBean.serviceName-TPSTotal" / times
+				
+				svcMetricsBean.tpsAvg =  svcAggregateMap."$svcReportBean.serviceName-TPSAvg"
+				svcMetricsBean.duration = ( new Date().getTime() - startTime ) / 1000 / 60
+				
+				svcStatsMap[svcReportBean.serviceName] = svcMetricsBean				
+			}	
+			
+			printMetrics(svcStatsMap,qStatsMap)	
+			csvLogMetrics(svcStatsMap,qStatsMap)	
+			def fastestQueue = loadScript.'reporters'.'jms-reporters'.'@fastest-queue-mbean-name'[0]
+			done = util.fastestQueueDone("$fastestQueue")			
+		}
+   }
+   
+   private createReportFiles(logDir)
+   {
+   		svcReportLog = new File(logDir + "/load-service-report-" + new Date().getTime() + ".csv")
+   		svcReportLog.getParentFile().mkdirs()
+		svcReportLog.append("Service, TPS, AVG TPS, Duration\n")
+		
+		queueReportLog = new File(logDir + "/load-queue-report-" + new Date().getTime() + ".csv")
+   		queueReportLog.getParentFile().mkdirs()
+		queueReportLog.append("Queue, Factor, Factor AVG, Duration\n")
+   }
+   
+   private printMetrics(svcStatsMap,qStatsMap)
+   {
+   		println "######Service Stats######"
+   		svcStatsMap.each {
+   			key, svcStats ->	
+   			println "Svc: $key, TPS: $svcStats.tps, AVG TPS: $svcStats.tpsAvg, Duration: $svcStats.duration" 
+   		}
+   		println "######Queue Stats######"
+   		qStatsMap.each {
+   			key, qStats ->	
+   			println "Queue: $key, Factor: $qStats.queueFactor, Factor AVG: $qStats.queueFactorAvg, Duration: $qStats.duration" 
+   		}
+   }
+   
+   private csvLogMetrics(serviceMetricsBean,queueMetricsBean)
+   {
+   		svcStatsMap.each {
+   			key, svcStats ->	
+   			svcReportLog.append("$key, $svcStats.tps, $svcStats.tpsAvg, $svcStats.duration\n") 
+   		}
+   		
+   		qStatsMap.each {
+   			key, qStats ->	
+   			def queueKeys = key.split(',')
+   			def queueName = queueKeys[1]
+   			queueReportLog.append("$queueName, $qStats.queueFactor, $qStats.queueFactorAvg, $qStats.duration\n")
+   		}
+   }  
+
+	static void main(args)
+	{
+		LoadReport reporter = new LoadReport(args[0])
+		reporter.generateMetrics()	
+	}
+
+}
+ 
+
     
    
\ No newline at end of file




More information about the jboss-svn-commits mailing list