Uploaded image for project: 'OptaPlanner'
  1. OptaPlanner
  2. PLANNER-338

SolverManager: a high-level wrapper for the low-level Solver to handle thread management, multitenancy, load-balancing, ...

    XMLWordPrintable

Details

    • Solver Manager
    • Done

    Description

      The Solver deliberately doesn't do any thread creation. It just provides the low-level tread-safe methods such as terminateEarly() and addProblemFactChange(pfc).

      The SolverManager will be a wrapper that does do thread management to add the following functionality.

      Phase 1:

      • It manages the thread pool with the internal solver threads.
      • It exposes the solver status (not started, solving, terminate early, stopped, etc) to external threads.
      • It exposes the best solution (and the best score) to the external threads.
      • It support adding problem fact changes
      • Thread safe
      • Graceful shutdown See PLANNER-534
      • Exception handling and reporting: Don't eat an exception (for example thrown by a custom score calculator), but instead relay it to the external threads when they ask for something.
      • Pluggable thread management: Reuse managed ExecutorService from wildfly/EAP so the thread pool size can be controlled through JMX.

      Phase 2 and later

      • Handle a solver will itself spawns multiple threads. For example an 8 pool thread with 2 solvers each doing a 4-threaded Partitioned Search is already full...
      • Multitenancy load balancing: Running 10 solver datasets with 8 cores will only run 8 in parallel and round-robin swap out the other 2 (if desired, alternatively it starts 10 threads and let the JVM do the round-robining).
        • it can run 100 solvers simultaneously on an 8 core machine but still only saturate 6 cores (if configured for that behavior),
          by injecting a runnableThreadSemaphore in each solver with a runnableSolverThreadLimit = 6.
          I've already done that trick for PartitionedSearch and that works like a charm
      • Fail-over: threads can die
      • High Availability? Horizontal scaling across multiple nodes.
      • Load balancing?

      SolverManager should be reusable by camel-optaplanner, mule-optaplanner, optaplanner-execution-server, ...

      Strawman api proposal

      interface SolverManager {
         Long addSolver(optional KieContainer, String solverConfigPath); // returns a solverId
         boolean removeSolver(Long solverId);
        
         boolean solveAsync(Long solverId, Solution planningProblem, optional callback);
         Solution getBestSolution(Long solverId);
         SolverStatus getSolverStatus(Long solverId);
         boolean terminateEarly(Long solverId);
         boolean addProblemFactChange(Long solverId, ProblemFactChange);
         ...
      }
      

      Discussions document: https://docs.google.com/document/d/16gZZUuxufjG4NLAS-FdLm9Rquhc0TrSespXJeddX5Xk/edit?usp=sharing

      Attachments

        Issue Links

          Activity

            People

              gdesmet@redhat.com Geoffrey De Smet (Inactive)
              gdesmet@redhat.com Geoffrey De Smet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: