Skip to content

Commit 3da44c8

Browse files
committed
Better formatting of process title.
1 parent 743aad4 commit 3da44c8

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

lib/falcon/command/serve.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ def endpoint_options
5757
@options.slice(:hostname, :port, :timeout)
5858
end
5959

60+
def name
61+
@options[:hostname] || @options[:bind]
62+
end
63+
6064
def environment
6165
Async::Service::Environment.new(Falcon::Environment::Server).with(
6266
Falcon::Environment::Rackup,
@@ -73,7 +77,7 @@ def environment
7377
preload: [@options[:preload]].compact,
7478
url: @options[:bind],
7579

76-
name: "server",
80+
name: self.name,
7781

7882
endpoint: ->{Endpoint.parse(url, **endpoint_options)}
7983
)

lib/falcon/server.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,53 @@ def self.middleware(rack_app, verbose: false, cache: true)
3535
run rack_app
3636
end
3737
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
3886
end
3987
end

lib/falcon/service/server.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def setup(container)
6767
if health_check_timeout
6868
Async(transient: true) do
6969
while true
70-
instance.name = "#{server} load=#{Fiber.scheduler.load}"
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)})"
7172
sleep(health_check_timeout / 2)
7273
instance.ready!
7374
end

0 commit comments

Comments
 (0)