Workers and parallelism
Pages 78
Basic stuff
- Home
- Introduction
- Getting started
- Different bus modes
- How does rebus compare to other .net service buses?
- 3rd party extensions
- Rebus versions
Configuration
Scenarios
Areas
- Logging
- Routing
- Serialization
- Pub sub messaging
- Process managers
- Message context
- Data bus
- Correlation ids
- Container adapters
- Automatic retries and error handling
- Message dispatch
- Thread safety and instance policies
- Timeouts
- Timeout manager
- Transactions
- Delivery guarantees
- Idempotence
- Unit of work
- Workers and parallelism
- Wire level format of messages
- Handler pipeline
- Polymorphic message dispatch
- Persistence ignorance
- Saga parallelism
- Transport message forwarding
- Testing
- Outbox
- Startup/shutdown
Transports (not a full list)
Customization
- Extensibility
- Auto flowing user context extensibility example
- Back off strategy
- Message compression and encryption
- Fail fast on certain exception types
Pipelines
- Log message pipelines
- Incoming messages pipeline
- Incoming step context
- Outgoing messages pipeline
- Outgoing step context
Prominent application services
Clone this wiki locally
Since everything in Rebus is async
, one single worker can perform a ridiculous amount of work in parallel if that work can be await
ed.
Therefore – to avoid doing too much work – the "max parallelism" concept is present, which puts a global max cap on how many messages to process in parallel.
You can configure those options by going
Configure.With(...)
.(...)
.Options(o => {
o.SetNumberOfWorkers(1);
o.SetMaxParallelism(10);
})
.(...)
Which values to use for the settings depends on the type of work you want to perform. The following are some reasonable settings that maybe can give you some food for thought:
- Work is predominantly asynchronous – use a few worker threads and fairly high parallelism, e.g.
o.SetNumberOfWorkers(2); o.SetMaxParallelism(20);
- Work is fast and synchronous – use a few worker threads and a matching parallelism, e.g.
o.SetNumberOfWorkers(5); o.SetMaxParallelism(5);
(although setting the parallelism higher will not affect anything in this case) - Work is slow and synchronous – use more worker threads and a matching parallelism, e.g.
o.SetNumberOfWorkers(15); o.SetMaxParallelism(15);
(again: setting the parallelism higher will not affect anything in this case) - Work must be performed in a synchronous manner, effectively serializing access to some particular resource (or to make an endpoint easier to debug during development) – use one single worker thread and a matching parallelism:
o.SetNumberOfWorkers(1); o.SetMaxParallelism(1);
Since the parallelism setting puts an absolute upper cap on how many messages can be handled in parallel, it does not make sense to set the parallelism lower than the number of threads. It does not create any problems on the other hand though, it is just a waste of resources.
Defaults
Rebus will default to 1 worker thread and a max parallelism of 5.
Worker threads
Rebus will actually spawn the number of worker threads as dedicated threads. The threads will be used for polling the transport for messages.
Depending on whether the transport is asynchronous or not, the continuation after having received a message will either execute on the worker thread or on the thread pool.
We do our best to ensure that the documentation wiki is up-to-date - please let us know if you think there's something we should do better.