throttle_machines 0.4.2-aarch64-linux → 0.5.0-aarch64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +231 -0
- data/README.md +89 -14
- data/ext/throttle_machines_native/core/CHANGELOG.md +77 -0
- data/ext/throttle_machines_native/core/README.md +100 -0
- data/ext/throttle_machines_native/extconf.rb +2 -0
- data/ext/throttle_machines_native/ffi/CHANGELOG.md +59 -0
- data/lib/throttle_machines/async_breaker.rb +5 -0
- data/lib/throttle_machines/async_support.rb +16 -21
- data/lib/throttle_machines/breakers.rb +46 -0
- data/lib/throttle_machines/control.rb +25 -46
- data/lib/throttle_machines/controller_helpers.rb +11 -10
- data/lib/throttle_machines/hedged_breaker.rb +4 -6
- data/lib/throttle_machines/hedged_request.rb +29 -42
- data/lib/throttle_machines/instrumentation.rb +10 -75
- data/lib/throttle_machines/limiter.rb +71 -136
- data/lib/throttle_machines/middleware.rb +6 -6
- data/lib/throttle_machines/rack_middleware/allow2_ban.rb +1 -8
- data/lib/throttle_machines/rack_middleware/ban_filter.rb +3 -2
- data/lib/throttle_machines/rack_middleware/configuration.rb +4 -2
- data/lib/throttle_machines/rack_middleware/fail2_ban.rb +5 -21
- data/lib/throttle_machines/rack_middleware/throttle.rb +2 -1
- data/lib/throttle_machines/rack_middleware.rb +3 -1
- data/lib/throttle_machines/storage/base.rb +49 -48
- data/lib/throttle_machines/storage/cache.rb +12 -6
- data/lib/throttle_machines/storage/memory.rb +68 -96
- data/lib/throttle_machines/storage/null.rb +18 -28
- data/lib/throttle_machines/storage/redis/gcra.lua +21 -20
- data/lib/throttle_machines/storage/redis/increment_counter.lua +4 -4
- data/lib/throttle_machines/storage/redis/peek_gcra.lua +16 -16
- data/lib/throttle_machines/storage/redis/peek_token_bucket.lua +22 -18
- data/lib/throttle_machines/storage/redis/token_bucket.lua +31 -19
- data/lib/throttle_machines/storage/redis.rb +63 -69
- data/lib/throttle_machines/throttled_error.rb +4 -1
- data/lib/throttle_machines/version.rb +1 -1
- data/lib/throttle_machines.rb +130 -87
- data/lib/throttle_machines_native/throttle_machines_native.so +0 -0
- data/sig/throttle_machines.rbs +555 -0
- metadata +19 -57
- data/lib/throttle_machines/async_limiter.rb +0 -24
- data/lib/throttle_machines/dependency_error.rb +0 -6
- data/lib/throttle_machines/native_speedup.rb +0 -110
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: throttle_machines
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: aarch64-linux
|
|
6
6
|
authors:
|
|
7
7
|
- Abdelkader Boudih
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -72,108 +72,69 @@ dependencies:
|
|
|
72
72
|
requirements:
|
|
73
73
|
- - ">="
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: 0.
|
|
75
|
+
version: 0.28.0
|
|
76
76
|
type: :runtime
|
|
77
77
|
prerelease: false
|
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
79
|
requirements:
|
|
80
80
|
- - ">="
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
|
-
version: 0.
|
|
82
|
+
version: 0.28.0
|
|
83
83
|
- !ruby/object:Gem::Dependency
|
|
84
84
|
name: chrono_machines
|
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements:
|
|
87
87
|
- - ">="
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: 0.
|
|
89
|
+
version: 0.13.0
|
|
90
90
|
type: :runtime
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
94
|
- - ">="
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: 0.
|
|
96
|
+
version: 0.13.0
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
98
|
name: deadline_machines
|
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
|
100
100
|
requirements:
|
|
101
101
|
- - ">="
|
|
102
102
|
- !ruby/object:Gem::Version
|
|
103
|
-
version:
|
|
103
|
+
version: 0.2.0
|
|
104
104
|
type: :runtime
|
|
105
105
|
prerelease: false
|
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
|
107
107
|
requirements:
|
|
108
108
|
- - ">="
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
|
-
version:
|
|
111
|
-
-
|
|
112
|
-
|
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
|
114
|
-
requirements:
|
|
115
|
-
- - "~>"
|
|
116
|
-
- !ruby/object:Gem::Version
|
|
117
|
-
version: '6.0'
|
|
118
|
-
type: :development
|
|
119
|
-
prerelease: false
|
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
-
requirements:
|
|
122
|
-
- - "~>"
|
|
123
|
-
- !ruby/object:Gem::Version
|
|
124
|
-
version: '6.0'
|
|
125
|
-
- !ruby/object:Gem::Dependency
|
|
126
|
-
name: rake
|
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
|
128
|
-
requirements:
|
|
129
|
-
- - "~>"
|
|
130
|
-
- !ruby/object:Gem::Version
|
|
131
|
-
version: '13.0'
|
|
132
|
-
type: :development
|
|
133
|
-
prerelease: false
|
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
-
requirements:
|
|
136
|
-
- - "~>"
|
|
137
|
-
- !ruby/object:Gem::Version
|
|
138
|
-
version: '13.0'
|
|
139
|
-
- !ruby/object:Gem::Dependency
|
|
140
|
-
name: rake-compiler
|
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
|
142
|
-
requirements:
|
|
143
|
-
- - "~>"
|
|
144
|
-
- !ruby/object:Gem::Version
|
|
145
|
-
version: '1.3'
|
|
146
|
-
type: :development
|
|
147
|
-
prerelease: false
|
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
-
requirements:
|
|
150
|
-
- - "~>"
|
|
151
|
-
- !ruby/object:Gem::Version
|
|
152
|
-
version: '1.3'
|
|
153
|
-
description: ThrottleMachines provides ultra-thin, elegant rate limiting with temporal
|
|
154
|
-
precision for distributed systems.
|
|
110
|
+
version: 0.2.0
|
|
111
|
+
description: ThrottleMachines limits call rates with a no_std Rust core on Integer-nanosecond
|
|
112
|
+
clocks, over memory, Redis or cache storage, with Rack and Rails integration.
|
|
155
113
|
email:
|
|
156
114
|
- terminale@gmail.com
|
|
157
115
|
executables: []
|
|
158
116
|
extensions: []
|
|
159
117
|
extra_rdoc_files: []
|
|
160
118
|
files:
|
|
119
|
+
- CHANGELOG.md
|
|
161
120
|
- LICENSE
|
|
162
121
|
- README.md
|
|
122
|
+
- ext/throttle_machines_native/core/CHANGELOG.md
|
|
123
|
+
- ext/throttle_machines_native/core/README.md
|
|
124
|
+
- ext/throttle_machines_native/extconf.rb
|
|
125
|
+
- ext/throttle_machines_native/ffi/CHANGELOG.md
|
|
163
126
|
- lib/throttle_machines.rb
|
|
164
127
|
- lib/throttle_machines/async_breaker.rb
|
|
165
|
-
- lib/throttle_machines/async_limiter.rb
|
|
166
128
|
- lib/throttle_machines/async_support.rb
|
|
129
|
+
- lib/throttle_machines/breakers.rb
|
|
167
130
|
- lib/throttle_machines/control.rb
|
|
168
131
|
- lib/throttle_machines/controller_helpers.rb
|
|
169
|
-
- lib/throttle_machines/dependency_error.rb
|
|
170
132
|
- lib/throttle_machines/engine.rb
|
|
171
133
|
- lib/throttle_machines/hedged_breaker.rb
|
|
172
134
|
- lib/throttle_machines/hedged_request.rb
|
|
173
135
|
- lib/throttle_machines/instrumentation.rb
|
|
174
136
|
- lib/throttle_machines/limiter.rb
|
|
175
137
|
- lib/throttle_machines/middleware.rb
|
|
176
|
-
- lib/throttle_machines/native_speedup.rb
|
|
177
138
|
- lib/throttle_machines/rack_middleware.rb
|
|
178
139
|
- lib/throttle_machines/rack_middleware/allow2_ban.rb
|
|
179
140
|
- lib/throttle_machines/rack_middleware/ban_filter.rb
|
|
@@ -199,13 +160,14 @@ files:
|
|
|
199
160
|
- lib/throttle_machines/unsupported_operation_error.rb
|
|
200
161
|
- lib/throttle_machines/version.rb
|
|
201
162
|
- lib/throttle_machines_native/throttle_machines_native.so
|
|
163
|
+
- sig/throttle_machines.rbs
|
|
202
164
|
homepage: https://github.com/seuros/throttle_machines
|
|
203
165
|
licenses:
|
|
204
166
|
- MIT
|
|
205
167
|
metadata:
|
|
206
168
|
homepage_uri: https://github.com/seuros/throttle_machines
|
|
207
169
|
source_code_uri: https://github.com/seuros/throttle_machines
|
|
208
|
-
changelog_uri: https://github.com/seuros/throttle_machines/blob/
|
|
170
|
+
changelog_uri: https://github.com/seuros/throttle_machines/blob/master/CHANGELOG.md
|
|
209
171
|
rubygems_mfa_required: 'true'
|
|
210
172
|
cargo_crate_name: throttle_machines_native
|
|
211
173
|
cargo_manifest_path: ext/throttle_machines_native/ffi/Cargo.toml
|
|
@@ -230,5 +192,5 @@ requirements: []
|
|
|
230
192
|
rubygems_version: 3.5.23
|
|
231
193
|
signing_key:
|
|
232
194
|
specification_version: 4
|
|
233
|
-
summary:
|
|
195
|
+
summary: Rate limiting (GCRA, token bucket, fixed window) with a native Rust core
|
|
234
196
|
test_files: []
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ThrottleMachines
|
|
4
|
-
# Backward-compatible async-aware limiter class.
|
|
5
|
-
#
|
|
6
|
-
# Example:
|
|
7
|
-
# limiter = ThrottleMachines::AsyncLimiter.new("api",
|
|
8
|
-
# limit: 100,
|
|
9
|
-
# period: 60,
|
|
10
|
-
# algorithm: :gcra
|
|
11
|
-
# )
|
|
12
|
-
#
|
|
13
|
-
# Async do
|
|
14
|
-
# if limiter.allowed_async?
|
|
15
|
-
# # Currently allowed without consuming capacity
|
|
16
|
-
# end
|
|
17
|
-
#
|
|
18
|
-
# limiter.throttle_async(max_wait: 5) do
|
|
19
|
-
# # Consumes capacity through the same atomic path as throttle!
|
|
20
|
-
# end
|
|
21
|
-
# end
|
|
22
|
-
class AsyncLimiter < Limiter
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Native speedup for ThrottleMachines using Rust FFI.
|
|
4
|
-
#
|
|
5
|
-
# This module is automatically loaded when the native extension is available.
|
|
6
|
-
# It prepends optimized implementations onto Storage::Memory.
|
|
7
|
-
#
|
|
8
|
-
# Environment controls:
|
|
9
|
-
# DISABLE_MATRYOSHKA_NATIVE=1 - Disable all matryoshka native extensions
|
|
10
|
-
# DISABLE_THROTTLE_MACHINES_NATIVE=1 - Disable only throttle_machines native
|
|
11
|
-
# DEBUG_MATRYOSHKA=1 - Log which backend is loaded
|
|
12
|
-
|
|
13
|
-
return if ENV["DISABLE_MATRYOSHKA_NATIVE"]
|
|
14
|
-
return if ENV["DISABLE_THROTTLE_MACHINES_NATIVE"]
|
|
15
|
-
|
|
16
|
-
begin
|
|
17
|
-
require "throttle_machines_native/throttle_machines_native"
|
|
18
|
-
|
|
19
|
-
module ThrottleMachines
|
|
20
|
-
module Storage
|
|
21
|
-
# Native GCRA implementation using Rust.
|
|
22
|
-
module NativeGCRA
|
|
23
|
-
def check_gcra_limit(key, emission_interval, delay_tolerance, ttl)
|
|
24
|
-
reclaim_capacity
|
|
25
|
-
with_write_lock(key) do
|
|
26
|
-
now = current_time
|
|
27
|
-
state = @gcra_states[key] || { tat: 0.0 }
|
|
28
|
-
|
|
29
|
-
# Rust does the math
|
|
30
|
-
ThrottleMachinesNative.gcra_check(
|
|
31
|
-
state[:tat], now, emission_interval, delay_tolerance
|
|
32
|
-
) => { allowed:, state: new_tat, retry_after: }
|
|
33
|
-
|
|
34
|
-
if allowed && !store_entry(@gcra_states, key, { tat: new_tat, expires_at: now + ttl })
|
|
35
|
-
return capacity_gcra_refusal(now, delay_tolerance)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
{ allowed: allowed, retry_after: retry_after, tat: new_tat }
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def peek_gcra_limit(key, _emission_interval, delay_tolerance)
|
|
43
|
-
reclaim_capacity
|
|
44
|
-
with_read_lock(key) do
|
|
45
|
-
now = current_time
|
|
46
|
-
return capacity_gcra_refusal(now, delay_tolerance) unless capacity_available?(@gcra_states, key)
|
|
47
|
-
|
|
48
|
-
state = @gcra_states[key] || { tat: 0.0 }
|
|
49
|
-
|
|
50
|
-
# Rust does the math
|
|
51
|
-
ThrottleMachinesNative.gcra_peek(
|
|
52
|
-
state[:tat], now, delay_tolerance
|
|
53
|
-
) => { allowed:, state: tat, retry_after: }
|
|
54
|
-
|
|
55
|
-
{ allowed: allowed, retry_after: retry_after, tat: tat }
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# Native Token Bucket implementation using Rust.
|
|
61
|
-
module NativeTokenBucket
|
|
62
|
-
def check_token_bucket(key, capacity, refill_rate, ttl)
|
|
63
|
-
reclaim_capacity
|
|
64
|
-
with_write_lock(key) do
|
|
65
|
-
now = current_time
|
|
66
|
-
bucket = @token_buckets[key] || { tokens: capacity, last_refill: now }
|
|
67
|
-
|
|
68
|
-
# Rust does the math
|
|
69
|
-
ThrottleMachinesNative.token_bucket_check(
|
|
70
|
-
bucket[:tokens], bucket[:last_refill], now, capacity, refill_rate
|
|
71
|
-
) => { allowed:, state: new_tokens, retry_after: }
|
|
72
|
-
|
|
73
|
-
if allowed
|
|
74
|
-
unless store_entry(@token_buckets, key, { tokens: new_tokens, last_refill: now, expires_at: now + ttl })
|
|
75
|
-
return capacity_token_bucket_refusal
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
{ allowed: allowed, retry_after: retry_after, tokens_remaining: new_tokens.floor }
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def peek_token_bucket(key, capacity, refill_rate)
|
|
84
|
-
reclaim_capacity
|
|
85
|
-
with_read_lock(key) do
|
|
86
|
-
now = current_time
|
|
87
|
-
return capacity_token_bucket_refusal unless capacity_available?(@token_buckets, key)
|
|
88
|
-
|
|
89
|
-
bucket = @token_buckets[key] || { tokens: capacity, last_refill: now }
|
|
90
|
-
|
|
91
|
-
# Rust does the math
|
|
92
|
-
ThrottleMachinesNative.token_bucket_peek(
|
|
93
|
-
bucket[:tokens], bucket[:last_refill], now, capacity, refill_rate
|
|
94
|
-
) => { allowed:, state: tokens, retry_after: }
|
|
95
|
-
|
|
96
|
-
{ allowed: allowed, retry_after: retry_after, tokens_remaining: tokens.floor }
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
# Prepend native implementations
|
|
104
|
-
ThrottleMachines::Storage::Memory.prepend(ThrottleMachines::Storage::NativeGCRA)
|
|
105
|
-
ThrottleMachines::Storage::Memory.prepend(ThrottleMachines::Storage::NativeTokenBucket)
|
|
106
|
-
|
|
107
|
-
warn "[ThrottleMachines] Native speedup loaded" if ENV["DEBUG_MATRYOSHKA"]
|
|
108
|
-
rescue LoadError => e
|
|
109
|
-
warn "[ThrottleMachines] Native speedup unavailable: #{e.message}" if ENV["DEBUG_MATRYOSHKA"]
|
|
110
|
-
end
|