| 1 | | | /// Concurrency settings governing parallelization of workers in a [WorkerPool]. |
| 2 | | | class ConcurrencySettings { |
| 3 | | 12 | const ConcurrencySettings( |
| 4 | | | {this.minWorkers = 0, this.maxWorkers = 0, this.maxParallel = 1}) |
| 5 | | 24 | : assert(minWorkers >= 0, 'minWorkers must be >= 0'), |
| 6 | | 24 | assert(maxWorkers >= 0, 'maxWorkers must be >= 0'), |
| 7 | | 24 | assert(minWorkers <= maxWorkers, 'maxWorkers must be >= minWorkers'), |
| 8 | | 24 | assert(maxParallel >= 1, 'maxParallel must be >= 1'); |
| 9 | | | |
| 10 | | | /// Minimum number of workers in the pool. |
| 11 | | | final int minWorkers; |
| 12 | | | |
| 13 | | | /// Maximum number of workers in the pool. If this is set to 0, the number of |
| 14 | | | /// workers is unbounded (as a result, any task posted to the pool will be |
| 15 | | | /// assigned a worker asap). |
| 16 | | | final int maxWorkers; |
| 17 | | | |
| 18 | | | /// Maximum number of tasks that can be posted to a worker. Tasks in excess |
| 19 | | | /// will be queued and processed later. Please note that this value does not |
| 20 | | | /// reflect real parallelism; eg. when a synchronous workload is picked up by |
| 21 | | | /// a worker, it will run to completion (either success or failure) before any |
| 22 | | | /// other task can be scheduled. |
| 23 | | | final int maxParallel; |
| 24 | | | |
| 25 | | | /// Maximum number of running tasks. |
| 26 | | 12 | int get maxConcurrency => maxWorkers * maxParallel; |
| 27 | | | |
| 28 | | | /// 50 tasks per worker with at most 1 worker. |
| 29 | | | static const oneIoThread = |
| 30 | | | ConcurrencySettings(minWorkers: 0, maxWorkers: 1, maxParallel: 50); |
| 31 | | | |
| 32 | | | /// 50 tasks per worker with at most 2 workers. |
| 33 | | | static const twoIoThreads = |
| 34 | | | ConcurrencySettings(minWorkers: 0, maxWorkers: 2, maxParallel: 50); |
| 35 | | | |
| 36 | | | /// 50 tasks per worker, 1 to 4 workers. |
| 37 | | | static const fourIoThreads = |
| 38 | | | ConcurrencySettings(minWorkers: 1, maxWorkers: 4, maxParallel: 50); |
| 39 | | | |
| 40 | | | /// 50 tasks per worker, 1 to 8 workers. |
| 41 | | | static const eightIoThreads = |
| 42 | | | ConcurrencySettings(minWorkers: 1, maxWorkers: 8, maxParallel: 50); |
| 43 | | | |
| 44 | | | /// 50 tasks per worker, 1 to 16 workers. |
| 45 | | | static const sixteenIoThreads = |
| 46 | | | ConcurrencySettings(minWorkers: 1, maxWorkers: 16, maxParallel: 50); |
| 47 | | | |
| 48 | | | /// 1 task per worker, 1 worker. |
| 49 | | | static const oneCpuThread = |
| 50 | | | ConcurrencySettings(minWorkers: 1, maxWorkers: 1, maxParallel: 1); |
| 51 | | | |
| 52 | | | /// 1 task per worker, 1 to 3 workers. |
| 53 | | | static const threeCpuThreads = |
| 54 | | | ConcurrencySettings(minWorkers: 1, maxWorkers: 3, maxParallel: 1); |
| 55 | | | |
| 56 | | | /// 1 task per worker, 1 to 7 workers. |
| 57 | | | static const sevenCpuThreads = |
| 58 | | | ConcurrencySettings(minWorkers: 1, maxWorkers: 7, maxParallel: 1); |
| 59 | | | |
| 60 | | | /// 1 task per worker, 1 to 15 workers. |
| 61 | | | static const fifteenCpuThreads = |
| 62 | | | ConcurrencySettings(minWorkers: 1, maxWorkers: 15, maxParallel: 1); |
| 63 | | | } |