コード例 #1
0
ファイル: SingleConsole.java プロジェクト: qz267/ngrinder
  /*
   * (non-Javadoc)
   *
   * @see
   * net.grinder.console.model.SampleListener#update(net.grinder.statistics
   * .StatisticsSet, net.grinder.statistics.StatisticsSet)
   */
  @Override
  public void update(
      final StatisticsSet intervalStatistics, final StatisticsSet cumulativeStatistics) {
    try {
      if (!capture) {
        return;
      }
      samplingCount++;
      long currentPeriod = cumulativeStatistics.getValue(getSampleModel().getPeriodIndex());
      setTpsValue(sampleModel.getTPSExpression().getDoubleValue(intervalStatistics));
      checkTooLowTps(getTpsValues());
      updateStatistics(intervalStatistics, cumulativeStatistics);

      writeIntervalCsvData(intervalStatistics);
      int interval = getSampleModel().getSampleInterval();
      long gap = 1;
      if (samplingCount == 1) {
        lastSamplingPeriod = currentPeriod;
      } else {
        lastSamplingPeriod = lastSamplingPeriod + interval;
        gap = ((currentPeriod - lastSamplingPeriod) / interval);
      }
      // Adjust sampling delay.. run write data multiple times... when it
      // takes longer than 1
      // sec.

      samplingLifeCycleListener.apply(
          new Informer<SamplingLifeCycleListener>() {
            @Override
            public void inform(SamplingLifeCycleListener listener) {
              listener.onSampling(getReportPath(), intervalStatistics, cumulativeStatistics);
            }
          });
      for (int i = 0; i < (gap + 1); i++) {
        final boolean lastCall = (samplingCount == 1 && i == 0) || (samplingCount != 1 && i == gap);
        writeIntervalSummaryData(intervalStatistics, lastCall);
        if (interval >= (MIN_SAMPLING_INTERVAL_TO_ACTIVATE_TPS_PER_TEST)) {
          writeIntervalSummaryDataPerTest(intervalStatisticMapPerTest, lastCall);
        }
        samplingLifeCycleFollowupListener.apply(
            new Informer<SamplingLifeCycleFollowUpListener>() {
              @Override
              public void inform(SamplingLifeCycleFollowUpListener listener) {
                listener.onSampling(
                    getReportPath(), intervalStatistics, cumulativeStatistics, lastCall);
              }
            });
      }
      checkTooManyError(cumulativeStatistics);
      lastSamplingPeriod = lastSamplingPeriod + (interval * gap);
    } catch (RuntimeException e) {
      LOGGER.error("Error occurred while updating the statistics : {}", e.getMessage());
      LOGGER.debug("Details : ", e);
      throw e;
    }
  }
コード例 #2
0
ファイル: SingleConsole.java プロジェクト: qz267/ngrinder
 /**
  * Check if too many error has been occurred. If the half of total transaction is error for the
  * last 10 secs. It notifies the {@link ConsoleShutdownListener}
  *
  * @param cumulativeStatistics accumulated Statistics
  */
 private void checkTooManyError(StatisticsSet cumulativeStatistics) {
   StatisticsIndexMap statisticsIndexMap = getStatisticsIndexMap();
   long testSum =
       cumulativeStatistics.getCount(statisticsIndexMap.getLongSampleIndex("timedTests"));
   long errors = cumulativeStatistics.getValue(statisticsIndexMap.getLongIndex("errors"));
   if (((double) (testSum + errors)) / 2 < errors) {
     if (lastMomentWhenErrorsMoreThanHalfOfTotalTPSValue == 0) {
       lastMomentWhenErrorsMoreThanHalfOfTotalTPSValue = System.currentTimeMillis();
     } else if (isOverLowTpsThreshhold()) {
       LOGGER.warn(
           "Stop the test because the count of test error is more than"
               + " half of total tps for last {} seconds.",
           TOO_MANY_ERROR_TIME / 1000);
       getListeners()
           .apply(
               new Informer<ConsoleShutdownListener>() {
                 public void inform(ConsoleShutdownListener listener) {
                   listener.readyToStop(StopReason.TOO_MANY_ERRORS);
                 }
               });
       lastMomentWhenErrorsMoreThanHalfOfTotalTPSValue = 0;
     }
   }
 }