File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ source "https://rubygems.org"
4+
5+ gem "async-service" , path : "../../"
6+ gem "async-container-supervisor"
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env async-service
2+ # frozen_string_literal: true
3+
4+ # Released under the MIT License.
5+ # Copyright, 2024-2025, by Samuel Williams.
6+
7+ require "async/container/supervisor"
8+ require "async/service/managed_service"
9+ require "async/service/managed_environment"
10+
11+ class MemoryUsageService < Async ::Service ::ManagedService
12+ def run ( instance , evaluator )
13+ things = [ ]
14+
15+ Async do
16+ while true
17+ sleep ( rand )
18+ things << " " * 1024 * 1024 * 10
19+ Console . info ( self , "Allocated #{ things . last . bytesize } bytes..." )
20+ end
21+ ensure
22+ Fiber . blocking do
23+ Console . info ( self , "Blocking for cleanup..." )
24+ sleep
25+ ensure
26+ Console . info ( self , "Cleanup complete." )
27+ end
28+ end
29+ end
30+ end
31+
32+ service "memory-usage" do
33+ include Async ::Service ::ManagedEnvironment
34+
35+ service_class MemoryUsageService
36+
37+ count 40
38+
39+ health_check_timeout 10
40+
41+ include Async ::Container ::Supervisor ::Supervised
42+ end
43+
44+ service "supervisor" do
45+ include Async ::Container ::Supervisor ::Environment
46+
47+ monitors do
48+ [
49+ Async ::Container ::Supervisor ::MemoryMonitor . new (
50+ # The interval at which to check for memory leaks.
51+ interval : 10 ,
52+ maximum_size_limit : 1024 * 1024 * 30 ,
53+ increase_limit : nil ,
54+ )
55+ ]
56+ end
57+ end
You can’t perform that action at this time.
0 commit comments