List of usage examples for org.apache.commons.math.stat.descriptive StorelessUnivariateStatistic getResult
double getResult();
From source file:net.sf.katta.tool.loadtest.LoadTestMasterOperation.java
@Override public void nodeOperationsComplete(MasterContext context, List<OperationResult> nodeResults) throws Exception { try {/*from w w w.j ava 2 s .com*/ final int queryRate = calculateCurrentQueryRate(); LOG.info("collecting results for iteration " + _currentIteration + " and query rate " + queryRate + " after " + (System.currentTimeMillis() - _currentIterationStartTime) + " ms ..."); List<LoadTestQueryResult> queryResults = new ArrayList<LoadTestQueryResult>(); for (OperationResult operationResult : nodeResults) { if (operationResult == null || operationResult.getUnhandledException() != null) { Exception rootException = null; if (operationResult != null) { rootException = operationResult.getUnhandledException(); } throw new IllegalStateException( "at least one node operation did not completed properly: " + nodeResults, rootException); } LoadTestNodeOperationResult nodeOperationResult = (LoadTestNodeOperationResult) operationResult; queryResults.addAll(nodeOperationResult.getQueryResults()); } LOG.info("Received " + queryResults.size() + " queries, expected " + queryRate * _runTime / 1000); File statisticsFile = new File(_resultDir, "load-test-log-" + _startTime + ".log"); File resultsFile = new File(_resultDir, "load-test-results-" + _startTime + ".log"); Writer statisticsWriter = new OutputStreamWriter(new FileOutputStream(statisticsFile, true)); Writer resultWriter = new OutputStreamWriter(new FileOutputStream(resultsFile, true)); if (_currentIteration == 0) { // print headers statisticsWriter.append("#queryRate \tnode \tstartTime \tendTime \telapseTime \tquery \n"); resultWriter.append( "#requestedQueryRate \tachievedQueryRate \tfiredQueries \tqueryErrors \tavarageQueryDuration \tstandardDeviation \n"); } try { StorelessUnivariateStatistic timeStandardDeviation = new StandardDeviation(); StorelessUnivariateStatistic timeMean = new Mean(); int errors = 0; for (LoadTestQueryResult result : queryResults) { long elapsedTime = result.getEndTime() > 0 ? result.getEndTime() - result.getStartTime() : -1; statisticsWriter.write(queryRate + "\t" + result.getNodeId() + "\t" + result.getStartTime() + "\t" + result.getEndTime() + "\t" + elapsedTime + "\t" + result.getQuery() + "\n"); if (elapsedTime != -1) { timeStandardDeviation.increment(elapsedTime); timeMean.increment(elapsedTime); } else { ++errors; } } resultWriter.write(queryRate + "\t" + ((double) queryResults.size() / (_runTime / 1000)) + "\t" + queryResults.size() + "\t" + errors + "\t" + (int) timeMean.getResult() + "\t" + (int) timeStandardDeviation.getResult() + "\n"); } catch (IOException e) { throw new IllegalStateException("Failed to write statistics data.", e); } try { LOG.info("results written to " + resultsFile.getAbsolutePath()); LOG.info("statistics written to " + statisticsFile.getAbsolutePath()); statisticsWriter.close(); resultWriter.close(); } catch (IOException e) { LOG.warn("Failed to close statistics file."); } if (queryRate + _step <= _endRate) { _currentIteration++; LOG.info("triggering next iteration " + _currentIteration); context.getMasterQueue().add(this); } else { LOG.info("finish load test in iteration " + _currentIteration + " after " + (System.currentTimeMillis() - _startTime) + " ms"); context.getProtocol().removeFlag(getName()); } } catch (Exception e) { context.getProtocol().removeFlag(getName()); } }