1 4 package com.tctest.performance.throughput; 5 6 import com.tc.simulator.app.ApplicationConfig; 7 import com.tc.simulator.listener.ListenerProvider; 8 import com.tc.test.TempDirectoryHelper; 9 import com.tctest.performance.generate.load.LinearTransitionLoadGenerator; 10 import com.tctest.performance.generate.load.LoadGenerator; 11 import com.tctest.performance.generate.load.Measurement; 12 import com.tctest.performance.generate.load.Metronome; 13 import com.tctest.performance.generate.load.WorkQueueOverflowException; 14 import com.tctest.performance.results.PerformanceMeasurementMarshaller; 15 import com.tctest.performance.simulate.type.SimulatedType; 16 import com.tctest.performance.simulate.type.SimulatedTypeFactory; 17 import com.tctest.runner.AbstractTransparentApp; 18 19 import java.io.File ; 20 import java.util.ArrayList ; 21 import java.util.LinkedList ; 22 import java.util.List ; 23 24 public abstract class AbstractSingleQueueThroughputTestApp extends AbstractTransparentApp { 25 26 private final List results; 27 private Measurement[] workQueueWaitTimes; 28 private static final int DURATION = 60 * 10; 29 private static final int INIT_LOAD = 600; 30 private static final int MAX_LOAD = 3000; 31 private static final int PERCENT_UNIQUE = 100; 32 33 public AbstractSingleQueueThroughputTestApp(String appId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 34 super(appId, cfg, listenerProvider); 35 results = new LinkedList (); 36 } 37 38 public void run() { 39 Thread producer = new Thread () { 40 public void run() { 41 SimulatedType sInt = SimulatedTypeFactory.create(new Integer (0)); 42 LoadGenerator loadGenerator = new LinearTransitionLoadGenerator(); 43 loadGenerator.start(DURATION, INIT_LOAD, MAX_LOAD, sInt, PERCENT_UNIQUE); 44 try { 45 while (true) { 46 Object obj = loadGenerator.getNext(); 47 if (obj == null) { 48 workQueueWaitTimes = loadGenerator.getWaitTimes(); 49 break; } 51 populate(obj); 52 } 53 } catch (WorkQueueOverflowException e) { 54 System.err.println("UPPER BOUND REACHED"); 55 workQueueWaitTimes = loadGenerator.getWaitTimes(); 56 return; 57 58 } catch (InterruptedException e) { 59 throw new RuntimeException (e); } 61 } 62 }; 63 producer.setDaemon(true); 64 65 Thread consumer = new Thread () { 66 public void run() { 67 try { 68 while (true) { 69 retrieve(); 70 } 71 } catch (Throwable t) { 72 notifyError(t); 73 } 74 } 75 }; 76 consumer.setDaemon(true); 77 78 System.err.println("LOAD STARTED"); 79 80 producer.start(); 81 consumer.start(); 82 83 try { 84 producer.join(); 85 } catch (Throwable t) { 86 notifyError(t); 87 } 88 89 System.err.println("DURATION COMPLETE"); 90 91 writeData(); 92 } 93 94 protected abstract void populate(Object data) throws InterruptedException ; 95 96 protected abstract void retrieve() throws InterruptedException ; 97 98 protected abstract String title(); 99 100 protected List results() { 101 return results; 102 } 103 104 protected List generateStatistics() { 105 List measurementList = new ArrayList (); 106 Measurement[] stats = new Measurement[results.size()]; 107 Metronome data; 108 for (int i = 0; i < stats.length; i++) { 109 data = (Metronome) results.get(i); 110 stats[i] = new Measurement(data.load, data.endtime - data.starttime); 111 } 112 measurementList.add(workQueueWaitTimes); 113 measurementList.add(stats); 114 115 return measurementList; 116 } 117 118 protected void writeData() { 119 try { 120 TempDirectoryHelper helper = new TempDirectoryHelper(getClass()); 121 File dataDir = helper.getDirectory(); 122 File output = new File (dataDir + File.separator + "results.data"); 123 output.createNewFile(); 124 System.err.println("WROTE RESULT DATA TO: " + output); 125 126 PerformanceMeasurementMarshaller.Header header = PerformanceMeasurementMarshaller.createHeader(); 127 header.title = title(); 128 header.xLabel = INIT_LOAD + " to " + MAX_LOAD + " Objects/sec."; 129 header.yLabel = "Time spent in queue (Milliseconds)"; 130 header.duration = DURATION; 131 132 String [] lineDescriptions = new String [] { "Work Queue Wait Time", 133 "Time Spent in Shared Queue - duration: " + header.duration + " sec. | " + header.xLabel }; 134 135 PerformanceMeasurementMarshaller.marshall(generateStatistics(), header, output, lineDescriptions); 136 137 } catch (Throwable t) { 138 notifyError(t); 139 } 140 } 141 } 142 | Popular Tags |