You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.MD
+22-22
Original file line number
Diff line number
Diff line change
@@ -134,34 +134,34 @@ thr := NewThrottlerAll( // throttles only if all children throttle
134
134
135
135
| Throttler | Definition | Description |
136
136
|---|---|---|
137
-
| echo |`func NewThrottlerEcho(err error) Throttler`| Always throttles with the specified error back. |
137
+
| echo |`func NewThrottlerEcho(err error) Throttler`| Always throttles with the specified error back.<br> - could return any specified error;|
138
138
| wait |`func NewThrottlerWait(duration time.Duration) Throttler`| Always waits for the specified duration. |
139
139
| square |`func NewThrottlerSquare(duration time.Duration, limit time.Duration, reset bool) Throttler`| Always waits for square growing *[1, 4, 9, 16, ...]* multiplier on the specified initial duration, up until the specified duration limit is reached.<br> If reset is set then after throttler riches the specified duration limit next multiplier value will be reseted. |
140
140
| jitter |`func NewThrottlerJitter(initial time.Duration, limit time.Duration, reset bool, jitter float64) Throttler`| Waits accordingly to undelying square throttler but also adds the provided jitter delta distribution on top.<br> Jitter value is normalized to [0.0, 1.0] range and defines which part of square delay could be randomized in percents.<br> Implementation uses `math/rand` as PRNG function and expects rand seeding by a client. |
| each |`func NewThrottlerEach(threshold uint64) Throttler`| Throttles each periodic *i-th* call defined by the specified threshold. |
144
-
| before |`func NewThrottlerBefore(threshold uint64) Throttler`| Throttles each call below the *i-th* call defined by the specified threshold. |
145
-
| after |`func NewThrottlerAfter(threshold uint64) Throttler`| Throttles each call after the *i-th* call defined by the specified threshold. |
146
-
| chance |`func NewThrottlerChance(threshold float64) Throttler`| Throttles each call with the chance *p* defined by the specified threshold.<br> Chance value is normalized to *[0.0, 1.0]* range.<br> Implementation uses `math/rand` as PRNG function and expects rand seeding by a client. |
147
-
| running |`func NewThrottlerRunning(threshold uint64) Throttler`| Throttles each call which exeeds the running quota *acquired - release**q* defined by the specified threshold. |
141
+
| context |`func NewThrottlerContext() Throttler`| Always throttless on *done* context.<br> - could return `ErrorInternal`;|
142
+
| panic |`func NewThrottlerPanic() Throttler`| Always panics with `ErrorInternal`. |
143
+
| each |`func NewThrottlerEach(threshold uint64) Throttler`| Throttles each periodic *i-th* call defined by the specified threshold.<br> - could return `ErrorThreshold`;|
144
+
| before |`func NewThrottlerBefore(threshold uint64) Throttler`| Throttles each call below the *i-th* call defined by the specified threshold.<br> - could return `ErrorThreshold`;|
145
+
| after |`func NewThrottlerAfter(threshold uint64) Throttler`| Throttles each call after the *i-th* call defined by the specified threshold.<br> - could return `ErrorThreshold`;|
146
+
| chance |`func NewThrottlerChance(threshold float64) Throttler`| Throttles each call with the chance *p* defined by the specified threshold.<br> Chance value is normalized to *[0.0, 1.0]* range.<br> Implementation uses `math/rand` as PRNG function and expects rand seeding by a client.<br> - could return `ErrorThreshold`;|
147
+
| running |`func NewThrottlerRunning(threshold uint64) Throttler`| Throttles each call which exeeds the running quota *acquired - release**q* defined by the specified threshold.<br> - could return `ErrorThreshold`;|
148
148
| buffered |`func NewThrottlerBuffered(threshold uint64) Throttler`| Waits on call which exeeds the running quota *acquired - release**q* defined by the specified threshold until the running quota is available again. |
149
149
| priority |`func NewThrottlerPriority(threshold uint64, levels uint8) Throttler`| Waits on call which exeeds the running quota *acquired - release**q* defined by the specified threshold until the running quota is available again.<br> Running quota is not equally distributed between *n* levels of priority defined by the specified levels.<br> Use `func WithPriority(ctx context.Context, priority uint8) context.Context` to override context call priority, *1* by default. |
150
-
| timed |`func NewThrottlerTimed(threshold uint64, interval time.Duration, quantum time.Duration) Throttler`| Throttles each call which exeeds the running quota *acquired - release**q* defined by the specified threshold in the specified interval.<br> Periodically each specified interval the running quota number is reseted.<br> If quantum is set then quantum will be used instead of interval to provide the running quota delta updates. |
151
-
| latency |`func NewThrottlerLatency(threshold time.Duration, retention time.Duration) Throttler`| Throttles each call after the call latency *l* defined by the specified threshold was exeeded once.<br> If retention is set then throttler state will be reseted after retention duration.<br> Use `func WithTimestamp(ctx context.Context, ts time.Time) context.Context` to specify running duration between throttler *acquire* and *release*. |
152
-
| percentile |`func NewThrottlerPercentile(threshold time.Duration, capacity uint8, percentile float64, retention time.Duration) Throttler`| Throttles each call after the call latency *l* defined by the specified threshold was exeeded once considering the specified percentile.<br> Percentile values are kept in bounded buffer with capacity *c* defined by the specified capacity. <br> If retention is set then throttler state will be reseted after retention duration.<br> Use `func WithTimestamp(ctx context.Context, ts time.Time) context.Context` to specify running duration between throttler *acquire* and *release*. |
153
-
| monitor |`func NewThrottlerMonitor(mnt Monitor, threshold Stats) Throttler`| Throttles call if any of the stats returned by provided monitor exceeds any of the stats defined by the specified threshold or if any internal error occurred.<br> Builtin `Monitor` implementations come with stats caching by default.<br> Use builtin `NewMonitorSystem` to create go system monitor instance. |
154
-
| metric |`func NewThrottlerMetric(mtc Metric) Throttler`| Throttles call if boolean metric defined by the specified boolean metric is reached or if any internal error occurred.<br> Builtin `Metric` implementations come with boolean metric caching by default.<br> Use builtin `NewMetricPrometheus` to create Prometheus metric instance. |
155
-
| enqueuer |`func NewThrottlerEnqueue(enq Enqueuer) Throttler`| Always enqueues message to the specified queue throttles only if any internal error occurred.<br> Use `func WithMessage(ctx context.Context, message interface{}) context.Context` to specify context message for enqueued message and `func WithMarshaler(ctx context.Context, mrsh Marshaler) context.Context` to specify context message marshaler.<br> Builtin `Enqueuer` implementations come with connection reuse and retries by default.<br> Use builtin `func NewEnqueuerRabbit(url string, queue string, retries uint64) Enqueuer` to create RabbitMQ enqueuer instance or `func NewEnqueuerKafka(net string, url string, topic string, retries uint64) Enqueuer` to create Kafka enqueuer instance. |
156
-
| adaptive |`func NewThrottlerAdaptive(threshold uint64, interval time.Duration, quantum time.Duration, step uint64, thr Throttler) Throttler`| Throttles each call which exeeds the running quota *acquired - release**q* defined by the specified threshold in the specified interval.<br> Periodically each specified interval the running quota number is reseted.<br> If quantum is set then quantum will be used instead of interval to provide the running quota delta updates.<br> Provided adapted throttler adjusts the running quota of adapter throttler by changing the value by *d* defined by the specified step, it subtracts *d^2* from the running quota if adapted throttler throttles or adds *d* to the running quota if it doesn't. |
157
-
| pattern |`func NewThrottlerPattern(patterns ...Pattern) Throttler`| Throttles if matching throttler from provided patterns throttles.<br> Use `func WithKey(ctx context.Context, key string) context.Context` to specify key for regexp pattern throttler matching.<br> `Pattern` defines a pair of regexp and related throttler. |
158
-
| ring |`func NewThrottlerRing(thrs ...Throttler) Throttler`| Throttles if the *i-th* call throttler from provided list throttle. |
159
-
| all |`func NewThrottlerAll(thrs ...Throttler) Throttler`| Throttles call if all provided throttlers throttle. |
160
-
| any |`func NewThrottlerAny(thrs ...Throttler) Throttler`| Throttles call if any of provided throttlers throttle. |
161
-
| not |`func NewThrottlerNot(thr Throttler) Throttler`| Throttles call if provided throttler doesn't throttle. |
150
+
| timed |`func NewThrottlerTimed(threshold uint64, interval time.Duration, quantum time.Duration) Throttler`| Throttles each call which exeeds the running quota *acquired - release**q* defined by the specified threshold in the specified interval.<br> Periodically each specified interval the running quota number is reseted.<br> If quantum is set then quantum will be used instead of interval to provide the running quota delta updates.<br> - could return `ErrorThreshold`;|
151
+
| latency |`func NewThrottlerLatency(threshold time.Duration, retention time.Duration) Throttler`| Throttles each call after the call latency *l* defined by the specified threshold was exeeded once.<br> If retention is set then throttler state will be reseted after retention duration.<br> Use `func WithTimestamp(ctx context.Context, ts time.Time) context.Context` to specify running duration between throttler *acquire* and *release*.<br> - could return `ErrorThreshold`;|
152
+
| percentile |`func NewThrottlerPercentile(threshold time.Duration, capacity uint8, percentile float64, retention time.Duration) Throttler`| Throttles each call after the call latency *l* defined by the specified threshold was exeeded once considering the specified percentile.<br> Percentile values are kept in bounded buffer with capacity *c* defined by the specified capacity. <br> If retention is set then throttler state will be reseted after retention duration.<br> Use `func WithTimestamp(ctx context.Context, ts time.Time) context.Context` to specify running duration between throttler *acquire* and *release*.<br> - could return `ErrorThreshold`;|
153
+
| monitor |`func NewThrottlerMonitor(mnt Monitor, threshold Stats) Throttler`| Throttles call if any of the stats returned by provided monitor exceeds any of the stats defined by the specified threshold or if any internal error occurred.<br> Builtin `Monitor` implementations come with stats caching by default.<br> Use builtin `NewMonitorSystem` to create go system monitor instance.<br> - could return `ErrorInternal`;<br> - could return `ErrorThreshold`;|
154
+
| metric |`func NewThrottlerMetric(mtc Metric) Throttler`| Throttles call if boolean metric defined by the specified boolean metric is reached or if any internal error occurred.<br> Builtin `Metric` implementations come with boolean metric caching by default.<br> Use builtin `NewMetricPrometheus` to create Prometheus metric instance.<br> - could return `ErrorInternal`;<br> - could return `ErrorThreshold`;|
155
+
| enqueuer |`func NewThrottlerEnqueue(enq Enqueuer) Throttler`| Always enqueues message to the specified queue throttles only if any internal error occurred.<br> Use `func WithMessage(ctx context.Context, message interface{}) context.Context` to specify context message for enqueued message and `func WithMarshaler(ctx context.Context, mrsh Marshaler) context.Context` to specify context message marshaler.<br> Builtin `Enqueuer` implementations come with connection reuse and retries by default.<br> Use builtin `func NewEnqueuerRabbit(url string, queue string, retries uint64) Enqueuer` to create RabbitMQ enqueuer instance or `func NewEnqueuerKafka(net string, url string, topic string, retries uint64) Enqueuer` to create Kafka enqueuer instance.<br> - could return `ErrorInternal`;|
156
+
| adaptive |`func NewThrottlerAdaptive(threshold uint64, interval time.Duration, quantum time.Duration, step uint64, thr Throttler) Throttler`| Throttles each call which exeeds the running quota *acquired - release**q* defined by the specified threshold in the specified interval.<br> Periodically each specified interval the running quota number is reseted.<br> If quantum is set then quantum will be used instead of interval to provide the running quota delta updates.<br> Provided adapted throttler adjusts the running quota of adapter throttler by changing the value by *d* defined by the specified step, it subtracts *d^2* from the running quota if adapted throttler throttles or adds *d* to the running quota if it doesn't.<br> - could return `ErrorThreshold`;|
157
+
| pattern |`func NewThrottlerPattern(patterns ...Pattern) Throttler`| Throttles if matching throttler from provided patterns throttles.<br> Use `func WithKey(ctx context.Context, key string) context.Context` to specify key for regexp pattern throttler matching.<br> `Pattern` defines a pair of regexp and related throttler.<br> - could return `ErrorInternal`;<br> - could return any underlying throttler error;|
158
+
| ring |`func NewThrottlerRing(thrs ...Throttler) Throttler`| Throttles if the *i-th* call throttler from provided list throttle.<br> - could return `ErrorInternal`;<br> - could return any underlying throttler error;|
159
+
| all |`func NewThrottlerAll(thrs ...Throttler) Throttler`| Throttles call if all provided throttlers throttle.<br> - could return `ErrorInternal`;|
160
+
| any |`func NewThrottlerAny(thrs ...Throttler) Throttler`| Throttles call if any of provided throttlers throttle.<br> - could return `ErrorInternal`;|
161
+
| not |`func NewThrottlerNot(thr Throttler) Throttler`| Throttles call if provided throttler doesn't throttle.<br> - could return `ErrorInternal`;|
162
162
| suppress |`func NewThrottlerSuppress(thr Throttler) Throttler`| Suppresses provided throttler to never throttle. |
163
-
| retry |`func NewThrottlerRetry(thr Throttler, retries uint64) Throttler`| Retries provided throttler error up until the provided retries threshold.<br> Internally retry uses square throttler with `DefaultRetriedDuration` initial duration. |
164
-
| cache |`func NewThrottlerCache(thr Throttler, cache time.Duration) Throttler`| Caches provided throttler calls for the provided cache duration, throttler release resulting resets cache.<br> Only non throttling calls are cached for the provided cache duration. |
163
+
| retry |`func NewThrottlerRetry(thr Throttler, retries uint64) Throttler`| Retries provided throttler error up until the provided retries threshold.<br> Internally retry uses square throttler with `DefaultRetriedDuration` initial duration.<br> - could return any underlying throttler error;|
164
+
| cache |`func NewThrottlerCache(thr Throttler, cache time.Duration) Throttler`| Caches provided throttler calls for the provided cache duration, throttler release resulting resets cache.<br> Only non throttling calls are cached for the provided cache duration.<br> - could return any underlying throttler error;|
0 commit comments