Class: Omnizip::Models::ParallelOptions
- Inherits:
-
Object
- Object
- Omnizip::Models::ParallelOptions
- Defined in:
- lib/omnizip/models/parallel_options.rb
Overview
Model for parallel processing configuration
Stores settings for parallel compression and extraction operations including thread count, queue size, and load balancing strategy.
Instance Attribute Summary collapse
-
#batch_size ⇒ Integer
Batch size for work queue polling.
-
#chunk_size ⇒ Integer
Chunk size for chunked operations in bytes.
-
#queue_size ⇒ Integer
Maximum size of job queue (default: 1000).
-
#strategy ⇒ Symbol
Load balancing strategy (:dynamic or :static).
-
#threads ⇒ Integer
Number of worker threads (default: auto-detect).
-
#verbose ⇒ Boolean
Enable verbose progress output.
Instance Method Summary collapse
-
#apply(attributes) ⇒ self
Apply a hash of attributes to this options object.
-
#dup ⇒ ParallelOptions
Create a copy of options.
-
#initialize ⇒ ParallelOptions
constructor
Initialize parallel options with default values.
-
#to_h ⇒ Hash
Convert to hash.
-
#validate! ⇒ Boolean
Validate options.
Constructor Details
#initialize ⇒ ParallelOptions
Initialize parallel options with default values
38 39 40 41 42 43 44 45 |
# File 'lib/omnizip/models/parallel_options.rb', line 38 def initialize @threads = detect_cpu_count @queue_size = 1000 @chunk_size = 64 * 1024 * 1024 # 64MB default @strategy = :dynamic @verbose = false @batch_size = 10 end |
Instance Attribute Details
#batch_size ⇒ Integer
Returns Batch size for work queue polling.
35 36 37 |
# File 'lib/omnizip/models/parallel_options.rb', line 35 def batch_size @batch_size end |
#chunk_size ⇒ Integer
Returns Chunk size for chunked operations in bytes.
26 27 28 |
# File 'lib/omnizip/models/parallel_options.rb', line 26 def chunk_size @chunk_size end |
#queue_size ⇒ Integer
Returns Maximum size of job queue (default: 1000).
23 24 25 |
# File 'lib/omnizip/models/parallel_options.rb', line 23 def queue_size @queue_size end |
#strategy ⇒ Symbol
Returns Load balancing strategy (:dynamic or :static).
29 30 31 |
# File 'lib/omnizip/models/parallel_options.rb', line 29 def strategy @strategy end |
#threads ⇒ Integer
Returns Number of worker threads (default: auto-detect).
20 21 22 |
# File 'lib/omnizip/models/parallel_options.rb', line 20 def threads @threads end |
#verbose ⇒ Boolean
Returns Enable verbose progress output.
32 33 34 |
# File 'lib/omnizip/models/parallel_options.rb', line 32 def verbose @verbose end |
Instance Method Details
#apply(attributes) ⇒ self
Apply a hash of attributes to this options object. Only keys
that correspond to known writers (+threads=+, queue_size=,
etc.) are applied; unknown keys are silently ignored.
69 70 71 72 73 74 75 76 |
# File 'lib/omnizip/models/parallel_options.rb', line 69 def apply(attributes) SETTERS.each do |key, setter| next unless attributes.key?(key) public_send(setter, attributes[key]) end self end |
#dup ⇒ ParallelOptions
Create a copy of options
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/omnizip/models/parallel_options.rb', line 91 def dup copy = self.class.new copy.threads = threads copy.queue_size = queue_size copy.chunk_size = chunk_size copy.strategy = strategy copy.verbose = verbose copy.batch_size = batch_size copy end |
#to_h ⇒ Hash
Convert to hash
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/omnizip/models/parallel_options.rb', line 105 def to_h { threads: threads, queue_size: queue_size, chunk_size: chunk_size, strategy: strategy, verbose: verbose, batch_size: batch_size, } end |
#validate! ⇒ Boolean
Validate options
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/omnizip/models/parallel_options.rb', line 51 def validate! raise ArgumentError, "threads must be > 0" if threads <= 0 raise ArgumentError, "queue_size must be > 0" if queue_size <= 0 raise ArgumentError, "chunk_size must be > 0" if chunk_size <= 0 raise ArgumentError, "strategy must be :dynamic or :static" unless %i[ dynamic static ].include?(strategy) raise ArgumentError, "batch_size must be > 0" if batch_size <= 0 true end |