在Scala 2.10中为所有集合设置并行度级别吗? [英] Set the parallelism level for all collections in Scala 2.10?

查看:283
本文介绍了在Scala 2.10中为所有集合设置并行度级别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解如何通过可变的tasksupport字段为单个并行集合设置并行度(请参阅 https://stackoverflow.com/a/5425354/82970 ).

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/82970).

如何在Scala 2.10中为所有新的并行集合设置并行度级别?

How can I set the parallelism level for all new parallel collections in Scala 2.10?

一个辅助问题--- tasksupport是否与由并行数据集构建的新并行数据集继承"的并行数据集相关? (例如,使用takemap等)

A subsidiary question --- is the tasksupport associated to a parallel collection 'inherited' by new parallel collections built out of it? (e.g. with take, map, etc.)

推荐答案

  1. 我简要地看了看源代码,如果我对它们的理解正确,那么可以使用三个系统属性来配置默认执行上下文,这似乎可以用作默认任务支持.这些决定了任务支持对象的并行度.

  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:整数,最小并行度
  • scala.concurrent.context.numThreads:一个Int,以指定要直接使用的并行度,或者一个String:一个"x",后跟一个Double(例如,"x1.5"),然后与Runtime.getRuntime.availableProcessors
  • scala.concurrent.context.maxThreads:整数,最大并行度
  • 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.

关于您问题的第二部分:
诸如mapfilter等的转换操作应保留在原始集合上设置的任务支持.至少消息来源是这样的. :)
大多数并行操作在
ParIterableLike中定义,他们要么在resultWithTaskSupport > Combiner (通过工厂在ParIterableLike的568行或581行中获取原始任务支持集),或直接在结果集合上设置任务支持.

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.

这篇关于在Scala 2.10中为所有集合设置并行度级别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆