示例#1
0
  private int executeStage(Configuration configuration, Cluster cluster, int stageId) {
    Stage stage =
        masterConfig
            .getScenario()
            .getStage(
                stageId,
                state,
                getCurrentExtras(masterConfig, configuration, cluster),
                state.getReport());
    InitHelper.init(stage);
    StageResult result;
    try {
      if (stage instanceof MasterStage) {
        result = executeMasterStage((MasterStage) stage);
      } else if (stage instanceof DistStage) {
        result = executeDistStage(stageId, (DistStage) stage);
      } else {
        log.error("Stage '" + stage.getName() + "' is neither master nor distributed");
        return -1;
      }
    } finally {
      InitHelper.destroy(stage);
    }

    if (result == StageResult.SUCCESS) {
      return stageId + 1;
    } else if (result == StageResult.FAIL || result == StageResult.EXIT) {
      returnCode = masterConfig.getConfigurations().indexOf(configuration) + 1;
      if (result == StageResult.EXIT) {
        exitFlag = true;
      }
      return -1;
    } else if (result == StageResult.BREAK || result == StageResult.CONTINUE) {
      Stack<String> repeatNames = (Stack<String>) state.get(RepeatStage.REPEAT_NAMES);
      String nextLabel;
      if (repeatNames == null || repeatNames.isEmpty()) {
        log.warn("BREAK or CONTINUE used out of any repeat.");
        return -1;
      } else if (result == StageResult.BREAK) {
        nextLabel = Utils.concat(".", "repeat", repeatNames.peek(), "end");
      } else if (result == StageResult.CONTINUE) {
        nextLabel = Utils.concat(".", "repeat", repeatNames.peek(), "begin");
      } else throw new IllegalStateException();
      int nextStageId = masterConfig.getScenario().getLabel(nextLabel);
      if (nextStageId < 0) {
        log.error("No label '" + nextLabel + "' defined");
      }
      return nextStageId;
    } else {
      throw new IllegalStateException("Result does not match to any type.");
    }
  }
示例#2
0
  public void run() throws Exception {
    try {
      connection =
          new RemoteSlaveConnection(
              masterConfig.getMaxClusterSize(), masterConfig.getHost(), masterConfig.getPort());
      connection.establish();
      state.setMaxClusterSize(masterConfig.getMaxClusterSize());
      // let's create reporters now to fail soon in case of misconfiguration
      ArrayList<Reporter> reporters = new ArrayList<>();
      for (ReporterConfiguration reporterConfiguration : masterConfig.getReporters()) {
        for (ReporterConfiguration.Report report : reporterConfiguration.getReports()) {
          reporters.add(
              ReporterHelper.createReporter(reporterConfiguration.type, report.getProperties()));
        }
      }

      long benchmarkStart = System.currentTimeMillis();
      for (Configuration configuration : masterConfig.getConfigurations()) {
        log.info("Started benchmarking configuration '" + configuration.name + "'");
        state.setConfigName(configuration.name);
        long configStart = System.currentTimeMillis();
        for (Cluster cluster : masterConfig.getClusters()) {
          int clusterSize = cluster.getSize();
          log.info("Starting scenario on " + cluster);
          connection.sendCluster(cluster);
          connection.sendConfiguration(configuration);
          // here we should restart, therefore, we have to send it again
          connection.restartSlaves(clusterSize);
          connection.sendCluster(cluster);
          connection.sendConfiguration(configuration);
          connection.sendScenario(masterConfig.getScenario(), clusterSize);
          state.setCluster(cluster);
          state.setReport(new Report(configuration, cluster));
          long clusterStart = System.currentTimeMillis();
          int stageCount = masterConfig.getScenario().getStageCount();
          int scenarioDestroyId = stageCount - 2;
          int scenarioCleanupId = stageCount - 1;
          try {
            try {
              // ScenarioDestroy and ScenarioCleanup are special ones, executed always
              int nextStageId = 0;
              do {
                nextStageId = executeStage(configuration, cluster, nextStageId);
              } while (nextStageId >= 0 && nextStageId < scenarioDestroyId);
              // run ScenarioDestroy
            } finally {
              executeStage(configuration, cluster, scenarioDestroyId);
            }
          } finally {
            // run ScenarioCleanup
            executeStage(configuration, cluster, scenarioCleanupId);
          }
          log.info(
              "Finished scenario on "
                  + cluster
                  + " in "
                  + Utils.getMillisDurationString(System.currentTimeMillis() - clusterStart));
          state.getReport().addTimelines(connection.receiveTimelines(clusterSize));
          reports.add(state.getReport());
          if (exitFlag) {
            break;
          }
        }
        log.info(
            "Finished benchmarking configuration '"
                + configuration.name
                + "' in "
                + Utils.getMillisDurationString(System.currentTimeMillis() - configStart));
        if (exitFlag) {
          log.info("Exiting whole benchmark");
          break;
        }
      }
      log.info(
          "Executed all benchmarks in "
              + Utils.getMillisDurationString(System.currentTimeMillis() - benchmarkStart)
              + ", reporting...");
      for (Reporter reporter : reporters) {
        try {
          log.info("Running reporter " + reporter);
          reporter.run(Collections.unmodifiableList(reports));
        } catch (Exception e) {
          log.error("Error in reporter " + reporter, e);
          returnCode = 127;
        } finally {
          InitHelper.destroy(reporter);
        }
      }
      String reportersMessage =
          reporters.isEmpty()
              ? "No reporters have been specified."
              : "All reporters have been executed, exiting.";
      log.info(reportersMessage);
    } catch (Throwable e) {
      log.error("Exception in Master.run: ", e);
      returnCode = 127;
    } finally {
      if (connection != null) {
        connection.release();
      }
      ShutDownHook.exit(returnCode);
    }
  }