/** * Determine if a request should be dropped to reduce load. * * @see Degrader#checkDrop(double) */ public boolean checkDrop(double code) { long now = _clock.currentTimeMillis(); checkStale(now); _countTotal.incrementAndGet(); double dropRate = _dropRate; double computedDropRate = _computedDropRate; boolean drop; if (code < dropRate) { long lastNotDropped = _lastNotDroppedTime.get(); if ((lastNotDropped + _maxDropDuration) <= now) { drop = !_lastNotDroppedTime.compareAndSet(lastNotDropped, now); } else { drop = true; } if (drop) { _droppedCountTotal.incrementAndGet(); } } else { drop = false; _lastNotDroppedTime.set(now); } if (code < computedDropRate) { _noOverrideDropCountTotal.incrementAndGet(); } return drop; }
public synchronized void reset() { setComputedDropRate(0.0); _lastIntervalCountTotal = 0; _lastIntervalDroppedCountTotal = 0; _lastIntervalDroppedRate = 0.0; _lastResetTime = _clock.currentTimeMillis(); _lastNotDroppedTime.set(_lastResetTime); _countTotal.set(0); _noOverrideDropCountTotal.set(0); _droppedCountTotal.set(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()); }