private <T> List<Future<T>> executeThreads(String test, Callable<T> task) throws ExecutionException, InterruptedException { int concurrency = storageConfiguration.getBenchmark().getConcurrency(); // System.out.println("concurrency :: " + concurrency); ExecutorService executorService = Executors.newFixedThreadPool(10); List<Future<T>> futureList = new ArrayList<>(10); for (int i = 0; i < concurrency; i++) { futureList.add(executorService.submit(task)); } int totalTime = 0; for (Future<T> queryResultFuture : futureList) { totalTime += ((QueryResult) queryResultFuture.get()).getDbTime(); // System.out.println("queryResultFuture.get().getDbTime() = " + queryResultFuture.get().getDbTime()); // System.out.println("queryResultFuture.get().getResult().size() = " + queryResultFuture.get().getResult().get(0)); } benchmarkStats.addExecutionTime(test, totalTime); benchmarkStats.addStdDeviation(test, totalTime); return futureList; } }
public void addThreadGroup(List<? extends Sampler> samplers) { // Loop Controller LoopController loopController = new LoopController(); loopController.setLoops(storageConfiguration.getBenchmark().getNumRepetitions()); loopController.setFirst(true); loopController.setProperty(TestElement.TEST_CLASS, LoopController.class.getName()); loopController.setProperty(TestElement.GUI_CLASS, LoopControlPanel.class.getName()); loopController.initialize(); // Thread Group ThreadGroup threadGroup = new ThreadGroup(); threadGroup.setName("Thread-Group"); threadGroup.setNumThreads(storageConfiguration.getBenchmark().getConcurrency()); threadGroup.setRampUp(1); threadGroup.setSamplerController(loopController); threadGroup.setProperty(TestElement.TEST_CLASS, ThreadGroup.class.getName()); threadGroup.setProperty(TestElement.GUI_CLASS, ThreadGroupGui.class.getName()); // Construct Test Plan from previously initialized elements HashTree threadGroupHashTree = testPlanTree.add(testPlan, threadGroup); ConstantTimer timer = new ConstantTimer(); timer.setDelay(String.valueOf(storageConfiguration.getBenchmark().getDelay())); timer.setName("timer"); // Add samplers to the ThreadGroup threadGroupHashTree.add(samplers); // Add timer to the ThreadGroup threadGroupHashTree.add(timer); }
storageConfiguration.getBenchmark().getConcurrency()); return benchmarkStats;