Skip to content

Commit

Permalink
Better formatting of process title.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Feb 7, 2025
1 parent 743aad4 commit a5fd24f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/falcon/command/serve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def endpoint_options
@options.slice(:hostname, :port, :timeout)
end

def name
@options[:hostname] || @options[:bind]
end

def environment
Async::Service::Environment.new(Falcon::Environment::Server).with(
Falcon::Environment::Rackup,
Expand All @@ -73,7 +77,7 @@ def environment
preload: [@options[:preload]].compact,
url: @options[:bind],

name: "server",
name: self.name,

endpoint: ->{Endpoint.parse(url, **endpoint_options)}
)
Expand Down
36 changes: 36 additions & 0 deletions lib/falcon/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,41 @@ def self.middleware(rack_app, verbose: false, cache: true)
run rack_app
end
end

def initialize(...)
super

@accept_count = 0
@connection_count = 0

@request_count = 0
@active_count = 0
end

attr :request_count
attr :accept_count
attr :connect_count

def accept(...)
@accept_count += 1
@connection_count += 1

super
ensure
@connection_count -= 1
end

def call(...)
@request_count += 1
@active_count += 1

super
ensure
@active_count -= 1
end

def to_s
"connections: #{@connection_count}/#{@accept_count}, requests: #{@active_count}/#{@request_count}"
end
end
end
3 changes: 2 additions & 1 deletion lib/falcon/service/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def setup(container)
if health_check_timeout
Async(transient: true) do
while true
instance.name = "#{server} load=#{Fiber.scheduler.load}"
# We only update this if the health check is enabled. Maybe we should always update it?
instance.name = "#{self.name} (#{server.to_s}, load: #{Fiber.scheduler.load.round(3)})"
sleep(health_check_timeout / 2)
instance.ready!
end
Expand Down

0 comments on commit a5fd24f

Please sign in to comment.