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
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,13 +23,13 @@ the project!
23
23
To test Ox, use the following dependency, using either [sbt](https://www.scala-sbt.org):
24
24
25
25
```scala
26
-
"com.softwaremill.ox"%%"core"%"0.5.7"
26
+
"com.softwaremill.ox"%%"core"%"0.5.8"
27
27
```
28
28
29
29
Or [scala-cli](https://scala-cli.virtuslab.org):
30
30
31
31
```scala
32
-
//>usingdep"com.softwaremill.ox::core:0.5.7"
32
+
//>usingdep"com.softwaremill.ox::core:0.5.8"
33
33
```
34
34
35
35
Documentation is available at [https://ox.softwaremill.com](https://ox.softwaremill.com), ScalaDocs can be browsed at [https://javadoc.io](https://www.javadoc.io/doc/com.softwaremill.ox).
Copy file name to clipboardExpand all lines: generated-doc/out/info/dependency.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,10 +4,10 @@ To use ox core in your project, add:
4
4
5
5
```scala
6
6
// sbt dependency
7
-
"com.softwaremill.ox"%%"core"%"0.5.7"
7
+
"com.softwaremill.ox"%%"core"%"0.5.8"
8
8
9
9
// scala-cli dependency
10
-
//>usingdepcom.softwaremill.ox::core:0.5.7
10
+
//>usingdepcom.softwaremill.ox::core:0.5.8
11
11
```
12
12
13
13
Ox core depends only on the Java [jox](https://github.com/softwaremill/jox) project, where channels are implemented. There are no other direct or transitive dependencies.
Copy file name to clipboardExpand all lines: generated-doc/out/utils/rate-limiter.md
+16-12Lines changed: 16 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
1
# Rate limiter
2
2
3
-
The rate limiter mechanism allows controlling the rate at which operations are executed. It ensures that at most a certain number of operations are run concurrently within a specified time frame, preventing system overload and ensuring fair resource usage. Note that the implemented limiting mechanism only takes into account the start of execution and not the whole execution of an operation.
3
+
The rate limiter mechanism allows controlling the rate at which operations are executed. It ensures that at most a certain number of operations are run concurrently within a specified time frame, preventing system overload and ensuring fair resource usage.
4
+
5
+
Several rate limiting algorithms are available, either taking into account only the start time of the operation, or the entire duration of its execution.
@@ -34,24 +34,28 @@ The `operation` can be provided directly using a by-name parameter, i.e. `f: =>
34
34
## Configuration
35
35
36
36
The configuration of a `RateLimiter` depends on an underlying algorithm that controls whether an operation can be executed or not. The following algorithms are available:
37
-
-`RateLimiterAlgorithm.FixedWindow(rate: Int, dur: FiniteDuration)` - where `rate` is the maximum number of operations to be executed in fixed windows of `dur` duration.
38
-
-`RateLimiterAlgorithm.SlidingWindow(rate: Int, dur: FiniteDuration)` - where `rate` is the maximum number of operations to be executed in any window of time of duration `dur`.
39
-
-`RateLimiterAlgorithm.Bucket(maximum: Int, dur: FiniteDuration)` - where `maximum` is the maximum capacity of tokens available in the token bucket algorithm and one token is added each `dur`. It can represent both the leaky bucket algorithm or the token bucket algorithm.
37
+
-`StartTimeRateLimiterAlgorithm.FixedWindow(rate: Int, per: FiniteDuration)` - where `rate` is the maximum number of operations to be executed in fixed windows of `per` duration.
38
+
-`StartTimeRateLimiterAlgorithm.SlidingWindow(rate: Int, per: FiniteDuration)` - where `rate` is the maximum number of operations to be executed in any window of time of duration `per`.
39
+
-`StartTimeRateLimiterAlgorithm.LeakyBucket(maximum: Int, per: FiniteDuration)` - where `rate` is the maximum capacity of tokens available in the token bucket algorithm and one token is added each `per`. It can represent both the leaky bucket algorithm or the token bucket algorithm.
40
+
-`DurationRateLimiterAlgorithm.FixedWindow(rate: Int, per: FiniteDuration)` - where `rate` is the maximum number of operations which execution spans fixed windows of `per` duration. Considers whole execution time of an operation. Operation spanning more than one window blocks permits in all windows that it spans.
41
+
-`DurationRateLimiterAlgorithm.SlidingWindow(rate: Int, per: FiniteDuration)` - where `rate` is the maximum number of operations which execution spans any window of time of duration `per`. Considers whole execution time of an operation. Operation release permit after `per` passed since operation ended.
40
42
41
43
### API shorthands
42
44
43
45
You can use one of the following shorthands to define a Rate Limiter with the corresponding algorithm:
The `RateLimiterAlgorithm` employed by `RateLimiter` can be extended to implement new algorithms or modify existing ones. Its interface is modelled like that of a `Semaphore` although the underlying implementation could be different. For best compatibility with the existing interface of `RateLimiter`, methods `acquire` and `tryAcquire` should offer the same guaranties as Java's `Semaphores`.
57
+
The `RateLimiterAlgorithm` employed by `RateLimiter` can be extended to implement new algorithms or modify existing ones. Its interface is modelled like that of a `Semaphore` although the underlying implementation could be different. For best compatibility with the existing interface of `RateLimiter`, methods `acquire` and `tryAcquire` should offer the same guaranties as Java's `Semaphores`. There is also method `def runOperation[T](operation: => T, permits: Int): T` for cases where considering span of execution may be necessary (see implementations in `DurationRateLimiterAlgorithm`).
54
58
55
-
Additionally, there are two methods employed by the `GenericRateLimiter` for updating its internal state automatically:
59
+
Additionally, there are two methods employed by the `RateLimiter` for updating its internal state automatically:
56
60
-`def update(): Unit`: Updates the internal state of the rate limiter to reflect its current situation. Invoked in a background fork repeatedly, when a rate limiter is created.
57
61
-`def getNextUpdate: Long`: Returns the time in nanoseconds after which a new `update` needs to be called.
0 commit comments