-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
93 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
def leak(size: 1024*1024) | ||
require "async/http/internet/instance" | ||
|
||
Sync do | ||
response = Async::HTTP::Internet.get("http://localhost:8080/?leak=#{size}") | ||
ensure | ||
response&.finish | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env falcon --verbose serve -c | ||
# frozen_string_literal: true | ||
|
||
leaks = [] | ||
|
||
run do |env| | ||
request = Rack::Request.new(env) | ||
|
||
if size = request.params["leak"] | ||
Console.debug(self) {"Leaking #{size} bytes..."} | ||
leaks << " " * size.to_i | ||
end | ||
|
||
[200, {}, ["Hello World"]] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env falcon-host | ||
# frozen_string_literal: true | ||
|
||
# Released under the MIT License. | ||
# Copyright, 2019-2024, by Samuel Williams. | ||
|
||
require "falcon/environment/self_signed_tls" | ||
require "falcon/environment/rack" | ||
require "falcon/environment/supervisor" | ||
|
||
class MemoryMonitor < Async::Container::Supervisor::MemoryMonitor | ||
def memory_leak_detected(process_id, monitor) | ||
connections = @processes[process_id] | ||
|
||
# Note that if you use a multi-threaded or hybrid container, there will be multiple connections per process. We break after the first successful dump. | ||
connections.each do |connection| | ||
response = connection.call(do: :memory_dump, path: "memory-#{process_id}.json", timeout: 30) | ||
Console.info(self, "Memory dumped...", response: response) | ||
|
||
break | ||
end | ||
|
||
super | ||
end | ||
end | ||
|
||
service "hello.localhost" do | ||
include Falcon::Environment::SelfSignedTLS | ||
include Falcon::Environment::Rack | ||
|
||
scheme "http" | ||
protocol {Async::HTTP::Protocol::HTTP} | ||
|
||
endpoint do | ||
Async::HTTP::Endpoint.for(scheme, "localhost", port: 9292, protocol: protocol) | ||
end | ||
|
||
count 4 | ||
|
||
url "http://localhost:8080" | ||
|
||
endpoint do | ||
::Async::HTTP::Endpoint.parse(url).with(**endpoint_options) | ||
end | ||
|
||
include Async::Container::Supervisor::Supervised | ||
end | ||
|
||
service "supervisor" do | ||
include Falcon::Environment::Supervisor | ||
|
||
monitors do | ||
[ | ||
MemoryMonitor.new(interval: 10, | ||
# Per-supervisor (cluster) limit: | ||
total_size_limit: 80*1024*1024, | ||
# Per-process limit: | ||
maximum_size_limit: 20*1024*1024 | ||
) | ||
] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
# Released under the MIT License. | ||
# Copyright, 2020-2024, by Samuel Williams. | ||
|
||
# $stderr.puts "Preloading..." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters