Class: Takagi::Controller::ResourceAllocator
- Inherits:
-
Object
- Object
- Takagi::Controller::ResourceAllocator
- Defined in:
- lib/takagi/controller/resource_allocator.rb
Overview
Allocates thread pool resources to controllers
Supports two modes:
-
Manual: Controllers specify exact thread counts via profiles
-
Automatic: Divides global pool among controllers based on weights
Constant Summary collapse
- PROFILE_WEIGHTS =
Profile weights for automatic allocation Higher weight = more resources
{ minimal: 1, low_traffic: 2, long_lived: 8, high_throughput: 16, large_payloads: 4, custom: 4 }.freeze
Class Method Summary collapse
-
.allocate(controllers:, mode: :automatic, total_threads: nil, protocol: :tcp) ⇒ Hash
Allocate thread pool resources to controllers.
-
.validate!(allocations, total_threads:) ⇒ Object
Validate that allocations don’t exceed available resources.
Class Method Details
.allocate(controllers:, mode: :automatic, total_threads: nil, protocol: :tcp) ⇒ Hash
Allocate thread pool resources to controllers
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/takagi/controller/resource_allocator.rb', line 57 def allocate(controllers:, mode: :automatic, total_threads: nil, protocol: :tcp) case mode when :manual allocate_manual(controllers, protocol: protocol) when :automatic allocate_automatic(controllers, total_threads: total_threads, protocol: protocol) else raise ArgumentError, "Unknown allocation mode: #{mode}. Use :manual or :automatic" end end |
.validate!(allocations, total_threads:) ⇒ Object
Validate that allocations don’t exceed available resources
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/takagi/controller/resource_allocator.rb', line 73 def validate!(allocations, total_threads:) allocated = allocations.values.sum { |alloc| alloc[:threads] || 0 } if allocated > total_threads raise ArgumentError, "Controller thread allocations (#{allocated}) exceed available threads (#{total_threads})" end allocations end |