github.com/anaPerezGhiglia/worker_pool
main / published Jun 17, 2025 / repository
Minimalistic worker pool implementation to split workload between concurrent workers in a bounded manner
worker_pool
Minimalistic worker pool implementation
WorkerPool allows to split workload between concurrent workers in a bounded manner (it spawns a new fiber for each worker created)
Installation
-
Add the dependency to your
shard.yml:dependencies: worker_pool: github: anaperezghiglia/worker_pool -
Run
shards install
Usage
Keep in mind that the pool is internally implemented with a BufferedChannel. This means that if the channel is full then the calling fiber will block until there is space for the new workload. The size of the buffer and the number of active workers is configurable so it can fit different needs.
buffer_capacitydefines the capacity of the inner Channel.pool_sizecontrols the # of workers (thus fibers) to initialize & have ready to process workload
instantiate a new worker_pool
require "worker_pool"
worker_pool = WorkerPool::Pool(String).new buffer_capacity: 10, pool_size: 3 { |channel, id|
Mailman.new(channel, id)
}
process workload
worker_pool.process("This is an example")
Explore examples directory for more detailed examples
Development
TODO: Write development instructions here
Contributing
- Fork it (https://github.com/your-github-user/worker_pool/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Ana Perez Ghiglia - creator and maintainer