Show / Hide Table of Contents

Class SlidingWindowThrottle

Efficiently calculates the throttling rate over a number of seconds. The algorithm implements a variation of token bucket algorithm that doesn't require to add tokens to the bucket on a timer but rather it maintains a cirtular buffer of tokens with resolution of 1/BucketsPerSec. The Add() function is used to add items to a bucket associated with the timestamp passed as the first argument to the function. The Sum() returns the total number of items over the given interval of seconds. The items automatically expire when the time moves on the successive invocations of the Add() method.

Inheritance
System.Object
DisposableObject
ApplicationComponent
Throttle
SlidingWindowThrottle
Implements
IConfigurable
IThrottle
IApplicationComponent
System.IDisposable
Inherited Members
Throttle.Throttling
Throttle.Name
Throttle.Unit
Throttle.Try()
Throttle.Try(Double)
Throttle.Register(IThrottling)
Throttle.Unregister()
Throttle.Configure(IConfigSectionNode)
ApplicationComponent.AllComponents
ApplicationComponent.GetAppComponentBySID(UInt64)
ApplicationComponent.GetAppComponentByCommonName(String)
ApplicationComponent.ComponentSID
ApplicationComponent.ComponentStartTime
ApplicationComponent.ComponentCommonName
ApplicationComponent.ComponentDirector
DisposableObject.DisposeAndNull<T>(T)
DisposableObject.DisposeStarted
DisposableObject.Disposed
DisposableObject.EnsureObjectNotDisposed()
DisposableObject.Dispose()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: NFX.Throttling
Assembly: NFX.dll
Syntax
public class SlidingWindowThrottle : Throttle, IConfigurable, IThrottle, IApplicationComponent, IDisposable

Constructors

SlidingWindowThrottle()

Declaration
public SlidingWindowThrottle()

SlidingWindowThrottle(String, Int32, Int32, Int32, String)

Constructor

Declaration
public SlidingWindowThrottle(string name, int throttleLimit, int throttleInterval, int bucketsPerSecond = 5, string unit = null)
Parameters
Type Name Description
System.String name

Name of this instance

System.Int32 throttleLimit

Throttling limit per throttleInterval

System.Int32 throttleInterval

Throttling interval in number of seconds

System.Int32 bucketsPerSecond

Number of buckets per second to calculate internal running sum. The greater the value the more precise the avg calculation is and the longer it takes to calculate

System.String unit

Unit of measurement

Properties

Avg

Return current running average over the throttling interval

Declaration
public double Avg { get; }
Property Value
Type Description
System.Double

BucketsPerSec

Number of measurement buckets per second. The greater the number the more accurate throttle rate is calculated and the slower the calculation gets

Declaration
[Config("$buckets-per-sec", 8)]
public int BucketsPerSec { get; }
Property Value
Type Description
System.Int32

Interval

Return throttling interval in seconds

Declaration
[Config("$interval")]
public int Interval { get; }
Property Value
Type Description
System.Int32

Limit

Return throttle limit over Interval

Declaration
[Config("$limit")]
public double Limit { get; }
Property Value
Type Description
System.Double

Sum

Return current running sum over the throttling interval

Declaration
public double Sum { get; }
Property Value
Type Description
System.Double

Methods

Destructor()

Declaration
protected override void Destructor()
Overrides
Throttle.Destructor()

DoConfigure(IConfigSectionNode)

Declaration
protected override void DoConfigure(IConfigSectionNode node)
Parameters
Type Name Description
IConfigSectionNode node
Overrides
Throttle.DoConfigure(IConfigSectionNode)

Reset()

Reset the internal state of the throttling strategy

Declaration
public override void Reset()
Overrides
Throttle.Reset()

ToString(DateTime)

Dump the internal state to string

Declaration
public string ToString(DateTime time)
Parameters
Type Name Description
System.DateTime time

Time for which to dump internal state to string

Returns
Type Description
System.String

Implements

IConfigurable
IThrottle
IApplicationComponent
System.IDisposable

Extension Methods

MiscUtils.NonNull<T>(T, Func<Exception>, String)
ObjectValueConversion.AsString(Object, String, ConvertErrorHandling)
ObjectValueConversion.AsNonNullOrEmptyString(Object)
ObjectValueConversion.AsLaconicConfig(Object, ConfigSectionNode, String, ConvertErrorHandling)
ObjectValueConversion.AsJSONConfig(Object, ConfigSectionNode, String, ConvertErrorHandling)
ObjectValueConversion.AsXMLConfig(Object, ConfigSectionNode, ConvertErrorHandling)
ObjectValueConversion.AsChar(Object, Char, ConvertErrorHandling)
ObjectValueConversion.AsNullableChar(Object, Nullable<Char>, ConvertErrorHandling)
ObjectValueConversion.AsByte(Object, Byte, ConvertErrorHandling)
ObjectValueConversion.AsNullableByte(Object, Nullable<Byte>, ConvertErrorHandling)
ObjectValueConversion.AsSByte(Object, SByte, ConvertErrorHandling)
ObjectValueConversion.AsNullableSByte(Object, Nullable<SByte>, ConvertErrorHandling)
ObjectValueConversion.AsShort(Object, Int16, ConvertErrorHandling)
ObjectValueConversion.AsNullableShort(Object, Nullable<Int16>, ConvertErrorHandling)
ObjectValueConversion.AsUShort(Object, UInt16, ConvertErrorHandling)
ObjectValueConversion.AsNullableUShort(Object, Nullable<UInt16>, ConvertErrorHandling)
ObjectValueConversion.AsInt(Object, Int32, ConvertErrorHandling)
ObjectValueConversion.AsNullableInt(Object, Nullable<Int32>, ConvertErrorHandling)
ObjectValueConversion.AsUInt(Object, UInt32, ConvertErrorHandling)
ObjectValueConversion.AsNullableUInt(Object, Nullable<UInt32>, ConvertErrorHandling)
ObjectValueConversion.AsLong(Object, Int64, ConvertErrorHandling)
ObjectValueConversion.AsNullableLong(Object, Nullable<Int64>, ConvertErrorHandling)
ObjectValueConversion.AsULong(Object, UInt64, ConvertErrorHandling)
ObjectValueConversion.AsNullableULong(Object, Nullable<UInt64>, ConvertErrorHandling)
ObjectValueConversion.AsDouble(Object, Double, ConvertErrorHandling)
ObjectValueConversion.AsNullableDouble(Object, Nullable<Double>, ConvertErrorHandling)
ObjectValueConversion.AsFloat(Object, Single, ConvertErrorHandling)
ObjectValueConversion.AsNullableFloat(Object, Nullable<Single>, ConvertErrorHandling)
ObjectValueConversion.AsDecimal(Object, Decimal, ConvertErrorHandling)
ObjectValueConversion.AsNullableDecimal(Object, Nullable<Decimal>, ConvertErrorHandling)
ObjectValueConversion.AsBool(Object, Boolean, ConvertErrorHandling)
ObjectValueConversion.AsNullableBool(Object, Nullable<Boolean>, ConvertErrorHandling)
ObjectValueConversion.AsGUID(Object, Guid, ConvertErrorHandling)
ObjectValueConversion.AsNullableGUID(Object, Nullable<Guid>, ConvertErrorHandling)
ObjectValueConversion.AsDateTime(Object)
ObjectValueConversion.AsDateTime(Object, DateTime, ConvertErrorHandling)
ObjectValueConversion.AsNullableDateTime(Object, Nullable<DateTime>, ConvertErrorHandling)
ObjectValueConversion.AsGDID(Object)
ObjectValueConversion.AsGDID(Object, GDID, ConvertErrorHandling)
ObjectValueConversion.AsNullableGDID(Object, Nullable<GDID>, ConvertErrorHandling)
ObjectValueConversion.AsGDIDSymbol(Object)
ObjectValueConversion.AsGDIDSymbol(Object, GDIDSymbol, ConvertErrorHandling)
ObjectValueConversion.AsNullableGDIDSymbol(Object, Nullable<GDIDSymbol>, ConvertErrorHandling)
ObjectValueConversion.AsTimeSpan(Object)
ObjectValueConversion.AsTimeSpan(Object, TimeSpan, ConvertErrorHandling)
ObjectValueConversion.AsNullableTimeSpan(Object, Nullable<TimeSpan>, ConvertErrorHandling)
ObjectValueConversion.AsEnum<TEnum>(Object, TEnum, ConvertErrorHandling)
ObjectValueConversion.AsNullableEnum<TEnum>(Object, Nullable<TEnum>, ConvertErrorHandling)
ObjectValueConversion.AsUri(Object, Uri, ConvertErrorHandling)
JSONExtensions.ToJSON(Object, JSONWritingOptions)
JSONExtensions.ToJSON(Object, TextWriter, JSONWritingOptions)
JSONExtensions.ToJSON(Object, Stream, JSONWritingOptions, Encoding)
ErlObject.ToErlObject(Object)
ErlObject.ToErlObject(Object, ErlTypeOrder, Boolean)
Back to top Copyright © 2006-2018 Agnicore Inc
Generated by DocFX