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.onap.aai.sparky.synchronizer;
28 import java.util.concurrent.atomic.AtomicInteger;
30 import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
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 NetworkStatisticsConfig tpc = new NetworkStatisticsConfig();
56 tpc.setNumSamplesPerThreadForRunningAverage(100);
58 tpc.setBytesHistogramLabel("bytesHistoLabel");
59 tpc.setBytesHistogramMaxYAxis(1000000);
60 tpc.setBytesHistogramNumBins(20);
61 tpc.setBytesHistogramNumDecimalPoints(2);
63 tpc.setQueueLengthHistogramLabel("queueHistoLabel");
64 tpc.setQueueLengthHistogramMaxYAxis(1000000);
65 tpc.setQueueLengthHistogramNumBins(20);
66 tpc.setQueueLengthHistogramNumDecimalPoints(2);
68 // ZeroDelayProcessor zdp = new ZeroDelayProcessor(LinkProcessorType.AAI, tpc);
69 // zdp.setStatCollector(this.aaiStatCollector);
71 * zdp.setTaskProcessorConfig(tpc);
73 * this.resolver.registerProcessor(zdp); this.resolver.registerEventListener(this); this.counter
74 * = new AtomicInteger(0); this.syncInProgress = false; }
76 * @Override public void handleEvent(AsyncEvent event) {
78 * if(event.getEventType() == AsyncEventType.RESOLVER_IDLE) {
80 * if(syncInProgress) { long duration = System.currentTimeMillis() - startTimeInMs;
81 * System.out.println(getStatReport(duration)); syncInProgress = false; }
83 * // shutdown(); } else if(event.getEventType() == AsyncEventType.TRANSACTION_PROCESSED) {
85 * this.syncInProgress = true;
87 * ExternalResource resource = (ExternalResource)event.getPayload();
89 * //aaiStatCollector.updateCounters(resource);
91 * counter.incrementAndGet();
97 * public void shutdown() { resolver.shutdown(); }
99 * private int getCounterValue(AtomicInteger counter) {
101 * if(counter == null) { return 0; }
103 * return counter.get(); }
105 * private void addActiveInventoryStatReport(StringBuilder sb) {
107 * if(sb == null) { return; }
109 * sb.append("\n\n ").append(LinkProcessorType.AAI.name());
111 * sb.append("\n\n ").append("REST Operational Stats:");
113 * /* Map<String, AtomicInteger> procOperationalCounters =
114 * aaiStatCollector.getActiveInventoryOperationalCounters();
116 * if(procOperationalCounters != null) {
119 * getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_1XX)); int _2XX
120 * = getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_2XX)); int
121 * _3XX = getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_3XX));
123 * getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_4XX)); int _5XX
124 * = getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_5XX)); int
125 * _6XX = getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.GET_6XX));
127 * sb.append("\n ").append(String.format(
128 * "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ", HttpMethod.GET,
129 * _1XX, _2XX, _3XX, _4XX, _5XX, _6XX)); }
132 // sb.append("\n\n ").append("Entity Stats:");
135 * sort entities, then sort nested op codes
139 * TreeMap<String, HashMap<String, AtomicInteger>> activeInventoryEntitySortedTreeMap = new
140 * TreeMap<String, HashMap<String, AtomicInteger>>( new Comparator<String>() {
142 * public int compare(String o1, String o2) { return
143 * o1.toLowerCase().compareTo(o2.toLowerCase()); } });
147 * activeInventoryEntitySortedTreeMap.putAll(aaiStatCollector.getActiveInventoryEntityCounters()
150 * for(String counterEntityKey : activeInventoryEntitySortedTreeMap.keySet()) {
152 * HashMap<String, AtomicInteger> entityCounters =
153 * activeInventoryEntitySortedTreeMap.get(counterEntityKey);
155 * AtomicInteger total = entityCounters.get(ActiveInventoryStatCollector.TOTAL); AtomicInteger
156 * found = entityCounters.get(ActiveInventoryStatCollector.FOUND); AtomicInteger notFound =
157 * entityCounters.get(ActiveInventoryStatCollector.NOT_FOUND); AtomicInteger error =
158 * entityCounters.get(ActiveInventoryStatCollector.ERROR);
160 * int totalValue = (total == null) ? 0 : total.get(); int foundValue = (found == null) ? 0 :
161 * found.get(); int notFoundValue = (found == null) ? 0 : notFound.get(); int errorValue =
162 * (error == null) ? 0 : error.get();
164 * sb.append("\n ").append(String.format(
165 * "%-30s TOTAL: %-12d FOUND: %-12d NOT_FOUND: %-12d ERROR: %-12d", counterEntityKey,
166 * totalValue, foundValue, notFoundValue, errorValue));
171 // sb.append("\n\n ").append("Task Processor Stats:");
173 // int totalRetries =
174 // getCounterValue(procOperationalCounters.get(ActiveInventoryStatCollector.NUM_RETRIES));
175 // int currentQueueLength = resolver.getCurrentQueueLength(LinkProcessorType.AAI.name());
179 * ).append(resolver.getProcessorTaskAgeStats(LinkProcessorType.AAI.name(), false, " "
180 * )); sb.append("\n "
181 * ).append(resolver.getProcessorResponseStats(LinkProcessorType.AAI.name(), false, " "
182 * )); sb.append("\n")
183 * .append(resolver.getQueueItemLengthHistogram(LinkProcessorType.AAI.name(), false,
184 * " ")); sb.append("\n")
185 * .append(resolver.getResponseByteSizeHistogram(LinkProcessorType.AAI.name(), false,
186 * " ")); sb.append("\n "
187 * ).append("TPS=").append(resolver.getTPS(LinkProcessorType.AAI.name())).append(", NumRetries="
188 * ).append(totalRetries) .append(", CurrentQueueLength=").append(currentQueueLength);
193 * private String getStatReport(long syncOpTimeInMs) {
195 * StringBuilder sb = new StringBuilder(128);
197 * sb.append("\n").append("Async Resolver Statistics: ( Sync Operation Duration = " +
198 * NodeUtils.getDurationBreakdown(syncOpTimeInMs) + " )");
200 * addActiveInventoryStatReport(sb);
202 * return sb.toString();
206 * public void loadResolver(int numItems) {
208 * if(numItems <= 0) { return; }
210 * startTimeInMs = System.currentTimeMillis();
212 * DummyPerformanceTask dpt = null;
214 * for(int i = 0; i < numItems; i++) {
216 * dpt = new DummyPerformanceTask(); dpt.setLinkProcessorType(LinkProcessorType.AAI);
217 * dpt.setResourceEntityType("DummyPerformanceEntity"); dpt.setOperationType(HttpMethod.GET);
219 * resolver.resolve(dpt);
225 * public static void main(String[] args) throws Exception {
227 * System.getProperties().setProperty("AJSC_HOME", "x:\\aaiui\\");
229 * System.out.println("Available processors = " + Runtime.getRuntime().availableProcessors());
231 * AsyncRateControlTester arcTester = new AsyncRateControlTester();
233 * // give us time to instrument the jvm with jvisualvm // Thread.sleep(30000);
234 * Thread.sleep(5000);
236 * arcTester.loadResolver(1000);