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 AbstractDualQueueThroughputTestApp extends AbstractTransparentApp { 25 26 private final List results1; 27 private final List results2; 28 private Measurement[] workQueueWaitTimes1; 29 private Measurement[] workQueueWaitTimes2; 30 private static final int DURATION = 60 * 10; 31 private static final int INIT_LOAD = 400; 32 private static final int MAX_LOAD = 2000; 33 private static final int PERCENT_UNIQUE = 100; 34 private volatile boolean escape; 35 36 public AbstractDualQueueThroughputTestApp(String appId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 37 super(appId, cfg, listenerProvider); 38 results1 = new LinkedList (); 39 results2 = new LinkedList (); 40 } 41 42 public void run() { 43 44 46 Thread producer1 = new Thread () { 47 public void run() { 48 SimulatedType sInt = SimulatedTypeFactory.create(new Integer (0)); 49 LoadGenerator loadGenerator = new LinearTransitionLoadGenerator(); 50 loadGenerator.start(DURATION, INIT_LOAD, MAX_LOAD, sInt, PERCENT_UNIQUE); 51 try { 52 while (!escape) { 53 Object obj = loadGenerator.getNext(); 54 if (obj == null) { 55 workQueueWaitTimes1 = loadGenerator.getWaitTimes(); 56 break; } 58 populate1(obj); 59 } 60 } catch (WorkQueueOverflowException e) { 61 System.err.println("UPPER BOUND REACHED"); 62 workQueueWaitTimes1 = loadGenerator.getWaitTimes(); 63 escape = true; 64 return; 65 66 } catch (InterruptedException e) { 67 throw new RuntimeException (e); } 69 } 70 }; 71 producer1.setDaemon(true); 72 73 Thread producer2 = new Thread () { 74 public void run() { 75 SimulatedType sInt = SimulatedTypeFactory.create(new Integer (0)); 76 LoadGenerator loadGenerator = new LinearTransitionLoadGenerator(); 77 loadGenerator.start(DURATION, INIT_LOAD, MAX_LOAD, sInt, PERCENT_UNIQUE); 78 try { 79 while (!escape) { 80 Object obj = loadGenerator.getNext(); 81 if (obj == null) { 82 workQueueWaitTimes2 = loadGenerator.getWaitTimes(); 83 break; } 85 populate2(obj); 86 } 87 } catch (WorkQueueOverflowException e) { 88 System.err.println("UPPER BOUND REACHED"); 89 workQueueWaitTimes2 = loadGenerator.getWaitTimes(); 90 escape = true; 91 return; 92 93 } catch (InterruptedException e) { 94 throw new RuntimeException (e); } 96 } 97 }; 98 producer2.setDaemon(true); 99 100 Thread consumer1 = new Thread () { 101 public void run() { 102 try { 103 while (true) { 104 retrieve1(); 105 } 106 } catch (Throwable t) { 107 notifyError(t); 108 } 109 } 110 }; 111 consumer1.setDaemon(true); 112 113 Thread consumer2 = new Thread () { 114 public void run() { 115 try { 116 while (true) { 117 retrieve2(); 118 } 119 } catch (Throwable t) { 120 notifyError(t); 121 } 122 } 123 }; 124 consumer2.setDaemon(true); 125 126 System.err.println("LOAD STARTED"); 127 128 producer1.start(); 129 producer2.start(); 130 consumer1.start(); 131 consumer2.start(); 132 133 try { 134 producer1.join(); 135 producer2.join(); 136 } catch (Throwable t) { 137 notifyError(t); 138 } 139 140 System.err.println("DURATION COMPLETE"); 141 142 writeData(); 143 } 144 145 protected abstract void populate1(Object data) throws InterruptedException ; 146 147 protected abstract void populate2(Object data) throws InterruptedException ; 148 149 protected abstract void retrieve1() throws InterruptedException ; 150 151 protected abstract void retrieve2() throws InterruptedException ; 152 153 protected abstract String title(); 154 155 protected List results1() { 156 return results1; 157 } 158 159 protected List results2() { 160 return results2; 161 } 162 163 protected List generateStatistics() { 164 List measurementList = new ArrayList (); 165 Metronome data; 166 167 Measurement[] stats1 = new Measurement[results1.size()]; 168 for (int i = 0; i < stats1.length; i++) { 169 data = (Metronome) results1.get(i); 170 stats1[i] = new Measurement(data.load, data.endtime - data.starttime); 171 } 172 Measurement[] stats2 = new Measurement[results2.size()]; 173 for (int i = 0; i < stats2.length; i++) { 174 data = (Metronome) results2.get(i); 175 stats2[i] = new Measurement(data.load, data.endtime - data.starttime); 176 } 177 178 measurementList.add(workQueueWaitTimes1); 179 measurementList.add(workQueueWaitTimes2); 180 measurementList.add(stats1); 181 measurementList.add(stats2); 182 183 return measurementList; 184 } 185 186 protected void writeData() { 187 try { 188 TempDirectoryHelper helper = new TempDirectoryHelper(getClass()); 189 File dataDir = helper.getDirectory(); 190 File output = new File (dataDir + File.separator + "results.data"); 191 output.createNewFile(); 192 System.err.println("WROTE RESULT DATA TO: " + output); 193 194 PerformanceMeasurementMarshaller.Header header = PerformanceMeasurementMarshaller.createHeader(); 195 header.title = title(); 196 header.xLabel = INIT_LOAD + " to " + MAX_LOAD + " Objects/sec."; 197 header.yLabel = "Time spent in queue (Milliseconds)"; 198 header.duration = DURATION; 199 200 String [] lineDescriptions = new String [] { "Work Queue1 Wait Time", "Work Queue2 Wait Time", 201 "Time Spent in Shared Queue2 - duration: " + header.duration + " sec. | " + header.xLabel, 202 "Time Spent in Shared Queue1 - duration: " + header.duration + " sec. | " + header.xLabel }; 203 204 PerformanceMeasurementMarshaller.marshall(generateStatistics(), header, output, lineDescriptions); 205 206 } catch (Throwable t) { 207 notifyError(t); 208 } 209 } 210 } 211 | Popular Tags |