use of com.axway.ats.agent.core.model.EvenLoadDistributingUtils in project ats-framework by Axway.
the class UsernameDataConfig method distributeRangeArguments.
private List<ParameterDataConfig> distributeRangeArguments(int agents) {
List<ParameterDataConfig> distributedParameterProviders = new ArrayList<ParameterDataConfig>();
int[] distributionValues = new EvenLoadDistributingUtils().getEvenLoad(rangeEnd.intValue() - rangeStart.intValue() + 1, agents);
int numberValuesPerHost = distributionValues[0];
int numberValuesLastHost = distributionValues[1];
if (numberValuesPerHost == 0 || numberValuesLastHost == 0) {
throw new IllegalArgumentException("Could not distribute only " + (rangeEnd.intValue() - rangeStart.intValue() + 1) + " values of parameter '" + parameterName + "' to " + agents + " agents! Decrease the number of agents or increase the possible values.");
} else {
for (int i = 0; i < agents; i++) {
int newRangeStart = rangeStart.intValue() + i * numberValuesPerHost;
if (i < agents - 1) {
distributedParameterProviders.add(new UsernameDataConfig(this.staticValue, newRangeStart, newRangeStart + numberValuesPerHost - 1));
} else {
distributedParameterProviders.add(new UsernameDataConfig(this.staticValue, newRangeStart, newRangeStart + numberValuesLastHost - 1));
}
}
}
return distributedParameterProviders;
}
use of com.axway.ats.agent.core.model.EvenLoadDistributingUtils in project ats-framework by Axway.
the class UsernameDataConfig method distributeListArguments.
private List<ParameterDataConfig> distributeListArguments(int agents) {
List<ParameterDataConfig> distributedParameterProviders = new ArrayList<ParameterDataConfig>();
int[] distributionValues = new EvenLoadDistributingUtils().getEvenLoad(this.values.size(), agents);
if (distributionValues.length == 0) {
throw new IllegalArgumentException("Could not distribute only " + this.values.size() + " values of parameter '" + parameterName + "' to " + agents + " agents! Decrease the number of agents or increase the possible values.");
} else {
for (int i = 0; i < agents; i++) {
int startIndex = i * distributionValues[i];
// if we do not create a new instance of ArrayList here,
// the subList method returns a RandomAccessSublist which is not serializable
distributedParameterProviders.add(new UsernameDataConfig(new ArrayList<Object>(values.subList(startIndex, startIndex + distributionValues[i]))));
}
}
return distributedParameterProviders;
}
use of com.axway.ats.agent.core.model.EvenLoadDistributingUtils in project ats-framework by Axway.
the class ListDataConfig method distribute.
@Override
List<ParameterDataConfig> distribute(int agents) throws IllegalArgumentException {
List<ParameterDataConfig> distributedParameterProviders = new ArrayList<ParameterDataConfig>();
int[] distributionValues = new EvenLoadDistributingUtils().getEvenLoad(this.values.size(), agents);
if (distributionValues.length == 0) {
throw new IllegalArgumentException("Could not distribute only " + this.values.size() + " values of parameter '" + parameterName + "' to " + agents + " agents! Decrease number of loaders or increase the possible values.");
} else {
for (int i = 0; i < agents; i++) {
int startIndex = i * distributionValues[i];
// if we do not create a new instance of ArrayList here,
// the subList method returns a RandomAccessSublist which is not serializable
distributedParameterProviders.add(new ListDataConfig(this.parameterName, new ArrayList<Object>(values.subList(startIndex, startIndex + distributionValues[i])), this.parameterProviderLevel));
}
}
return distributedParameterProviders;
}
use of com.axway.ats.agent.core.model.EvenLoadDistributingUtils in project ats-framework by Axway.
the class RangeDataConfig method distribute.
@Override
List<ParameterDataConfig> distribute(int agents) {
List<ParameterDataConfig> distributedParameterProviders = new ArrayList<ParameterDataConfig>();
int[] distributionValues = new EvenLoadDistributingUtils().getEvenLoad(rangeEnd.intValue() - rangeStart.intValue() + 1, agents);
if (distributionValues.length == 0) {
throw new IllegalArgumentException("Could not distribute only " + (rangeEnd.intValue() - rangeStart.intValue() + 1) + " values of parameter '" + parameterName + "' to " + agents + " agents! Decrease number ot loaders or increase the possible values.");
} else {
for (int i = 0; i < agents; i++) {
int newRangeStart = rangeStart.intValue() + i * distributionValues[i];
distributedParameterProviders.add(new RangeDataConfig(this.parameterName, this.staticValue, newRangeStart, newRangeStart + distributionValues[i] - 1, this.parameterProviderLevel));
}
}
return distributedParameterProviders;
}
use of com.axway.ats.agent.core.model.EvenLoadDistributingUtils in project ats-framework by Axway.
the class RampUpQueueLoader method scheduleThreads.
@Override
public synchronized void scheduleThreads(String caller, boolean isUseSynchronizedIterations) throws ActionExecutionException, ActionTaskLoaderException, NoSuchComponentException, NoSuchActionException, NoCompatibleMethodFoundException, ThreadingPatternNotSupportedException {
//check the state first
if (state != ActionTaskLoaderState.NOT_STARTED) {
throw new ActionTaskLoaderException("Cannot schedule load queue " + queueName + " - it has already been scheduled");
}
//create the executor - terminate threads when finished
ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool();
executor.setKeepAliveTime(0, TimeUnit.SECONDS);
ExecutorCompletionService<Object> executionService = new ExecutorCompletionService<Object>(executor);
//synchronization aids
threadsManagers = new ArrayList<ThreadsManager>();
// create the thread for managing max iteration length
int iterationTimeout = startPattern.getIterationTimeout();
if (iterationTimeout > 0) {
itManager = new IterationTimeoutManager(iterationTimeout);
}
taskFutures = new ArrayList<Future<Object>>();
for (int i = 0; i < numThreadGroups; i++) {
//create the thread iterations manager for this group
ThreadsManager threadsManager = new ThreadsManager();
int numThreadsInGroup = (i != numThreadGroups - 1) ? numThreadsPerStep : numThreadsInLastGroup;
//distribute executions per timeFrame according to the number of threads
int executionsPerTimeFrame = executionPattern.getExecutionsPerTimeFrame();
int[] executionsPerTimeFramePerThread = new EvenLoadDistributingUtils().getEvenLoad(executionsPerTimeFrame, numThreads);
if (numThreads > executionsPerTimeFrame && executionsPerTimeFrame > 0) {
throw new ActionTaskLoaderException("We cannot evenly distribute " + executionsPerTimeFrame + " iterations per time frame to " + numThreads + " threads. Iterations per time frame must be at least as many as threads!");
}
for (int j = 0; j < numThreadsInGroup; j++) {
Future<Object> taskFuture = executionService.submit(ActionTaskFactory.createTask(caller, queueName, executionPattern, executionsPerTimeFramePerThread[j], threadsManager, itManager, actionRequests, parameterDataProviders, defaultTaskListeners, isUseSynchronizedIterations), null);
taskFutures.add(taskFuture);
}
threadsManagers.add(threadsManager);
}
state = ActionTaskLoaderState.SCHEDULED;
}
Aggregations