The general theme of this release is performance improvement by eliminating thread contention due to unnecessary locking of shared state. This required making some breaking changes to the API.
- Breaking
beekeeper::hive::Hivetype signature has changed- Removed the
W: Workerparameter as it is redundant (can be obtained fromQ::Kind) - Added
T: TaskQueuesto specify theTaskQueuesimplementation
- Removed the
- The
Builderinterface has been re-written to enable maximum flexibility.Builderis now a trait that must be in scope.ChannelBuilderimplements the previous builder functionality.WorkstealingBuilderis identical toChannelBuilder, except that it uses workstealing-based task queues (seeFeaturesbelow).OpenBuilderhas no type parameters and can be specialized to create aHivewith any combination ofQueenandTaskQueues.BeeBuilderandFullBuilderare intermediate types that generally should not be instantiated directly.
beekeeper::bee::Queen::createnow takes&selfrather than&mut self. There is a new type,beekeeper::bee::QueenMut, with acreate(&mut self)method, and needs to be wrapped in abeekeeper::bee::QueenCellto implement theQueentrait. This enables theHiveto create new workers without locking in the case of aQueenthat does not need mutable state.beekeeper::bee::Contextnow takes a generic parameter that must be input type of theWorker.beekeeper::hive::Hive::try_into_husknow has anurgentparameter to indicate whether queued tasks should be abandoned when shutting down the hive (true) or if they should be allowed to finish processing (false).- The type of
attemptandmax_retrieshas been changed tou8. This reduces memory usage and should still allow for the majority of use cases. - The
::ofmethods have been removed from stockWorkers in favor of implementingFrom.
- Features
- Added the
TaskQueuestrait, which enablesHiveto be specialized for different implementations of global (i.e., sending tasks from theHiveto worker threads) and local (i.e., worker thread-specific) queues.ChannelTaskQueuesimplements the existing behavior, using a channel for sending tasks.WorkstealingTaskQueueshas been added to implement the workstealing pattern, based oncrossbeam::dequeue.
- Added the
local-batchfeature, which enables worker threads to queue up batches of tasks locally, which can alleviate contention between threads in the pool, especially when there are many short-lived tasks.- When this feature is enabled, tasks can be optionally weighted (by wrapping each input in
crate::hive::Weighted) to help evenly distribute tasks with variable processing times. - Enabling this feature should be transparent (i.e., not break existing code), and the
Hive's task submission methods support both weighted and unweighted inputs (due to the blanket implementation ofFrom<T> for Weighted<T>); however, there are some cases where it is now necessary to specify the input type where before it could be elided.
- When this feature is enabled, tasks can be optionally weighted (by wrapping each input in
- Added the
Context::submitmethod, which enables tasks to submit new tasks to theHive.
- Added the
- Other
- Switched to using thread-local retry queues for the implementation of the
retryfeature, to reduce thread-contention. - Switched to storing
Outcomes in the hive using a data structure that does not require locking when inserting, which should reduce thread contention when using*_storeoperations. - Switched to using
crossbeam_channelfor the task input channel inChannelTaskQueues. These are multi-produer, multi-consumer channels (mpmc; as opposed tostd::mpsc, which is single-consumer), which means it is no longer necessary for worker threads to aquire a Mutex lock on the channel receiver when getting tasks. - Added the
beekeeper::hive::mockmodule, which has aMockTaskRunnerforapplying a worker in a mock context. This is useful for testing yourWorker. - Updated to
2024edition and Rust version1.85
- Switched to using thread-local retry queues for the implementation of the
- Bugfixes
- Reverted accidental change to default features in Cargo.toml
- Panics during drop of worker threads
- Other
- Added initial performance benchmarks
- Breaking
Builder::build*,Husk::into_hive*now returnHiverather thanResult<Hive, SpawnError>beekeeper::hive::SpawnErrorhas been removedHive::growandHive::use_all_coresnow returnResult<usize, Poisoned>rather thanusizeHive::num_threadshas been renamedHive::max_workers
- Features
Hivenow keeps track of spawn resultsHive::alive_workersreports the number of worker threads that are currently alive (<=max_workers)Hive::has_dead_workersreturnstrueif theHivehas encountered any errors spawing worker threadsHive::revive_workersattempts to re-spawn any dead worker threads
- Bugfixes
- Ordered iterators would enter an infinite loop if there were missing indicies
- Initial release