2 * ============LICENSE_START=======================================================
3 * SPARKY (AAI UI service)
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 package org.openecomp.sparky.synchronizer;
28 import java.util.concurrent.atomic.AtomicInteger;
30 import org.openecomp.sparky.synchronizer.config.TaskProcessorConfig;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
35 * The Class AsyncRateControlTester.
37 public class AsyncRateControlTester {
39 private static Logger logger = LoggerFactory.getLogger(AsyncRateControlTester.class);
41 private long startTimeInMs;
43 private AtomicInteger counter;
45 protected boolean syncInProgress;
48 * Instantiates a new async rate control tester.
50 * @throws Exception the exception
52 public AsyncRateControlTester() throws Exception {
54 TaskProcessorConfig tpc = new TaskProcessorConfig();
56 tpc.setMaxConcurrentWorkers(1);
57 tpc.setTransactionRateControllerEnabled(false);
58 tpc.setNumSamplesPerThreadForRunningAverage(100);
59 tpc.setTargetTps(0.25);
61 tpc.setBytesHistogramLabel("bytesHistoLabel");
62 tpc.setBytesHistogramMaxYAxis(1000000);
63 tpc.setBytesHistogramNumBins(20);
64 tpc.setBytesHistogramNumDecimalPoints(2);
66 tpc.setQueueLengthHistogramLabel("queueHistoLabel");
67 tpc.setQueueLengthHistogramMaxYAxis(1000000);
68 tpc.setQueueLengthHistogramNumBins(20);
69 tpc.setQueueLengthHistogramNumDecimalPoints(2);
71 // ZeroDelayProcessor zdp = new ZeroDelayProcessor(LinkProcessorType.AAI, tpc);
72 // zdp.setStatCollector(this.aaiStatCollector);
74 * zdp.setTaskProcessorConfig(tpc);
76 * this.resolver.registerProcessor(zdp); this.resolver.registerEventListener(this); this.counter
77 * = new AtomicInteger(0); this.syncInProgress = false; }
79 * @Override public void handleEvent(AsyncEvent event) {
81 * if(event.getEventType() == AsyncEventType.RESOLVER_IDLE) {
83 * if(syncInProgress) { long duration = System.currentTimeMillis() - startTimeInMs;
84 * System.out.println(getStatReport(duration)); syncInProgress = false; }
86 * // shutdown(); } else if(event.getEventType() == AsyncEventType.TRANSACTION_PROCESSED) {
88 * this.syncInProgress = true;
90 * ExternalResource resource = (ExternalResource)event.getPayload();
92 * //aaiStatCollector.updateCounters(resource);
94 * counter.incrementAndGet();
100 * public void shutdown() { resolver.shutdown(); }
102 * private int getCounterValue(AtomicInteger counter) {
104 * if(counter == null) { return 0; }
106 * return counter.get(); }
108 * private void addActiveInventoryStatReport(StringBuilder sb) {
110 * if(sb == null) { return; }
112 * sb.append("\n\n ").append(LinkProcessorType.AAI.name());
114 * sb.append("\n\n ").append("REST Operational Stats:");
116 * /* Map<String, AtomicInteger> procOperationalCounters =
117 * aaiStatCollector.getActiveInventoryOperationalCounters();
119 * if(procOperationalCounters != null) {
122 * getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_1XX)); int _2XX
123 * = getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_2XX)); int
124 * _3XX = getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_3XX));
126 * getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_4XX)); int _5XX
127 * = getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_5XX)); int
128 * _6XX = getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_6XX));
130 * sb.append("\n ").append(String.format(
131 * "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ", HttpMethod.GET,
132 * _1XX, _2XX, _3XX, _4XX, _5XX, _6XX)); }
135 // sb.append("\n\n ").append("Entity Stats:");
138 * sort entities, then sort nested op codes
142 * TreeMap<String, HashMap<String, AtomicInteger>> activeInventoryEntitySortedTreeMap = new
143 * TreeMap<String, HashMap<String, AtomicInteger>>( new Comparator<String>() {
145 * public int compare(String o1, String o2) { return
146 * o1.toLowerCase().compareTo(o2.toLowerCase()); } });
150 * activeInventoryEntitySortedTreeMap.putAll(aaiStatCollector.getActiveInventoryEntityCounters()
153 * for(String counterEntityKey : activeInventoryEntitySortedTreeMap.keySet()) {
155 * HashMap<String, AtomicInteger> entityCounters =
156 * activeInventoryEntitySortedTreeMap.get(counterEntityKey);
158 * AtomicInteger total = entityCounters.get(ActiveInventoryStatCollector.TOTAL); AtomicInteger
159 * found = entityCounters.get(ActiveInventoryStatCollector.FOUND); AtomicInteger notFound =
160 * entityCounters.get(ActiveInventoryStatCollector.NOT_FOUND); AtomicInteger error =
161 * entityCounters.get(ActiveInventoryStatCollector.ERROR);
163 * int totalValue = (total == null) ? 0 : total.get(); int foundValue = (found == null) ? 0 :
164 * found.get(); int notFoundValue = (found == null) ? 0 : notFound.get(); int errorValue =
165 * (error == null) ? 0 : error.get();
167 * sb.append("\n ").append(String.format(
168 * "%-30s TOTAL: %-12d FOUND: %-12d NOT_FOUND: %-12d ERROR: %-12d", counterEntityKey,
169 * totalValue, foundValue, notFoundValue, errorValue));
174 // sb.append("\n\n ").append("Task Processor Stats:");
176 // int totalRetries =
177 // getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.NUM_RETRIES));
178 // int currentQueueLength = resolver.getCurrentQueueLength(LinkProcessorType.AAI.name());
182 * ).append(resolver.getProcessorTaskAgeStats(LinkProcessorType.AAI.name(), false, " "
183 * )); sb.append("\n "
184 * ).append(resolver.getProcessorResponseStats(LinkProcessorType.AAI.name(), false, " "
185 * )); sb.append("\n")
186 * .append(resolver.getQueueItemLengthHistogram(LinkProcessorType.AAI.name(), false,
187 * " ")); sb.append("\n")
188 * .append(resolver.getResponseByteSizeHistogram(LinkProcessorType.AAI.name(), false,
189 * " ")); sb.append("\n "
190 * ).append("TPS=").append(resolver.getTPS(LinkProcessorType.AAI.name())).append(", NumRetries="
191 * ).append(totalRetries) .append(", CurrentQueueLength=").append(currentQueueLength);
196 * private String getStatReport(long syncOpTimeInMs) {
198 * StringBuilder sb = new StringBuilder(128);
200 * sb.append("\n").append("Async Resolver Statistics: ( Sync Operation Duration = " +
201 * NodeUtils.getDurationBreakdown(syncOpTimeInMs) + " )");
203 * addActiveInventoryStatReport(sb);
205 * return sb.toString();
209 * public void loadResolver(int numItems) {
211 * if(numItems <= 0) { return; }
213 * startTimeInMs = System.currentTimeMillis();
215 * DummyPerformanceTask dpt = null;
217 * for(int i = 0; i < numItems; i++) {
219 * dpt = new DummyPerformanceTask(); dpt.setLinkProcessorType(LinkProcessorType.AAI);
220 * dpt.setResourceEntityType("DummyPerformanceEntity"); dpt.setOperationType(HttpMethod.GET);
222 * resolver.resolve(dpt);
228 * public static void main(String[] args) throws Exception {
230 * System.getProperties().setProperty("AJSC_HOME", "x:\\aaiui\\");
232 * System.out.println("Available processors = " + Runtime.getRuntime().availableProcessors());
234 * AsyncRateControlTester arcTester = new AsyncRateControlTester();
236 * // give us time to instrument the jvm with jvisualvm // Thread.sleep(30000);
237 * Thread.sleep(5000);
239 * arcTester.loadResolver(1000);