/// <summary> /// When an event occurs at the specified time, this method reflects that in /// the rolling window. /// </summary> /// <remarks> /// When an event occurs at the specified time, this method reflects that in /// the rolling window. /// <p/> /// </remarks> /// <param name="time">the time at which the event occurred</param> /// <param name="delta">the delta that will be added to the window</param> public virtual void IncAt(long time, long delta) { int bi = ComputeBucketIndex(time); RollingWindow.Bucket bucket = buckets[bi]; // If the last time the bucket was updated is out of the scope of the // rolling window, reset the bucket. if (bucket.IsStaleNow(time)) { bucket.SafeReset(time); } bucket.Inc(delta); }
/// <param name="windowLenMs"> /// The period that is covered by the window. This period must /// be more than the buffering delays. /// </param> /// <param name="numBuckets">number of buckets in the window</param> internal RollingWindow(int windowLenMs, int numBuckets) { buckets = new RollingWindow.Bucket[numBuckets]; for (int i = 0; i < numBuckets; i++) { buckets[i] = new RollingWindow.Bucket(this); } this.windowLenMs = windowLenMs; this.bucketSize = windowLenMs / numBuckets; if (this.bucketSize % bucketSize != 0) { throw new ArgumentException("The bucket size in the rolling window is not integer: windowLenMs= " + windowLenMs + " numBuckets= " + numBuckets); } }