falcon-limiter 0.1.2 → 0.3.0
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
- checksums.yaml.gz.sig +0 -0
- data/lib/falcon/limiter/environment.rb +9 -2
- data/lib/falcon/limiter/middleware.rb +6 -3
- data/lib/falcon/limiter/semaphore.rb +3 -2
- data/lib/falcon/limiter/socket.rb +2 -2
- data/lib/falcon/limiter/version.rb +1 -1
- data/readme.md +24 -0
- data/releases.md +8 -0
- data.tar.gz.sig +0 -0
- metadata +20 -6
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: efce26d7d356f61fc199b952971ffb0aa4b30b12951b7cdb1f6679dc3efce8d4
|
|
4
|
+
data.tar.gz: fe3034b672f0d63c7474022af9f9c757ad9e4046f90254e61b034ec15cb79682
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8be62c56f78e18866b8278e57ff3591d45ecb27ef7046e6efb29ea33876c078b87bc670be31bcbcf1194cdcab14ad4acd364b091a9a96ff26a06b0d12f26cf96
|
|
7
|
+
data.tar.gz: 9fd43adf07deb0227c5f86492abdd5aac9ef39a1d48eec6cf9fb4781d31a65c61b53011c2f3794b076734580bfe39da09e9dc1e5f90dcd4e592b4a11e4c39785
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
require_relative "middleware"
|
|
8
8
|
require_relative "semaphore"
|
|
9
9
|
require_relative "wrapper"
|
|
10
|
+
require "async/utilization"
|
|
10
11
|
|
|
11
12
|
module Falcon
|
|
12
13
|
module Limiter
|
|
@@ -32,13 +33,18 @@ module Falcon
|
|
|
32
33
|
0.1
|
|
33
34
|
end
|
|
34
35
|
|
|
36
|
+
# @returns [Async::Utilization::Registry] The utilization registry for limiter metrics.
|
|
37
|
+
def limiter_utilization
|
|
38
|
+
@limiter_utilization ||= Async::Utilization::Registry.new
|
|
39
|
+
end
|
|
40
|
+
|
|
35
41
|
# @returns [Async::Limiter::Queued] The limiter for coordinating long tasks and connection accepts.
|
|
36
42
|
def connection_limiter
|
|
37
43
|
# Create priority queue and pre-populate with tokens:
|
|
38
44
|
queue = Async::PriorityQueue.new
|
|
39
45
|
limiter_maximum_connections.times{queue.push(true)}
|
|
40
46
|
|
|
41
|
-
Async::Limiter::Queued.new(queue)
|
|
47
|
+
Async::Limiter::Queued.new(queue, utilization: limiter_utilization.namespace(:socket_accept))
|
|
42
48
|
end
|
|
43
49
|
|
|
44
50
|
# @returns [Class] The middleware class to use for long task support.
|
|
@@ -54,7 +60,8 @@ module Falcon
|
|
|
54
60
|
middleware,
|
|
55
61
|
connection_limiter: connection_limiter,
|
|
56
62
|
maximum_long_tasks: limiter_maximum_long_tasks,
|
|
57
|
-
start_delay: limiter_start_delay
|
|
63
|
+
start_delay: limiter_start_delay,
|
|
64
|
+
utilization: limiter_utilization
|
|
58
65
|
)
|
|
59
66
|
else
|
|
60
67
|
middleware
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
# Copyright, 2025, by Samuel Williams.
|
|
6
6
|
|
|
7
7
|
require "protocol/http/middleware"
|
|
8
|
+
require "async/utilization"
|
|
8
9
|
require_relative "long_task"
|
|
9
10
|
require_relative "semaphore"
|
|
10
11
|
|
|
@@ -18,16 +19,18 @@ module Falcon
|
|
|
18
19
|
# @parameter connection_limiter [Async::Limiter] Connection limiter instance for managing accepts.
|
|
19
20
|
# @parameter maximum_long_tasks [Integer] Maximum number of concurrent long tasks (default: 10).
|
|
20
21
|
# @parameter start_delay [Float] Delay in seconds before starting long tasks (default: 0.1).
|
|
21
|
-
|
|
22
|
+
# @parameter utilization [Async::Utilization::Registry] Utilization registry for limiter metrics.
|
|
23
|
+
def initialize(delegate, connection_limiter:, maximum_long_tasks: 10, start_delay: 0.1, utilization: Async::Utilization::Registry.new)
|
|
22
24
|
super(delegate)
|
|
23
25
|
|
|
24
26
|
@maximum_long_tasks = maximum_long_tasks
|
|
25
27
|
@start_delay = start_delay
|
|
26
28
|
@connection_limiter = connection_limiter
|
|
27
|
-
@
|
|
29
|
+
@utilization = utilization
|
|
30
|
+
@long_task_limiter = Semaphore.new(maximum_long_tasks, utilization: utilization.namespace(:long_task))
|
|
28
31
|
end
|
|
29
32
|
|
|
30
|
-
attr_reader :maximum_long_tasks, :start_delay, :long_task_limiter, :connection_limiter
|
|
33
|
+
attr_reader :maximum_long_tasks, :start_delay, :long_task_limiter, :connection_limiter, :utilization
|
|
31
34
|
|
|
32
35
|
# Process an HTTP request with long task management support.
|
|
33
36
|
# Creates a long task context that applications can use to manage I/O operations.
|
|
@@ -15,13 +15,14 @@ module Falcon
|
|
|
15
15
|
module Semaphore
|
|
16
16
|
# Create a new limiter with the specified capacity.
|
|
17
17
|
# @parameter limit [Integer] The maximum number of concurrent operations allowed (default: 1).
|
|
18
|
+
# @parameter options [Hash] Options passed to {Async::Limiter::Queued#initialize}.
|
|
18
19
|
# @returns [Async::Limiter::Queued] A new limiter instance with pre-allocated tokens.
|
|
19
|
-
def self.new(limit = 1)
|
|
20
|
+
def self.new(limit = 1, **options)
|
|
20
21
|
# Create priority queue and pre-populate with tokens
|
|
21
22
|
queue = Async::PriorityQueue.new
|
|
22
23
|
limit.times{queue.push(true)}
|
|
23
24
|
|
|
24
|
-
return Async::Limiter::Queued.new(queue)
|
|
25
|
+
return Async::Limiter::Queued.new(queue, **options)
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
28
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# Released under the MIT License.
|
|
4
|
-
# Copyright, 2025, by Samuel Williams.
|
|
4
|
+
# Copyright, 2025-2026, by Samuel Williams.
|
|
5
5
|
|
|
6
6
|
module Falcon
|
|
7
7
|
module Limiter
|
|
@@ -25,7 +25,7 @@ module Falcon
|
|
|
25
25
|
ensure
|
|
26
26
|
if token = @token
|
|
27
27
|
@token = nil
|
|
28
|
-
token.
|
|
28
|
+
token.close
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
data/readme.md
CHANGED
|
@@ -26,6 +26,14 @@ Please see the [project documentation](https://socketry.github.io/falcon-limiter
|
|
|
26
26
|
|
|
27
27
|
Please see the [project releases](https://socketry.github.io/falcon-limiter/releases/index) for all releases.
|
|
28
28
|
|
|
29
|
+
### v0.3.0
|
|
30
|
+
|
|
31
|
+
- Use `Async::Limiter::Token#close` when closing sockets so cached tokens cannot re-acquire after socket close.
|
|
32
|
+
|
|
33
|
+
### v0.2.0
|
|
34
|
+
|
|
35
|
+
- Use `async-limiter` v2.2 utilization metrics for connection and long task limiter telemetry.
|
|
36
|
+
|
|
29
37
|
### v0.1.0
|
|
30
38
|
|
|
31
39
|
- Initial implementation.
|
|
@@ -46,6 +54,22 @@ We welcome contributions to this project.
|
|
|
46
54
|
4. Push to the branch (`git push origin my-new-feature`).
|
|
47
55
|
5. Create new Pull Request.
|
|
48
56
|
|
|
57
|
+
### Running Tests
|
|
58
|
+
|
|
59
|
+
To run the test suite:
|
|
60
|
+
|
|
61
|
+
``` shell
|
|
62
|
+
bundle exec sus
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Making Releases
|
|
66
|
+
|
|
67
|
+
To make a new release:
|
|
68
|
+
|
|
69
|
+
``` shell
|
|
70
|
+
bundle exec bake gem:release:patch # or minor or major
|
|
71
|
+
```
|
|
72
|
+
|
|
49
73
|
### Developer Certificate of Origin
|
|
50
74
|
|
|
51
75
|
In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
|
data/releases.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Releases
|
|
2
2
|
|
|
3
|
+
## v0.3.0
|
|
4
|
+
|
|
5
|
+
- Use `Async::Limiter::Token#close` when closing sockets so cached tokens cannot re-acquire after socket close.
|
|
6
|
+
|
|
7
|
+
## v0.2.0
|
|
8
|
+
|
|
9
|
+
- Use `async-limiter` v2.2 utilization metrics for connection and long task limiter telemetry.
|
|
10
|
+
|
|
3
11
|
## v0.1.0
|
|
4
12
|
|
|
5
13
|
- Initial implementation.
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: falcon-limiter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
- Josh Teeter
|
|
8
7
|
- Samuel Williams
|
|
8
|
+
- Josh Teeter
|
|
9
9
|
- Francisco Mejia
|
|
10
10
|
- Marc-André Cournoyer
|
|
11
11
|
bindir: bin
|
|
@@ -47,14 +47,28 @@ dependencies:
|
|
|
47
47
|
requirements:
|
|
48
48
|
- - "~>"
|
|
49
49
|
- !ruby/object:Gem::Version
|
|
50
|
-
version: '2.
|
|
50
|
+
version: '2.3'
|
|
51
|
+
type: :runtime
|
|
52
|
+
prerelease: false
|
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - "~>"
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '2.3'
|
|
58
|
+
- !ruby/object:Gem::Dependency
|
|
59
|
+
name: async-utilization
|
|
60
|
+
requirement: !ruby/object:Gem::Requirement
|
|
61
|
+
requirements:
|
|
62
|
+
- - "~>"
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
version: '0.4'
|
|
51
65
|
type: :runtime
|
|
52
66
|
prerelease: false
|
|
53
67
|
version_requirements: !ruby/object:Gem::Requirement
|
|
54
68
|
requirements:
|
|
55
69
|
- - "~>"
|
|
56
70
|
- !ruby/object:Gem::Version
|
|
57
|
-
version: '
|
|
71
|
+
version: '0.4'
|
|
58
72
|
executables: []
|
|
59
73
|
extensions: []
|
|
60
74
|
extra_rdoc_files: []
|
|
@@ -86,14 +100,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
86
100
|
requirements:
|
|
87
101
|
- - ">="
|
|
88
102
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '3.
|
|
103
|
+
version: '3.3'
|
|
90
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
105
|
requirements:
|
|
92
106
|
- - ">="
|
|
93
107
|
- !ruby/object:Gem::Version
|
|
94
108
|
version: '0'
|
|
95
109
|
requirements: []
|
|
96
|
-
rubygems_version:
|
|
110
|
+
rubygems_version: 4.0.3
|
|
97
111
|
specification_version: 4
|
|
98
112
|
summary: Advanced concurrency control and resource limiting for Falcon web server.
|
|
99
113
|
test_files: []
|
metadata.gz.sig
CHANGED
|
Binary file
|