Maintaining Background Processes Overview
Each new background processes require the creation of two new classes: a
BatchJob and a ThreadWorker. These classes fit
into the master-worker pattern used by the background process runtime
infrastructure to overcome the throughput limitations encountered by single-threaded
processes. By splitting work among many concurrent threads, often on multiple physical
nodes, background processes can achieve excellent scalability and react to changing work
demands without additional programming. In this pattern:
- A
BatchJobis responsible for determining the work to be processed for a batch run and then splitting that work into pieces that eachThreadWorkerwill process. When running a single process, a singleBatchJobobject is instantiated by the framework. The framework then makes calls to theBatchJobinstance at the appropriate time. One such set of calls to theBatchJobinstance is to return to the framework a collection ofThreadWorkinstances that will be distributed for execution. - A
ThreadWorkeris responsible for processing a singleThreadWorkinstance for a run. Within theThreadWork, there are manyWorkUnitsrepresenting the fine-grained units of work to be processed. In many cases, theseWorkUnitsrepresent a complete database transaction. For example, a bill being created for an account, whether or not theThreadWorkerexecutes on the same computer as otherThreadWorkers, or theBatchJobthat created its work is left as a configuration choice to be made at runtime. Within a single process, there may be manyThreadWorkerobjects. In general, eachThreadWorkerinstantiated in a batch run has a corresponding row in the Batch Instance table. The Batch Instance rows provide persistent state that is needed for theThreadWorkersto operate correctly in failure/restart situations.
