falcon 0.48.6 → 0.49.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a6198414f38d568e93d77452b6efa9b4f9267a5beedb57b8c7a96bd72a174cd
4
- data.tar.gz: 164f1aa2a4407eba29965a0c1acc85364ad734b6a2aa1215d408b3d1e67bd4f5
3
+ metadata.gz: 9e53a58574f18152b0d6a59ef2c20957cd09fe15e8dd3ab593f3692c9ecab092
4
+ data.tar.gz: 96abcd1f8fc3afd6d3f6065e25ecc0f201e28809651f4e16d456c3f0584e9e57
5
5
  SHA512:
6
- metadata.gz: e6942fa58fda793327bfcb767a0e729f2417c90d4dcdb7bbdc9f1a8c81492575b95fc96ee294b69e555322d643f3dd8b0443b38f3efb92a3eb31f68d445ad34e
7
- data.tar.gz: 8d4dcc4a530b7eaf74055e893fec7e101fa8e2419d9dc59713064f54fb679a566091f162220ecf5e25cbcf312db52a4f503dd65fb8398cf1f06c00dbab4ad39a
6
+ metadata.gz: 1002a1e4214a8d0bfda3bb03a5eb6cf29bbbde2559e600b0f40d0ae5e531ada93588138abc90e56b839a8b11e20591b4b9741b948bac0998d4baafe7158cd48f
7
+ data.tar.gz: 52c0ed26d2e5691c81490adeaf12d7eb078a88b0ce0a6dcbbea3f624be724cc619141e259c6da15c7114103b107e567900b6d26086f71c91c7c74cd041ec5cf4
checksums.yaml.gz.sig CHANGED
Binary file
@@ -45,16 +45,22 @@ module Falcon
45
45
 
46
46
  option "--[no]-restart", "Enable/disable automatic restart.", default: true
47
47
  option "--graceful-stop <timeout>", "Duration to wait for graceful stop.", type: Float, default: 1.0
48
+
49
+ option "--health-check-timeout <duration>", "Duration to wait for health check.", type: Float, default: 30.0
48
50
  end
49
51
 
50
52
  def container_options
51
- @options.slice(:count, :forks, :threads, :restart)
53
+ @options.slice(:count, :forks, :threads, :restart, :health_check_timeout)
52
54
  end
53
55
 
54
56
  def endpoint_options
55
57
  @options.slice(:hostname, :port, :timeout)
56
58
  end
57
59
 
60
+ def name
61
+ @options[:hostname] || @options[:bind]
62
+ end
63
+
58
64
  def environment
59
65
  Async::Service::Environment.new(Falcon::Environment::Server).with(
60
66
  Falcon::Environment::Rackup,
@@ -71,7 +77,7 @@ module Falcon
71
77
  preload: [@options[:preload]].compact,
72
78
  url: @options[:bind],
73
79
 
74
- name: "server",
80
+ name: self.name,
75
81
 
76
82
  endpoint: ->{Endpoint.parse(url, **endpoint_options)}
77
83
  )
@@ -9,21 +9,7 @@ require "async/service"
9
9
  module Falcon
10
10
  # Manages environments which describes how to host a specific application.
11
11
  #
12
- # Environments are key-value maps with lazy value resolution. An environment can inherit from a parent environment, which can provide defaults
13
- #
14
- # A typical configuration file might look something like:
15
- #
16
- # ~~~ ruby
17
- # #!/usr/bin/env falcon-host
18
- # # frozen_string_literal: true
19
- #
20
- # load :rack, :self_signed_tls, :supervisor
21
- #
22
- # supervisor
23
- #
24
- # rack 'hello.localhost', :self_signed_tls do
25
- # end
26
- # ~~~
12
+ # Environments are key-value maps with lazy value resolution. An environment can inherit from a parent environment, which can provide defaults or shared configuration.
27
13
  #
28
14
  class Configuration < ::Async::Service::Configuration
29
15
  # Load the specified configuration file. See {Loader#load_file} for more details.
@@ -33,7 +33,7 @@ module Falcon
33
33
 
34
34
  # Options to use when creating the container.
35
35
  def container_options
36
- {restart: true, count: self.count}.compact
36
+ {restart: true, count: self.count, health_check_timeout: 30}.compact
37
37
  end
38
38
 
39
39
  # The host that this server will receive connections for.
@@ -12,6 +12,12 @@ module Falcon
12
12
  module Environment
13
13
  # Provides an environment for hosting a supervisor which can monitor multiple applications.
14
14
  module Supervisor
15
+ # The service class to use for the supervisor.
16
+ # @returns [Class]
17
+ def service_class
18
+ ::Falcon::Service::Supervisor
19
+ end
20
+
15
21
  # The name of the supervisor
16
22
  # @returns [String]
17
23
  def name
@@ -30,10 +36,9 @@ module Falcon
30
36
  ::IO::Endpoint.unix(ipc_path)
31
37
  end
32
38
 
33
- # The service class to use for the supervisor.
34
- # @returns [Class]
35
- def service_class
36
- ::Falcon::Service::Supervisor
39
+ # Options to use when creating the container.
40
+ def container_options
41
+ {restart: true, count: 1, health_check_timeout: 30}
37
42
  end
38
43
  end
39
44
 
data/lib/falcon/server.rb CHANGED
@@ -35,5 +35,53 @@ module Falcon
35
35
  run rack_app
36
36
  end
37
37
  end
38
+
39
+ def initialize(...)
40
+ super
41
+
42
+ @accept_count = 0
43
+ @connection_count = 0
44
+
45
+ @request_count = 0
46
+ @active_count = 0
47
+ end
48
+
49
+ attr :request_count
50
+ attr :accept_count
51
+ attr :connect_count
52
+
53
+ def accept(...)
54
+ @accept_count += 1
55
+ @connection_count += 1
56
+
57
+ super
58
+ ensure
59
+ @connection_count -= 1
60
+ end
61
+
62
+ def call(...)
63
+ @request_count += 1
64
+ @active_count += 1
65
+
66
+ super
67
+ ensure
68
+ @active_count -= 1
69
+ end
70
+
71
+ def statistics_string
72
+ "C=#{format_count @connection_count}/#{format_count @accept_count} R=#{format_count @active_count}/#{format_count @request_count}"
73
+ end
74
+
75
+ private
76
+
77
+ def format_count(value)
78
+ if value > 1_000_000
79
+ "#{(value/1_000_000.0).round(2)}M"
80
+ elsif value > 1_000
81
+ "#{(value/1_000.0).round(2)}K"
82
+ else
83
+ value
84
+ end
85
+ end
38
86
  end
39
87
  end
@@ -52,6 +52,7 @@ module Falcon
52
52
  # @parameter container [Async::Container::Generic]
53
53
  def setup(container)
54
54
  container_options = @evaluator.container_options
55
+ health_check_timeout = container_options[:health_check_timeout]
55
56
 
56
57
  container.run(name: self.name, **container_options) do |instance|
57
58
  evaluator = @environment.evaluator
@@ -63,6 +64,17 @@ module Falcon
63
64
 
64
65
  instance.ready!
65
66
 
67
+ if health_check_timeout
68
+ Async(transient: true) do
69
+ while true
70
+ # We only update this if the health check is enabled. Maybe we should always update it?
71
+ instance.name = "#{self.name} (#{server.statistics_string} L=#{Fiber.scheduler.load.round(3)})"
72
+ sleep(health_check_timeout / 2)
73
+ instance.ready!
74
+ end
75
+ end
76
+ end
77
+
66
78
  task.children.each(&:wait)
67
79
  end
68
80
  end
@@ -69,7 +69,10 @@ module Falcon
69
69
  # Start the supervisor process which accepts connections from the bound endpoint and processes JSON formatted messages.
70
70
  # @parameter container [Async::Container::Generic]
71
71
  def setup(container)
72
- container.run(name: self.name, restart: true, count: 1) do |instance|
72
+ container_options = @evaluator.container_options
73
+ health_check_timeout = container_options[:health_check_timeout]
74
+
75
+ container.run(name: self.name, **container_options) do |instance|
73
76
  Async do
74
77
  @bound_endpoint.accept do |peer|
75
78
  stream = ::IO::Stream(peer)
@@ -81,6 +84,15 @@ module Falcon
81
84
  end
82
85
 
83
86
  instance.ready!
87
+
88
+ if health_check_timeout
89
+ Async(transient: true) do
90
+ while true
91
+ sleep(health_check_timeout / 2)
92
+ instance.ready!
93
+ end
94
+ end
95
+ end
84
96
  end
85
97
  end
86
98
 
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2017-2024, by Samuel Williams.
5
5
 
6
6
  module Falcon
7
- VERSION = "0.48.6"
7
+ VERSION = "0.49.0"
8
8
  end
data/readme.md CHANGED
@@ -45,6 +45,11 @@ Please see the [project documentation](https://socketry.github.io/falcon/) for m
45
45
 
46
46
  Please see the [project releases](https://socketry.github.io/falcon/releases/index) for all releases.
47
47
 
48
+ ### v0.49.0
49
+
50
+ - [Falcon Server Container Health Checks](https://socketry.github.io/falcon/releases/index#falcon-server-container-health-checks)
51
+ - [Falcon Server Process Title](https://socketry.github.io/falcon/releases/index#falcon-server-process-title)
52
+
48
53
  ### v0.48.4
49
54
 
50
55
  - Improve compatibility of rackup handler w.r.t. sinatra.
@@ -53,6 +58,39 @@ Please see the [project releases](https://socketry.github.io/falcon/releases/ind
53
58
 
54
59
  - Fix Falcon Supervisor implementation: due to invalid code, it was unable to start.
55
60
 
61
+ ### Compatibility Fixes
62
+
63
+ During the `v0.44.0` release cycle, the workflows for testing older rack releases were accidentally dropped. As such, `v0.44.0` was not compatible with older versions of rack. This release restores compatibility with older versions of rack.
64
+
65
+ Specifically, `protocol-rack` now provides `Protocol::Rack::Adapter.parse_file` to load Rack applications. Rack 2's `Rack::Builder.parse_file` returns both the application and a set of options (multi-value return). Rack 3 changed this to only return the application, as the prior multi-value return was confusing at best. This change allows `protocol-rack` to work with both versions of rack, and `falcon` adopts that interface.
66
+
67
+ ### Falcon Serve Options
68
+
69
+ In addition, `falcon serve` provides two new options:
70
+
71
+ 1. `--[no]-restart` which controls what happens when `async-container` instances crash. By default, `falcon serve` will restart the container when it crashes. This can be disabled with `--no-restart`.
72
+
73
+ 2. `--graceful-stop [timeout]` which allows you to specify a timeout for graceful shutdown. This is useful when you want to stop the server, but allow existing connections to finish processing before the server stops. This feature is highly experimental and doesn't work correctly in all cases yet, but we are aiming to improve it.
74
+
75
+ ### Falcon Host
76
+
77
+ `async-service` is a new gem that exposes a generic service interface on top of `async-container`. Previously, `falcon host` used `async-container` directly and `build-environment` for configuration. In order to allow for more generic service definitions and configuration, `async-service` now provides a similar interface to `build-environment` and exposes this in a way that can be used for services other tha falcon. This makes it simpler to integrate multiple services into a single application.
78
+
79
+ The current configuration format uses definitions like this:
80
+
81
+ ``` ruby
82
+ rack 'hello.localhost', :self_signed_tls
83
+ ```
84
+
85
+ This changes to:
86
+
87
+ ``` ruby
88
+ service 'hello.localhost' do
89
+ include Falcon::Environment::Rack
90
+ include Falcon::Environment::SelfSignedTLS
91
+ end
92
+ ```
93
+
56
94
  ## Contributing
57
95
 
58
96
  We welcome contributions to this project.
data/releases.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Releases
2
2
 
3
+ ## v0.49.0
4
+
5
+ ### Falcon Server Container Health Checks
6
+
7
+ {ruby Falcon::Service::Server} adds support for the {ruby Async::Container} health check which detects hung processes and restarts them. The default health check interval is 30 seconds.
8
+
9
+ `falcon serve` introduces a new `--health-check-timeout` option to configure the health check timeout. `falcon.rb`/`falcon host` can be changed using the `health_check_timeout` key within the `container_options` configuration - these are passed directly to {ruby Async::Container}. If you don't want a health check, set `health_check_timeout` to `nil`.
10
+
11
+ ### Falcon Server Process Title
12
+
13
+ The Falcon server process title is now updated periodically (alongside the health check) to include information about the numnber of connections and requests.
14
+
15
+ 12211 ttys002 0:00.28 /Users/samuel/.gem/ruby/3.4.1/bin/falcon serve --bind http://localhost:8000
16
+ 12213 ttys002 0:04.14 http://localhost:8000 (C=2/2 R=0/49.45K L=0.353)
17
+ 12214 ttys002 0:07.22 http://localhost:8000 (C=5/6 R=0/112.97K L=0.534)
18
+ 12215 ttys002 0:05.41 http://localhost:8000 (C=3/3 R=0/71.7K L=0.439)
19
+ 12216 ttys002 0:06.46 http://localhost:8000 (C=4/5 R=0/93.22K L=0.493)
20
+ 12217 ttys002 0:02.58 http://localhost:8000 (C=1/1 R=0/24.9K L=0.251)
21
+ 12218 ttys002 0:05.44 http://localhost:8000 (C=3/3 R=0/72.12K L=0.439)
22
+ 12219 ttys002 0:06.47 http://localhost:8000 (C=4/4 R=0/93.13K L=0.493)
23
+ 12220 ttys002 0:04.03 http://localhost:8000 (C=2/2 R=0/47.37K L=0.357)
24
+ 12221 ttys002 0:06.41 http://localhost:8000 (C=4/4 R=0/92.46K L=0.494)
25
+ 12222 ttys002 0:06.38 http://localhost:8000 (C=4/4 R=0/91.71K L=0.495)
26
+
27
+ - **C** – Connections: `(current/total)` connections accepted by the server
28
+ - **R** – Requests: `(current/total)` requests processed by the server
29
+ - **L** – Scheduler Load: A floating-point value representing the event loop load
30
+
3
31
  ## v0.48.4
4
32
 
5
33
  - Improve compatibility of rackup handler w.r.t. sinatra.
@@ -7,3 +35,40 @@
7
35
  ## v0.47.8
8
36
 
9
37
  - Fix Falcon Supervisor implementation: due to invalid code, it was unable to start.
38
+
39
+ # v0.45.0
40
+
41
+ ## Compatibility Fixes
42
+
43
+ During the `v0.44.0` release cycle, the workflows for testing older rack releases were accidentally dropped. As such, `v0.44.0` was not compatible with older versions of rack. This release restores compatibility with older versions of rack.
44
+
45
+ Specifically, `protocol-rack` now provides `Protocol::Rack::Adapter.parse_file` to load Rack applications. Rack 2's `Rack::Builder.parse_file` returns both the application and a set of options (multi-value return). Rack 3 changed this to only return the application, as the prior multi-value return was confusing at best. This change allows `protocol-rack` to work with both versions of rack, and `falcon` adopts that interface.
46
+
47
+ ## Falcon Serve Options
48
+
49
+ In addition, `falcon serve` provides two new options:
50
+
51
+ 1. `--[no]-restart` which controls what happens when `async-container` instances crash. By default, `falcon serve` will restart the container when it crashes. This can be disabled with `--no-restart`.
52
+
53
+ 2. `--graceful-stop [timeout]` which allows you to specify a timeout for graceful shutdown. This is useful when you want to stop the server, but allow existing connections to finish processing before the server stops. This feature is highly experimental and doesn't work correctly in all cases yet, but we are aiming to improve it.
54
+
55
+ # v0.44.0
56
+
57
+ ## Falcon Host
58
+
59
+ `async-service` is a new gem that exposes a generic service interface on top of `async-container`. Previously, `falcon host` used `async-container` directly and `build-environment` for configuration. In order to allow for more generic service definitions and configuration, `async-service` now provides a similar interface to `build-environment` and exposes this in a way that can be used for services other tha falcon. This makes it simpler to integrate multiple services into a single application.
60
+
61
+ The current configuration format uses definitions like this:
62
+
63
+ ``` ruby
64
+ rack 'hello.localhost', :self_signed_tls
65
+ ```
66
+
67
+ This changes to:
68
+
69
+ ``` ruby
70
+ service 'hello.localhost' do
71
+ include Falcon::Environment::Rack
72
+ include Falcon::Environment::SelfSignedTLS
73
+ end
74
+ ```
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: falcon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.48.6
4
+ version: 0.49.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -60,7 +60,7 @@ cert_chain:
60
60
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
61
61
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
62
62
  -----END CERTIFICATE-----
63
- date: 2025-01-29 00:00:00.000000000 Z
63
+ date: 2025-02-08 00:00:00.000000000 Z
64
64
  dependencies:
65
65
  - !ruby/object:Gem::Dependency
66
66
  name: async
@@ -82,14 +82,14 @@ dependencies:
82
82
  requirements:
83
83
  - - "~>"
84
84
  - !ruby/object:Gem::Version
85
- version: '0.18'
85
+ version: '0.20'
86
86
  type: :runtime
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  requirements:
90
90
  - - "~>"
91
91
  - !ruby/object:Gem::Version
92
- version: '0.18'
92
+ version: '0.20'
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: async-http
95
95
  requirement: !ruby/object:Gem::Requirement
@@ -239,7 +239,6 @@ files:
239
239
  - bake/falcon/supervisor.rb
240
240
  - bin/falcon
241
241
  - bin/falcon-host
242
- - changes.md
243
242
  - lib/falcon.rb
244
243
  - lib/falcon/command.rb
245
244
  - lib/falcon/command/host.rb
metadata.gz.sig CHANGED
Binary file
data/changes.md DELETED
@@ -1,38 +0,0 @@
1
- # Changes
2
-
3
- # v0.45.0
4
-
5
- ## Compatibility Fixes
6
-
7
- During the `v0.44.0` release cycle, the workflows for testing older rack releases were accidentally dropped. As such, `v0.44.0` was not compatible with older versions of rack. This release restores compatibility with older versions of rack.
8
-
9
- Specifically, `protocol-rack` now provides `Protocol::Rack::Adapter.parse_file` to load Rack applications. Rack 2's `Rack::Builder.parse_file` returns both the application and a set of options (multi-value return). Rack 3 changed this to only return the application, as the prior multi-value return was confusing at best. This change allows `protocol-rack` to work with both versions of rack, and `falcon` adopts that interface.
10
-
11
- ## Falcon Serve Options
12
-
13
- In addition, `falcon serve` provides two new options:
14
-
15
- 1. `--[no]-restart` which controls what happens when `async-container` instances crash. By default, `falcon serve` will restart the container when it crashes. This can be disabled with `--no-restart`.
16
-
17
- 2. `--graceful-stop [timeout]` which allows you to specify a timeout for graceful shutdown. This is useful when you want to stop the server, but allow existing connections to finish processing before the server stops. This feature is highly experimental and doesn't work correctly in all cases yet, but we are aiming to improve it.
18
-
19
- # v0.44.0
20
-
21
- ## Falcon Host
22
-
23
- `async-service` is a new gem that exposes a generic service interface on top of `async-container`. Previously, `falcon host` used `async-container` directly and `build-environment` for configuration. In order to allow for more generic service definitions and configuration, `async-service` now provides a similar interface to `build-environment` and exposes this in a way that can be used for services other tha falcon. This makes it simpler to integrate multiple services into a single application.
24
-
25
- The current configuration format uses definitions like this:
26
-
27
- ```ruby
28
- rack 'hello.localhost', :self_signed_tls
29
- ```
30
-
31
- This changes to:
32
-
33
- ```ruby
34
- service 'hello.localhost' do
35
- include Falcon::Environment::Rack
36
- include Falcon::Environment::SelfSignedTLS
37
- end
38
- ```