示例#1
0
 private boolean isHigh() {
   return (_callTrackerStats.getCallCount() >= adjustedMinCallCount()
           && (_latency >= _config.getHighLatency()
               || _callTrackerStats.getErrorRate() >= _config.getHighErrorRate()))
       || (_callTrackerStats.getOutstandingCount() >= _config.getMinOutstandingCount()
           && _outstandingLatency >= _config.getHighOutstanding());
 }
示例#2
0
 private boolean isLow() {
   return _callTrackerStats.getCallCount() >= adjustedMinCallCount()
       && _latency <= _config.getLowLatency()
       && _callTrackerStats.getErrorRate() <= _config.getLowErrorRate()
       && (_callTrackerStats.getOutstandingCount() < _config.getMinOutstandingCount()
           || _outstandingLatency <= _config.getLowOutstanding());
 }
示例#3
0
 /**
  * checks if the stats that we used to compute drop rate is stale or not. Stale meaning, we use a
  * certain interval (configured to be 5 seconds) to count the number of calls, latency, etc during
  * that 5 seconds. So every 5 seconds we'll want to refresh the window of interval for counting.
  *
  * <p>So if it's stale, we'll call CallTrackerImpl to refresh the window
  *
  * @param now
  */
 private void checkStale(long now) {
   if (_callTrackerStats.stale(now)) {
     // this code is a bit strange at first i.e. why it's not _callTrackerStats =
     // _callTracker.getCallStats();
     // but instead it's just _callTracker.getCallStats(); even though getCallStats returns a new
     // Object.
     // but this is fine because getCallStats() will eventually call Tracker.rolloverStats() which
     // has a listener!
     // the listener is actually {@see DegraderImpl.rollOverStats(CallTracker.CallStats)} which
     // will update
     // _callTrackerStats with the new stats. So we're fine.
     _callTracker.getCallStats();
   }
 }
示例#4
0
 public synchronized Stats getStats() {
   checkStale(_clock.currentTimeMillis());
   return new Stats(
       _dropRate,
       _computedDropRate,
       _countTotal.get(),
       _noOverrideDropCountTotal.get(),
       _droppedCountTotal.get(),
       _lastNotDroppedTime.get(),
       _callTrackerStats.getInterval(),
       _callTrackerStats.getIntervalEndTime(),
       _lastIntervalDroppedRate,
       _callTrackerStats.getCallCount(),
       _latency,
       _callTrackerStats.getErrorRate(),
       _outstandingLatency,
       _callTrackerStats.getOutstandingCount(),
       _callTrackerStats.getErrorTypeCountsTotal());
 }
示例#5
0
 private void snapLatency() {
   CallTracker.CallStats stats = _callTrackerStats;
   switch (_config._latencyToUse) {
     case PCT50:
       _latency = stats.getCallTimeStats().get50Pct();
       break;
     case PCT90:
       _latency = stats.getCallTimeStats().get90Pct();
       break;
     case PCT95:
       _latency = stats.getCallTimeStats().get95Pct();
       break;
     case PCT99:
       _latency = stats.getCallTimeStats().get99Pct();
       break;
     case AVERAGE:
       _latency = Math.round(stats.getCallTimeStats().getAverage());
       break;
     default:
       throw new IllegalArgumentException(
           "Latency to use " + _config._latencyToUse + " is unknown");
   }
 }
示例#6
0
 private void snapOutstandingLatency() {
   CallTracker.CallStats stats = _callTrackerStats;
   _outstandingLatency = stats.getOutstandingStartTimeAvg();
 }
示例#7
0
  private synchronized void rolloverStats(CallTracker.CallStats stats) {
    _callTrackerStats = stats;

    snapLatency();
    snapOutstandingLatency();

    if (_config.isLogEnabled()) {
      log.info(_config.getName() + " " + _callTrackerStats);
    }

    long countTotal = _countTotal.get();
    long noOverrideDropCountTotal = _noOverrideDropCountTotal.get();
    long droppedCountTotal = _droppedCountTotal.get();
    long dropped = droppedCountTotal - _lastIntervalDroppedCountTotal;
    long count = countTotal - _lastIntervalCountTotal;

    double lastIntervalDroppedRate = count == 0 ? 0.0 : (double) dropped / (double) count;

    double oldDropRate = _computedDropRate;
    double newDropRate = oldDropRate;
    if (oldDropRate < _config.getMaxDropRate() && isHigh()) {
      newDropRate = Math.min(_config.getMaxDropRate(), oldDropRate + _config.getUpStep());
    } else if (oldDropRate > 0.0 && isLow()) {
      newDropRate = Math.max(0.0, oldDropRate - _config.getDownStep());
    }

    if (oldDropRate != newDropRate) {
      if (log.isWarnEnabled()) {
        log.warn(
            _config.getName()
                + " ComputedDropRate "
                + (oldDropRate > newDropRate ? "decreased" : "increased")
                + " from "
                + oldDropRate
                + " to "
                + newDropRate
                + ", OverrideDropRate="
                + _config.getOverrideDropRate()
                + ", AdjustedMinCallCount="
                + adjustedMinCallCount()
                + ", CallCount="
                + _callTrackerStats.getCallCount()
                + ", Latency="
                + _latency
                + ", ErrorRate="
                + stats.getErrorRate()
                + ", OutstandingLatency="
                + _outstandingLatency
                + ", OutstandingCount="
                + stats.getOutstandingCount()
                + ", CountTotal="
                + countTotal
                + ", NoOverrideDropCountTotal="
                + noOverrideDropCountTotal
                + ", DroppedCountTotal="
                + droppedCountTotal
                + ", LastIntervalDroppedRate="
                + lastIntervalDroppedRate);
      }
    } else {
      if (_config.isLogEnabled() && log.isInfoEnabled()) {
        log.info(
            _config.getName()
                + " ComputedDropRate="
                + newDropRate
                + ", OverrideDropRate="
                + _config.getOverrideDropRate()
                + ", AdjustedMinCallCount="
                + adjustedMinCallCount()
                + ", CallCount="
                + _callTrackerStats.getCallCount()
                + ", Latency="
                + _latency
                + ", ErrorRate="
                + stats.getErrorRate()
                + ", OutstandingLatency="
                + _outstandingLatency
                + ", OutstandingCount="
                + stats.getOutstandingCount()
                + ", CountTotal="
                + countTotal
                + ", NoOverrideDropCountTotal="
                + noOverrideDropCountTotal
                + ", DroppedCountTotal="
                + droppedCountTotal
                + ", LastIntervalDroppedRate="
                + lastIntervalDroppedRate);
      } else if (log.isDebugEnabled()) {
        log.debug(
            _config.getName()
                + " ComputedDropRate="
                + newDropRate
                + ", OverrideDropRate="
                + _config.getOverrideDropRate()
                + ", AdjustedMinCallCount="
                + adjustedMinCallCount()
                + ", CallCount="
                + _callTrackerStats.getCallCount()
                + ", Latency="
                + _latency
                + ", ErrorRate="
                + stats.getErrorRate()
                + ", OutstandingLatency="
                + _outstandingLatency
                + ", OutstandingCount="
                + stats.getOutstandingCount()
                + ", CountTotal="
                + countTotal
                + ", NoOverrideDropCountTotal="
                + noOverrideDropCountTotal
                + ", DroppedCountTotal="
                + droppedCountTotal
                + ", LastIntervalDroppedRate="
                + lastIntervalDroppedRate);
      }
    }

    _lastIntervalCountTotal = countTotal;
    _lastIntervalDroppedCountTotal = droppedCountTotal;
    _lastIntervalDroppedRate = lastIntervalDroppedRate;
    setComputedDropRate(newDropRate);
  }