Class ThreadManager

  • All Implemented Interfaces:
    ConfigConstants

    public class ThreadManager
    extends Object
    implements ConfigConstants
    Manages client side concurrency based on available server threads
    • Field Detail

      • LOG

        public static final org.apache.commons.logging.Log LOG
    • Constructor Detail

      • ThreadManager

        public ThreadManager​(LocalJob job)
    • Method Detail

      • parseCmdlineOptions

        public void parseCmdlineOptions​(org.apache.commons.cli.CommandLine cmdline,
                                        Command cmd)
        Parse command line options
        Parameters:
        cmdline -
        cmd -
      • queryServerMaxThreads

        public void queryServerMaxThreads​(com.marklogic.xcc.ContentSource cs)
                                   throws com.marklogic.xcc.exceptions.RequestException
        Query the server stack to get the maximum available thread count.
        Parameters:
        cs -
        Throws:
        com.marklogic.xcc.exceptions.RequestException
      • runThreadPoller

        public void runThreadPoller()
        Schedule thread polling tasks.
      • runAutoScaling

        public boolean runAutoScaling()
        Check whether mlcp runs auto-scaling. If the user specifies command line option -thread_count or -thread_count_per_split, or mlcp is not running against a load balancer, then mlcp does not auto-scale.
        Returns:
        true if mlcp runs auto-scaling, false if it doesn't.
      • initThreadPool

        public ThreadPoolExecutor initThreadPool()
        Initialize thread pool before mlcp starts running jobs.
        Returns:
        initialized thread pool.
      • getActiveTaskCounts

        public int getActiveTaskCounts()
        Return the total counts of LocalMapTask that are actively running.
      • scaleOutThreadPool

        public void scaleOutThreadPool​(int activeTaskCounts)
        Scale-out thread pool based on newly available server threads. Create new map runners and assign them to each existing LocalMapTask in a round-robin fashion.
      • scaleInThreadPool

        public void scaleInThreadPool​(int activeTaskCounts)
        Scale-in thread pool based on new available server threads. Deduct active runners from each LocalMapTask in a round-robin fashion.
      • assignIdleThreads

        public void assignIdleThreads​(int activeTaskCounts)
        Reassign all the idle server threads in the thread pool to other active running tasks.
        Parameters:
        activeTaskCounts -
      • submitTask

        public void submitTask​(LocalJobRunner.LocalMapTask task,
                               int index,
                               int splitCount)
                        throws Exception
        Submit LocalMapTask (one task per input split) to thread pool.
        Parameters:
        task -
        index -
        splitCount -
        Throws:
        Exception
      • setRestrictHosts

        public void setRestrictHosts​(boolean newRestrictHosts)
        Used by checkOutputSpecs for indicating whether mlcp is running against a load balancer.
        Parameters:
        newRestrictHosts -