LCOV - code coverage report

Current view
top level - /src - concurrency_settings.dart
Test
lcov.info
Date
2022-04-02
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines1515100.0%
Functions00-
Branches00-
Each row represents a line of source code
LineBranchHitsSource code
1/// Concurrency settings governing parallelization of workers in a [WorkerPool].
2class ConcurrencySettings {
34 const ConcurrencySettings(
4 {this.minWorkers = 0, this.maxWorkers = 0, this.maxParallel = 1})
52 : assert(minWorkers >= 0),
62 assert(maxWorkers >= 0),
73 assert(minWorkers <= maxWorkers),
83 assert(maxParallel >= 1);
9
10 /// Minimum number of workers in the pool.
11 final int minWorkers;
12
13 /// Maximum number of workers in the pool.
14 /// If this is set to 0, the number of workers is unbounded (as a result, any task posted to the pool will be assigned a worker asap).
15 final int maxWorkers;
16
17 /// Maximum number of tasks that can be posted to a worker.
18 final int maxParallel;
19
20 /// Maximum number of running tasks.
214 int get maxConcurrency => maxWorkers * maxParallel;
22
23 /// Returns the number of workers necessary to handle [pending] tasks, taking into account [minWorkers] and [maxWorkers].
242 int max(int pending) {
254 if (pending < minWorkers) return minWorkers;
265 if (pending < maxWorkers || maxWorkers == 0) return pending;
272 return maxWorkers;
281 }
29
30 /// Returns the number of workers necessary to have at least [minLive] live workers, taking into account [minWorkers] and [maxWorkers].
312 int min(int minLive) {
324 if (minLive < minWorkers) return minWorkers;
332 return max(minLive);
341 }
35
36 /// 50 tasks per worker with at most 1 worker.
37 static const oneIoThread =
38 ConcurrencySettings(minWorkers: 0, maxWorkers: 1, maxParallel: 50);
39
40 /// 50 tasks per worker with at most 2 workers.
41 static const twoIoThreads =
42 ConcurrencySettings(minWorkers: 0, maxWorkers: 2, maxParallel: 50);
43
44 /// 50 tasks per worker, 1 to 4 workers.
45 static const fourIoThreads =
46 ConcurrencySettings(minWorkers: 1, maxWorkers: 4, maxParallel: 50);
47
48 /// 50 tasks per worker, 1 to 8 workers.
49 static const eightIoThreads =
50 ConcurrencySettings(minWorkers: 1, maxWorkers: 8, maxParallel: 50);
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 tasks per worker, 1 to 7 workers.
57 static const sevenCpuThreads =
58 ConcurrencySettings(minWorkers: 1, maxWorkers: 7, maxParallel: 1);
59}
Choose Features