use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestOutput in project controller by opendaylight.
the class DsbenchmarkProvider method startTest.
@Override
public Future<RpcResult<StartTestOutput>> startTest(final StartTestInput input) {
LOG.info("Starting the data store benchmark test, input: {}", input);
// Check if there is a test in progress
if (execStatus.compareAndSet(ExecStatus.Idle, ExecStatus.Executing) == false) {
LOG.info("Test in progress");
return RpcResultBuilder.success(new StartTestOutputBuilder().setStatus(StartTestOutput.Status.TESTINPROGRESS).build()).buildFuture();
}
// Cleanup data that may be left over from a previous test run
cleanupTestStore();
// Get the appropriate writer based on operation type and data format
DatastoreAbstractWriter dsWriter = getDatastoreWriter(input);
// Create listeners on OPERATIONAL and CONFIG test data subtrees
listenerProvider.createAndRegisterListeners(input.getListeners().intValue());
long startTime, endTime, listCreateTime, execTime;
startTime = System.nanoTime();
dsWriter.createList();
endTime = System.nanoTime();
listCreateTime = (endTime - startTime) / 1000;
// Run the test and measure the execution time
try {
startTime = System.nanoTime();
dsWriter.executeList();
endTime = System.nanoTime();
execTime = (endTime - startTime) / 1000;
this.testsCompleted++;
} catch (final Exception e) {
LOG.error("Test error: {}", e.toString());
execStatus.set(ExecStatus.Idle);
return RpcResultBuilder.success(new StartTestOutputBuilder().setStatus(StartTestOutput.Status.FAILED).build()).buildFuture();
}
LOG.info("Test finished");
setTestOperData(ExecStatus.Idle, testsCompleted);
execStatus.set(ExecStatus.Idle);
// Get the number of data change events and cleanup the data change listeners
long numDataChanges = listenerProvider.getDataChangeCount();
long numEvents = listenerProvider.getEventCountAndDestroyListeners();
StartTestOutput output = new StartTestOutputBuilder().setStatus(StartTestOutput.Status.OK).setListBuildTime(listCreateTime).setExecTime(execTime).setTxOk((long) dsWriter.getTxOk()).setNtfOk(numEvents).setDataChangeEventsOk(numDataChanges).setTxError((long) dsWriter.getTxError()).build();
return RpcResultBuilder.success(output).buildFuture();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestOutput in project controller by opendaylight.
the class NtfbenchmarkProvider method startTest.
@Override
public Future<RpcResult<StartTestOutput>> startTest(final StartTestInput input) {
final int producerCount = input.getProducers().intValue();
final int listenerCount = input.getListeners().intValue();
final int iterations = input.getIterations().intValue();
final int payloadSize = input.getIterations().intValue();
final List<AbstractNtfbenchProducer> producers = new ArrayList<>(producerCount);
final List<ListenerRegistration<NtfbenchTestListener>> listeners = new ArrayList<>(listenerCount);
for (int i = 0; i < producerCount; i++) {
producers.add(new NtfbenchBlockingProducer(publishService, iterations, payloadSize));
}
int expectedCntPerListener = producerCount * iterations;
for (int i = 0; i < listenerCount; i++) {
final NtfbenchTestListener listener;
if (input.getProducerType() == ProducerType.BLOCKING) {
listener = new NtfbenchWTCListener(payloadSize, expectedCntPerListener);
} else {
listener = new NtfbenchTestListener(payloadSize);
}
listeners.add(listenService.registerNotificationListener(listener));
}
try {
final ExecutorService executor = Executors.newFixedThreadPool(input.getProducers().intValue());
LOG.info("Test Started");
final long startTime = System.nanoTime();
for (int i = 0; i < input.getProducers().intValue(); i++) {
executor.submit(producers.get(i));
}
executor.shutdown();
try {
executor.awaitTermination(testTimeout, TimeUnit.MINUTES);
for (ListenerRegistration<NtfbenchTestListener> listenerRegistration : listeners) {
listenerRegistration.getInstance().getAllDone().get();
}
} catch (final InterruptedException | ExecutionException e) {
LOG.error("Out of time: test did not finish within the {} min deadline ", testTimeout);
}
final long producerEndTime = System.nanoTime();
final long producerElapsedTime = producerEndTime - startTime;
long allListeners = 0;
long allProducersOk = 0;
long allProducersError = 0;
for (final ListenerRegistration<NtfbenchTestListener> listenerRegistration : listeners) {
allListeners += listenerRegistration.getInstance().getReceived();
}
final long listenerEndTime = System.nanoTime();
final long listenerElapsedTime = producerEndTime - startTime;
LOG.info("Test Done");
for (final AbstractNtfbenchProducer abstractNtfbenchProducer : producers) {
allProducersOk += abstractNtfbenchProducer.getNtfOk();
allProducersError += abstractNtfbenchProducer.getNtfError();
}
final StartTestOutput output = new StartTestOutputBuilder().setProducerElapsedTime(producerElapsedTime / 1000000).setListenerElapsedTime(listenerElapsedTime / 1000000).setListenerOk(allListeners).setProducerOk(allProducersOk).setProducerError(allProducersError).setProducerRate((allProducersOk + allProducersError) * 1000000000 / producerElapsedTime).setListenerRate(allListeners * 1000000000 / listenerElapsedTime).build();
return RpcResultBuilder.success(output).buildFuture();
} finally {
for (final ListenerRegistration<NtfbenchTestListener> listenerRegistration : listeners) {
listenerRegistration.close();
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestOutput in project controller by opendaylight.
the class RpcbenchmarkProvider method startTest.
@Override
public Future<RpcResult<StartTestOutput>> startTest(final StartTestInput input) {
LOG.debug("startTest {}", input);
final RTCClient client;
final List<RoutedRpcRegistration<?>> rpcRegs = new ArrayList<>();
switch(input.getOperation()) {
case ROUTEDRTC:
List<InstanceIdentifier<?>> routeIid = new ArrayList<>();
for (int i = 0; i < input.getNumServers().intValue(); i++) {
GlobalBindingRTCServer server = new GlobalBindingRTCServer();
RoutedRpcRegistration<RpcbenchPayloadService> routedReg = providerRegistry.addRoutedRpcImplementation(RpcbenchPayloadService.class, server);
KeyedInstanceIdentifier<RpcRoute, RpcRouteKey> iid = InstanceIdentifier.create(RpcbenchRpcRoutes.class).child(RpcRoute.class, new RpcRouteKey(Integer.toString(i)));
routeIid.add(iid);
routedReg.registerPath(NodeContext.class, iid);
rpcRegs.add(routedReg);
}
client = new RoutedBindingRTClient(providerRegistry, input.getPayloadSize().intValue(), routeIid);
break;
case GLOBALRTC:
client = new GlobalBindingRTCClient(providerRegistry, input.getPayloadSize().intValue());
break;
default:
LOG.error("Unsupported server/client type {}", input.getOperation());
throw new IllegalArgumentException("Unsupported server/client type" + input.getOperation());
}
try {
ExecutorService executor = Executors.newFixedThreadPool(input.getNumClients().intValue());
final Runnable testRun = () -> client.runTest(input.getIterations().intValue());
LOG.info("Test Started");
long startTime = System.nanoTime();
for (int i = 0; i < input.getNumClients().intValue(); i++) {
executor.submit(testRun);
}
executor.shutdown();
try {
executor.awaitTermination(testTimeout, TimeUnit.MINUTES);
} catch (final InterruptedException e) {
LOG.error("Out of time: test did not finish within the {} min deadline ", testTimeout);
}
long endTime = System.nanoTime();
LOG.info("Test Done");
long elapsedTime = endTime - startTime;
StartTestOutput output = new StartTestOutputBuilder().setRate((long) 0).setGlobalRtcClientError(client.getRpcError()).setGlobalRtcClientOk(client.getRpcOk()).setExecTime(TimeUnit.NANOSECONDS.toMillis(elapsedTime)).setRate((client.getRpcOk() + client.getRpcError()) * 1000000000 / elapsedTime).build();
return RpcResultBuilder.success(output).buildFuture();
} finally {
for (RoutedRpcRegistration<?> routedRpcRegistration : rpcRegs) {
routedRpcRegistration.close();
}
}
}
Aggregations