Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/09_strategy_per_stage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def cleanup
accumulator :batch, max_size: 3, to: %i[heavy_save light_log]

# Heavy consumer spawns forks per batch (COW fork pattern)
process_per_batch(max: 2) do
cow_fork(2) do
consumer :heavy_save do |batch|
puts "[HeavySave:process_per_batch:#{Process.pid}] Processing batch of #{batch.size}"
sleep 0.01 # Simulate heavy work
Expand All @@ -56,7 +56,7 @@ def cleanup
end

# Light consumer uses threads (stream mode, no batching needed)
threads(5) do
thread_pool(5) do
consumer :light_log do |batch|
puts "[LightLog:threads] Logging batch of #{batch.size}"
batch.each { |num| @mutex.synchronize { thread_results << num } }
Expand Down
2 changes: 1 addition & 1 deletion examples/10_routing_to_nested_stages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def cleanup
end

# Nested pipeline with forked execution
process_per_batch(max: 2) do
cow_fork(2) do
consumer :save do |batch|
puts "[Consumer:save] (PID #{Process.pid}) Received batch: #{batch.inspect}"

Expand Down
2 changes: 1 addition & 1 deletion examples/10_web_crawler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def save_page_data(page)
end

# Stage 2: Fetch pages (with deduplication)
threads(20) do
thread_pool(20) do
processor :fetch_pages do |page_info, output|
url = page_info[:url]
depth = page_info[:depth]
Expand Down
2 changes: 1 addition & 1 deletion examples/17_database_connection_hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def log_event(event)
accumulator :batch, max_size: 5

# Use process_per_batch to process batches
process_per_batch(max: 2) do
cow_fork(2) do
consumer :process_users do |batch|
batch.each do |user_id|
@connection_events << "Processing user #{user_id} in PID #{Process.pid}"
Expand Down
2 changes: 1 addition & 1 deletion examples/18_resource_cleanup_hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def cleanup
# Accumulator batches records
accumulator :batch, max_size: 5

process_per_batch(max: 2) do
cow_fork(2) do
# Close connections before forking
before_fork :save_to_db do
@resource_events << 'Closing connections before fork'
Expand Down
2 changes: 1 addition & 1 deletion examples/19_statistics_gathering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def cleanup
@stats[:consumer_duration] = @stats[:consumer_end] - @stats[:consumer_start]
end

process_per_batch(max: 2) do
cow_fork(2) do
before_fork :save_results do
@stats[:forks_created] += 1
end
Expand Down
2 changes: 1 addition & 1 deletion examples/20_error_handling_hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def cleanup
@process_errors = []
end

process_per_batch(max: 2) do
cow_fork(2) do
after_fork :save_results do
# Report errors from this child process
puts "Child process #{Process.pid} had #{@process_errors.size} errors" if @process_errors&.any?
Expand Down
2 changes: 1 addition & 1 deletion examples/21_inline_hook_procs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def cleanup
accumulator :batch, max_size: 5

# Inline fork hooks for consumers
process_per_batch(max: 2) do
cow_fork(2) do
consumer :save_data,
before: -> { @timer[:save_start] = Time.now },
after: -> { @timer[:save_end] = Time.now },
Expand Down
2 changes: 1 addition & 1 deletion examples/23_runner_features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def initialize
# Use accumulator + process_per_batch to see process title in action
accumulator :batch, max_size: 5

process_per_batch(max: 2) do
cow_fork(2) do
consumer :process do |batch|
# On Unix systems, run 'ps aux | grep minigun' while this is running
# You'll see: "minigun-default-consumer-12345"
Expand Down
2 changes: 1 addition & 1 deletion examples/27_error_handling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize
5.times { |i| output << i }
end

threads(2) do
thread_pool(2) do
processor :process do |item, output|
raise StandardError, "Error on item #{item}" if item == 2

Expand Down
10 changes: 5 additions & 5 deletions examples/27_execution_contexts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def initialize
end

# Use thread pool for concurrent processing
threads(5) do
thread_pool(5) do
processor :process do |item, output|
sleep 0.01 # Simulate work
output << (item * 2)
Expand Down Expand Up @@ -146,7 +146,7 @@ def initialize

# Process isolation for CPU-bound tasks
batch 1
process_per_batch(max: 2) do
cow_fork(2) do
processor :process do |batch, output|
batch.each do |item|
output << { item: item, pid: Process.pid, result: item * 100 }
Expand Down Expand Up @@ -190,7 +190,7 @@ def initialize
10.times { |i| output << i }
end

threads(5) do
thread_pool(5) do
processor :process do |item, output|
sleep 0.01 # Simulate work
output << (item * 3)
Expand Down Expand Up @@ -233,7 +233,7 @@ def initialize
5.times { |i| output << i }
end

threads(2) do
thread_pool(2) do
processor :process do |item, output|
raise StandardError, "Error on item #{item}" if item == 2

Expand Down Expand Up @@ -273,7 +273,7 @@ def initialize
10.times { |i| output << i }
end

threads(3) do
thread_pool(3) do
processor :process do |item, output|
output << item
end
Expand Down
2 changes: 1 addition & 1 deletion examples/27_parallel_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize
10.times { |i| output << i }
end

threads(5) do
thread_pool(5) do
processor :process do |item, output|
sleep 0.01 # Simulate work
output << (item * 3)
Expand Down
2 changes: 1 addition & 1 deletion examples/27_process_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def initialize

# Process isolation for CPU-bound tasks
batch 1
process_per_batch(max: 2) do
cow_fork(2) do
processor :process do |batch, output|
batch.each do |item|
output << { item: item, pid: Process.pid, result: item * 100 }
Expand Down
2 changes: 1 addition & 1 deletion examples/27_termination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize
10.times { |i| output << i }
end

threads(3) do
thread_pool(3) do
processor :process do |item, output|
output << item
end
Expand Down
2 changes: 1 addition & 1 deletion examples/27_thread_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize
end

# Use thread pool for concurrent processing
threads(5) do
thread_pool(5) do
processor :process do |item, output|
sleep 0.01 # Simulate work
output << (item * 2)
Expand Down
2 changes: 1 addition & 1 deletion examples/28_basic_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize
end

# Thread pool with 3 workers
threads(3) do
thread_pool(3) do
processor :process do |item, output|
sleep 0.05
output << (item * 2)
Expand Down
2 changes: 1 addition & 1 deletion examples/28_bulk_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize
100.times { |i| output << i }
end

threads(20) do
thread_pool(20) do
processor :process do |item, output|
output << (item**2)
end
Expand Down
2 changes: 1 addition & 1 deletion examples/28_capacity_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize
end

# Limited to 2 concurrent workers
threads(2) do
thread_pool(2) do
processor :process do |item, output|
sleep 0.01
output << item
Expand Down
12 changes: 6 additions & 6 deletions examples/28_context_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def initialize
end

# Thread pool with 3 workers
threads(3) do
thread_pool(3) do
processor :process do |item, output|
sleep 0.05
output << (item * 2)
Expand Down Expand Up @@ -69,7 +69,7 @@ def initialize
end

# Limited to 2 concurrent workers
threads(2) do
thread_pool(2) do
processor :process do |item, output|
sleep 0.01
output << item
Expand Down Expand Up @@ -110,7 +110,7 @@ def initialize
50.times { |i| output << i }
end

threads(10) do
thread_pool(10) do
processor :process do |item, output|
output << (item * 2)
end
Expand Down Expand Up @@ -147,7 +147,7 @@ def initialize
20.times { |i| output << i }
end

threads(3) do
thread_pool(3) do
processor :track do |item, output|
@mutex.synchronize { @thread_ids << Thread.current.object_id }
output << item
Expand Down Expand Up @@ -186,7 +186,7 @@ def initialize
100.times { |i| output << i }
end

threads(20) do
thread_pool(20) do
processor :process do |item, output|
output << (item**2)
end
Expand Down Expand Up @@ -227,7 +227,7 @@ def initialize
5.times { |i| output << i }
end

threads(5) do
thread_pool(5) do
processor :process do |item, output|
sleep 0.01 # Simulate work
output << item
Expand Down
2 changes: 1 addition & 1 deletion examples/28_parallel_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize
50.times { |i| output << i }
end

threads(10) do
thread_pool(10) do
processor :process do |item, output|
output << (item * 2)
end
Expand Down
2 changes: 1 addition & 1 deletion examples/28_reuse_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize
20.times { |i| output << i }
end

threads(3) do
thread_pool(3) do
processor :track do |item, output|
@mutex.synchronize { @thread_ids << Thread.current.object_id }
output << item
Expand Down
2 changes: 1 addition & 1 deletion examples/28_termination_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize
5.times { |i| output << i }
end

threads(5) do
thread_pool(5) do
processor :process do |item, output|
sleep 0.01 # Simulate work
output << item
Expand Down
4 changes: 2 additions & 2 deletions examples/31_adaptive_pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ def batch_size
1000.times { |i| output << i }
end

threads(thread_count) do
thread_pool(thread_count) do
processor :fetch do |item, output|
output << { id: item, data: 'fetched' }
end
end

batch batch_size

process_per_batch(max: process_count) do
cow_fork(process_count) do
processor :process do |batch, _output|
batch.map { |x| x[:data].upcase }
end
Expand Down
2 changes: 1 addition & 1 deletion examples/31_configurable_downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def initialize(threads: 10, batch_size: 100)
end

# Use instance variable for thread count
threads(@thread_count) do
thread_pool(@thread_count) do
processor :download do |url, output|
# Simulate download
sleep 0.01
Expand Down
Loading
Loading