Set the parallelism level for all collections in Scala 2.10?

后端 未结 1 404
小蘑菇
小蘑菇 2020-12-16 02:02

I understand how to set the parallelism level for a single parallel collection, via the mutable tasksupport field (c.f. https://stackoverflow.com/a/5425354/8297

相关标签:
1条回答
  • 2020-12-16 03:01
    1. I looked at the sources briefly and if I understand things correctly, there are three system properties that can be used to configure the default execution context, which seems to be used as default task support. These determine the parallelism level of the task support object.

      • scala.concurrent.context.minThreads: Int, minimum parallelism level
      • scala.concurrent.context.numThreads: either an Int, to specify the parallelism level to use directly, or a String: an "x" followed by a Double (e.g. "x1.5"), which is then multiplied with Runtime.getRuntime.availableProcessors
      • scala.concurrent.context.maxThreads: Int, maximum parallelism level

      The relevant source file (if I followed everything correctly) seems to be ExecutionContextImpl.

    2. As for the second part of your question:
      Transforming operations like map, filter etc. should preserve the task support that has been set on the originating collection. At least the sources look that way. :)
      Most parallel operations are defined in ParIterableLike and they either call resultWithTaskSupport in Combiner (which gets gets the originating task support set via the factory in lines 568 or 581 in ParIterableLike) or set the task support directly on the resulting collection.

    0 讨论(0)
提交回复
热议问题