<commit_before>//
// WorkStealingScheduler.scala -- A work-stealing scheduler for Orc
// Project OrcScala
//
// Created by amp on Feb, 2017.
//
// Copyright (c) 2017 The University of Texas at Austin. All rights reserved.
//
// Use and redistribution of this file is governed by the license terms in
// the LICENSE file found in the project's top-level directory and also found at
// URL: http://orc.csres.utexas.edu/license.shtml .
//
package orc.run.extensions

import java.util.concurrent.ConcurrentLinkedQueue
import java.util.logging.Level

import scala.collection.mutable.ArrayBuffer

import orc.{ OrcExecutionOptions, Schedulable }
import orc.run.Orc
import orc.util.ABPWSDeque

/** @param monitorInterval The interval at which the monitor thread runs and checks that the thread pool is the correct size.
  * @param goalExtraThreads The ideal number of extra idle threads that the pool should contain.
  * @param workerQueueLength The length of the queues maintained by the threads. If this is too small the threads will overflow their queues frequently, if this is too large it will waste memory.
  *
  * @author amp
  */
class SimpleWorkStealingScheduler(
  maxSiteThreads: Int,
  val monitorInterval: Int = 100,
  val goalExtraThreads: Int = 0,
  val workerQueueLength: Int = 1024 * 2) {
  schedulerThis =>

  val nCores = Runtime.getRuntime().availableProcessors()
  
  val overrideWorkers = Option(System.getProperty("SimpleWorkStealingScheduler.overrideWorkers")).map(_.toInt)
  overrideWorkers foreach { n =>
    Logger.info(s"Worker count fixed at $n (read from System property SimpleWorkStealingScheduler.overrideWorkers).")
  }

  /** The minimum number of worker threads.
    */
  val minWorkers = overrideWorkers.getOrElse(math.max(4, nCores * 2))
  /** The maximum number of worker threads.
    */
  val maxWorkers = overrideWorkers.getOrElse(minWorkers + maxSiteThreads)
  /** The maximum amount of time (ms) to wait between attempts to steal work.
    */
  val maxStealWait = 100
  /** The ideal number of active (non-blocked) worker threads.<commit_msg>Add "orc." to system property name.<commit_after>//
// WorkStealingScheduler.scala -- A work-stealing scheduler for Orc
// Project OrcScala
//
// Created by amp on Feb, 2017.
//
// Copyright (c) 2017 The University of Texas at Austin. All rights reserved.
//
// Use and redistribution of this file is governed by the license terms in
// the LICENSE file found in the project's top-level directory and also found at
// URL: http://orc.csres.utexas.edu/license.shtml .
//
package orc.run.extensions

import java.util.concurrent.ConcurrentLinkedQueue
import java.util.logging.Level

import scala.collection.mutable.ArrayBuffer

import orc.{ OrcExecutionOptions, Schedulable }
import orc.run.Orc
import orc.util.ABPWSDeque

/** @param monitorInterval The interval at which the monitor thread runs and checks that the thread pool is the correct size.
  * @param goalExtraThreads The ideal number of extra idle threads that the pool should contain.
  * @param workerQueueLength The length of the queues maintained by the threads. If this is too small the threads will overflow their queues frequently, if this is too large it will waste memory.
  *
  * @author amp
  */
class SimpleWorkStealingScheduler(
  maxSiteThreads: Int,
  val monitorInterval: Int = 100,
  val goalExtraThreads: Int = 0,
  val workerQueueLength: Int = 1024 * 2) {
  schedulerThis =>

  val nCores = Runtime.getRuntime().availableProcessors()
  
  val overrideWorkers = Option(System.getProperty("orc.SimpleWorkStealingScheduler.overrideWorkers")).map(_.toInt)
  overrideWorkers foreach { n =>
    Logger.info(s"Worker count fixed at $n (read from System property orc.SimpleWorkStealingScheduler.overrideWorkers).")
  }

  /** The minimum number of worker threads.
    */
  val minWorkers = overrideWorkers.getOrElse(math.max(4, nCores * 2))
  /** The maximum number of worker threads.
    */
  val maxWorkers = overrideWorkers.getOrElse(minWorkers + maxSiteThreads)
  /** The maximum amount of time (ms) to wait between attempts to steal work.
    */
  val maxStealWait = 100
  /** The ideal number of active (non-blocked) worker threads.
{'fraction_non_alphanumeric': 0.08656145384983262, 'fraction_numerical': 0.010521281683405069, 'mean_word_length': 3.967933491686461, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4151479', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1187, 'n_words': 446}