| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package com.sun.opends.sdk.tools; |
| | |
| | | |
| | | /** |
| | | * Worker thread base implementation. |
| | | * |
| | | * @param <R> |
| | | * Type of result handler. |
| | | */ |
| | | abstract class WorkerThread<R extends ResultHandler<?>> extends Thread |
| | | abstract class WorkerThread extends Thread |
| | | { |
| | | private int count; |
| | | |
| | |
| | | |
| | | |
| | | |
| | | public abstract R getHandler(long startTime); |
| | | |
| | | |
| | | |
| | | public abstract FutureResult<?> performOperation( |
| | | AsynchronousConnection connection, R handler, DataSource[] dataSources); |
| | | AsynchronousConnection connection, DataSource[] dataSources, |
| | | long startTime); |
| | | |
| | | |
| | | |
| | |
| | | { |
| | | FutureResult<?> future; |
| | | AsynchronousConnection connection; |
| | | R handler; |
| | | |
| | | final double targetTimeInMS = |
| | | (1.0 / (targetThroughput / |
| | |
| | | long start; |
| | | while (!stopRequested && !(maxIterations > 0 && count >= maxIterations)) |
| | | { |
| | | start = System.nanoTime(); |
| | | handler = getHandler(start); |
| | | |
| | | if (this.connection == null) |
| | | { |
| | | try |
| | |
| | | } |
| | | } |
| | | } |
| | | future = performOperation(connection, handler, dataSources.get()); |
| | | |
| | | start = System.nanoTime(); |
| | | future = performOperation(connection, dataSources.get(), start); |
| | | operationRecentCount.getAndIncrement(); |
| | | count++; |
| | | if (!isAsync) |
| | |
| | | |
| | | private final AtomicInteger operationRecentCount = new AtomicInteger(); |
| | | |
| | | private final AtomicInteger successRecentCount = new AtomicInteger(); |
| | | protected final AtomicInteger successRecentCount = new AtomicInteger(); |
| | | |
| | | private final AtomicInteger failedRecentCount = new AtomicInteger(); |
| | | protected final AtomicInteger failedRecentCount = new AtomicInteger(); |
| | | |
| | | private final AtomicLong waitRecentTime = new AtomicLong(); |
| | | |
| | |
| | | |
| | | |
| | | |
| | | PerformanceRunner(final ArgumentParser argParser, final ConsoleApplication app) |
| | | PerformanceRunner(final ArgumentParser argParser, |
| | | final ConsoleApplication app, |
| | | boolean neverRebind, boolean neverAsynchronous, |
| | | boolean alwaysSingleThreaded) |
| | | throws ArgumentException |
| | | { |
| | | this.app = app; |
| | |
| | | true, 1, false, 0, LocalizableMessage |
| | | .raw("Number of worker threads per connection")); |
| | | numThreadsArgument.setPropertyName("numThreads"); |
| | | argParser.addArgument(numThreadsArgument); |
| | | if(!alwaysSingleThreaded) |
| | | { |
| | | argParser.addArgument(numThreadsArgument); |
| | | } |
| | | else |
| | | { |
| | | numThreadsArgument.addValue("1"); |
| | | } |
| | | |
| | | numConnectionsArgument = new IntegerArgument("numConnections", 'c', |
| | | "numConnections", false, false, true, LocalizableMessage |
| | | .raw("{numConnections}"), 1, null, true, 1, false, 0, |
| | | LocalizableMessage.raw("Number of connections")); |
| | | numThreadsArgument.setPropertyName("numConnections"); |
| | | numConnectionsArgument.setPropertyName("numConnections"); |
| | | argParser.addArgument(numConnectionsArgument); |
| | | |
| | | maxIterationsArgument = new IntegerArgument("maxIterations", 'm', |
| | | "maxIterations", false, false, true, LocalizableMessage |
| | | .raw("{maxIterations}"), 0, null, LocalizableMessage |
| | | .raw("Max iterations, 0 for unlimited")); |
| | | numThreadsArgument.setPropertyName("maxIterations"); |
| | | maxIterationsArgument.setPropertyName("maxIterations"); |
| | | argParser.addArgument(maxIterationsArgument); |
| | | |
| | | statsIntervalArgument = new IntegerArgument("statInterval", 'i', |
| | |
| | | .raw("{statInterval}"), 5, null, true, 1, false, 0, |
| | | LocalizableMessage |
| | | .raw("Display results each specified number of seconds")); |
| | | numThreadsArgument.setPropertyName("statInterval"); |
| | | statsIntervalArgument.setPropertyName("statInterval"); |
| | | argParser.addArgument(statsIntervalArgument); |
| | | |
| | | targetThroughputArgument = new IntegerArgument("targetThroughput", 'M', |
| | |
| | | |
| | | noRebindArgument = new BooleanArgument("noRebind", 'F', "noRebind", |
| | | LocalizableMessage.raw("Keep connections open and don't rebind")); |
| | | keepConnectionsOpen.setPropertyName("noRebind"); |
| | | argParser.addArgument(noRebindArgument); |
| | | noRebindArgument.setPropertyName("noRebind"); |
| | | if(!neverRebind) |
| | | { |
| | | argParser.addArgument(noRebindArgument); |
| | | } |
| | | else |
| | | { |
| | | noRebindArgument.addValue(String.valueOf(true)); |
| | | } |
| | | |
| | | asyncArgument = new BooleanArgument("asynchronous", 'A', "asynchronous", |
| | | LocalizableMessage.raw("Use asynchronous mode and don't " + |
| | | "wait for results before sending the next request")); |
| | | keepConnectionsOpen.setPropertyName("asynchronous"); |
| | | argParser.addArgument(asyncArgument); |
| | | asyncArgument.setPropertyName("asynchronous"); |
| | | if(!neverAsynchronous) |
| | | { |
| | | argParser.addArgument(asyncArgument); |
| | | } |
| | | |
| | | arguments = new StringArgument("argument", 'g', "argument", false, true, |
| | | true, LocalizableMessage.raw("{generator function or static string}"), |
| | |
| | | |
| | | |
| | | |
| | | abstract WorkerThread<?> newWorkerThread(AsynchronousConnection connection, |
| | | abstract WorkerThread newWorkerThread(AsynchronousConnection connection, |
| | | ConnectionFactory connectionFactory); |
| | | |
| | | |