java.util.concurrent.ForkJoinPool.getSurplusQueuedTaskCount()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(93)

本文整理了Java中java.util.concurrent.ForkJoinPool.getSurplusQueuedTaskCount()方法的一些代码示例,展示了ForkJoinPool.getSurplusQueuedTaskCount()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ForkJoinPool.getSurplusQueuedTaskCount()方法的具体详情如下:
包路径:java.util.concurrent.ForkJoinPool
类名称:ForkJoinPool
方法名:getSurplusQueuedTaskCount

ForkJoinPool.getSurplusQueuedTaskCount介绍

[英]Returns a cheap heuristic guide for task partitioning when programmers, frameworks, tools, or languages have little or no idea about task granularity. In essence by offering this method, we ask users only about tradeoffs in overhead vs expected throughput and its variance, rather than how finely to partition tasks. In a steady state strict (tree-structured) computation, each thread makes available for stealing enough tasks for other threads to remain active. Inductively, if all threads play by the same rules, each thread should make available only a constant number of tasks. The minimum useful constant is just 1. But using a value of 1 would require immediate replenishment upon each steal to maintain enough tasks, which is infeasible. Further, partitionings/granularities of offered tasks should minimize steal rates, which in general means that threads nearer the top of computation tree should generate more than those nearer the bottom. In perfect steady state, each thread is at approximately the same level of computation tree. However, producing extra tasks amortizes the uncertainty of progress and diffusion assumptions. So, users will want to use values larger (but not much larger) than 1 to both smooth over transient shortages and hedge against uneven progress; as traded off against the cost of extra task overhead. We leave the user to pick a threshold value to compare with the results of this call to guide decisions, but recommend values such as 3. When all threads are active, it is on average OK to estimate surplus strictly locally. In steady-state, if one thread is maintaining say 2 surplus tasks, then so are others. So we can just use estimated queue length. However, this strategy alone leads to serious mis-estimates in some non-steady-state conditions (ramp-up, ramp-down, other stalls). We can detect many of these by further considering the number of "idle" threads, that are known to have zero queued tasks, so compensate by a factor of (#idle/#active) threads. Note: The approximation of #busy workers as #active workers is not very good under current signalling scheme, and should be improved.
[中]当程序员、框架、工具或语言对任务粒度知之甚少或一无所知时,返回任务划分的廉价启发式指南。本质上,通过提供这种方法,我们只询问用户开销与预期吞吐量及其变化之间的权衡,而不是任务划分的精细程度。在稳态严格(树结构)计算中,每个线程都可以窃取足够的任务,以使其他线程保持活动状态。归纳地说,如果所有线程都遵循相同的规则,那么每个线程应该只提供固定数量的任务。最小有用常数仅为1。但是使用值1需要在每次偷窃后立即补充,以维持足够的任务,这是不可行的。此外,所提供任务的分区/粒度应将窃取率降至最低,这通常意味着更接近计算树顶部的线程应比更接近底部的线程生成更多。在完全稳定状态下,每个线程都处于大致相同的计算树级别。然而,产生额外任务会分摊进度和扩散假设的不确定性。因此,用户希望使用大于1(但不太大)的值来缓解暂时性短缺和对冲不平衡的进展;与额外任务开销的成本进行权衡。我们让用户选择一个阈值,与此调用的结果进行比较,以指导决策,但建议使用3等值。当所有线程都处于活动状态时,在本地严格估计剩余值通常是可以的。在稳定状态下,如果一个线程正在维护(比如说)两个剩余任务,那么其他线程也是如此。所以我们可以只使用估计的队列长度。然而,在某些非稳态条件下(上升、下降、其他失速),仅此策略就会导致严重的错误估计。我们可以通过进一步考虑“空闲”线程的数量来检测其中的许多线程,已知这些线程没有排队任务,因此通过(#空闲/#活动)线程的系数进行补偿。注:在当前的信令方案下,将“忙碌的工作人员”近似为“活跃的工作人员”不是很好,应该改进。

代码示例

代码示例来源:origin: robovm/robovm

/**
 * Returns an estimate of how many more locally queued tasks are
 * held by the current worker thread than there are other worker
 * threads that might steal them, or zero if this thread is not
 * operating in a ForkJoinPool. This value may be useful for
 * heuristic decisions about whether to fork other tasks. In many
 * usages of ForkJoinTasks, at steady state, each worker should
 * aim to maintain a small constant surplus (for example, 3) of
 * tasks, and to process computations locally if this threshold is
 * exceeded.
 *
 * @return the surplus number of tasks, which may be negative
 */
public static int getSurplusQueuedTaskCount() {
  return ForkJoinPool.getSurplusQueuedTaskCount();
}

代码示例来源:origin: FlexoVM/flexovm

/**
 * Returns an estimate of how many more locally queued tasks are
 * held by the current worker thread than there are other worker
 * threads that might steal them, or zero if this thread is not
 * operating in a ForkJoinPool. This value may be useful for
 * heuristic decisions about whether to fork other tasks. In many
 * usages of ForkJoinTasks, at steady state, each worker should
 * aim to maintain a small constant surplus (for example, 3) of
 * tasks, and to process computations locally if this threshold is
 * exceeded.
 *
 * @return the surplus number of tasks, which may be negative
 */
public static int getSurplusQueuedTaskCount() {
  return ForkJoinPool.getSurplusQueuedTaskCount();
}

代码示例来源:origin: hm.binkley/binkley-util

/**
 * Returns an estimate of how many more locally queued tasks are
 * held by the current worker thread than there are other worker
 * threads that might steal them, or zero if this thread is not
 * operating in a ForkJoinPool. This value may be useful for
 * heuristic decisions about whether to fork other tasks. In many
 * usages of ForkJoinTasks, at steady state, each worker should
 * aim to maintain a small constant surplus (for example, 3) of
 * tasks, and to process computations locally if this threshold is
 * exceeded.
 *
 * @return the surplus number of tasks, which may be negative
 */
public static int getSurplusQueuedTaskCount() {
  return ForkJoinPool.getSurplusQueuedTaskCount();
}

代码示例来源:origin: com.gluonhq/robovm-rt

/**
 * Returns an estimate of how many more locally queued tasks are
 * held by the current worker thread than there are other worker
 * threads that might steal them, or zero if this thread is not
 * operating in a ForkJoinPool. This value may be useful for
 * heuristic decisions about whether to fork other tasks. In many
 * usages of ForkJoinTasks, at steady state, each worker should
 * aim to maintain a small constant surplus (for example, 3) of
 * tasks, and to process computations locally if this threshold is
 * exceeded.
 *
 * @return the surplus number of tasks, which may be negative
 */
public static int getSurplusQueuedTaskCount() {
  return ForkJoinPool.getSurplusQueuedTaskCount();
}

代码示例来源:origin: MobiVM/robovm

/**
 * Returns an estimate of how many more locally queued tasks are
 * held by the current worker thread than there are other worker
 * threads that might steal them, or zero if this thread is not
 * operating in a ForkJoinPool. This value may be useful for
 * heuristic decisions about whether to fork other tasks. In many
 * usages of ForkJoinTasks, at steady state, each worker should
 * aim to maintain a small constant surplus (for example, 3) of
 * tasks, and to process computations locally if this threshold is
 * exceeded.
 *
 * @return the surplus number of tasks, which may be negative
 */
public static int getSurplusQueuedTaskCount() {
  return ForkJoinPool.getSurplusQueuedTaskCount();
}

代码示例来源:origin: ibinti/bugvm

/**
 * Returns an estimate of how many more locally queued tasks are
 * held by the current worker thread than there are other worker
 * threads that might steal them, or zero if this thread is not
 * operating in a ForkJoinPool. This value may be useful for
 * heuristic decisions about whether to fork other tasks. In many
 * usages of ForkJoinTasks, at steady state, each worker should
 * aim to maintain a small constant surplus (for example, 3) of
 * tasks, and to process computations locally if this threshold is
 * exceeded.
 *
 * @return the surplus number of tasks, which may be negative
 */
public static int getSurplusQueuedTaskCount() {
  return ForkJoinPool.getSurplusQueuedTaskCount();
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * Returns an estimate of how many more locally queued tasks are
 * held by the current worker thread than there are other worker
 * threads that might steal them, or zero if this thread is not
 * operating in a ForkJoinPool. This value may be useful for
 * heuristic decisions about whether to fork other tasks. In many
 * usages of ForkJoinTasks, at steady state, each worker should
 * aim to maintain a small constant surplus (for example, 3) of
 * tasks, and to process computations locally if this threshold is
 * exceeded.
 *
 * @return the surplus number of tasks, which may be negative
 */
public static int getSurplusQueuedTaskCount() {
  return ForkJoinPool.getSurplusQueuedTaskCount();
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * Returns an estimate of how many more locally queued tasks are
 * held by the current worker thread than there are other worker
 * threads that might steal them, or zero if this thread is not
 * operating in a ForkJoinPool. This value may be useful for
 * heuristic decisions about whether to fork other tasks. In many
 * usages of ForkJoinTasks, at steady state, each worker should
 * aim to maintain a small constant surplus (for example, 3) of
 * tasks, and to process computations locally if this threshold is
 * exceeded.
 *
 * @return the surplus number of tasks, which may be negative
 */
public static int getSurplusQueuedTaskCount() {
  return ForkJoinPool.getSurplusQueuedTaskCount();
}

相关文章

微信公众号

最新文章

更多

ForkJoinPool类方法