コード例 #1
0
    def test_get_priority_metric(self):
        ts = task_scheduler.TaskScheduler()
        t = task_scheduler.TaskScheduler.Task('task', 2, 100)
        ts.tasks[t.name] = t

        # Verify that our priority metric is a tasks cores * full execution time
        self.assertEqual(200, ts.get_priority_metric(t.name))
コード例 #2
0
    def test_prioritize_tasks(self):
        ts = task_scheduler.TaskScheduler()
        t1 = task_scheduler.TaskScheduler.Task('task1', 1, 100)
        t2 = task_scheduler.TaskScheduler.Task('task2', 3, 200)
        t3 = task_scheduler.TaskScheduler.Task('task3', 2, 200)
        ts.tasks[t1.name] = t1
        ts.tasks[t2.name] = t2
        ts.tasks[t3.name] = t3

        # Verify that prioritize_tasks returns a list of tasks in descending
        # order based on their priority metrics
        self.assertEqual([t2.name, t3.name, t1.name], ts.prioritize_tasks())
コード例 #3
0
def get_schedule(observers, function):
    '''
    Generate observer order based on scheduling requests for specified
    function.

    Parameters
    ----------
    observers : dict
        Mapping from service names to service instances.
    function : str
        Name of function to generate schedule for.

    Returns
    -------
    list
        List of observer service names in scheduled order.
    '''
    logger = _L()  # use logger with function context

    # Query plugins for schedule requests for 'function'
    schedule_requests = {}
    for observer in observers.values():
        if hasattr(observer, 'get_schedule_requests'):
            schedule_requests[observer.name] =\
                    observer.get_schedule_requests(function)

    if schedule_requests:
        scheduler = task_scheduler.TaskScheduler(observers.keys())
        for request in [
                r for name, requests in schedule_requests.items()
                for r in requests
        ]:
            try:
                scheduler.request_order(*request)
            except AssertionError:
                logger.debug('Schedule requests for `%s`', function)
                map(logger.debug,
                    pprint.pformat(schedule_requests).splitlines())
                logger.info(
                    'emit_signal(%s) could not add schedule request '
                    '%s', function, request)
                continue
        return scheduler.get_schedule()
    else:
        return observers.keys()
コード例 #4
0
ファイル: plugin_manager.py プロジェクト: ryanfobel/microdrop
def get_schedule(observers, function):
    # Query plugins for schedule requests for 'function'
    schedule_requests = {}
    for observer in observers.values():
        if hasattr(observer, 'get_schedule_requests'):
            schedule_requests[observer.name] =\
                    observer.get_schedule_requests(function)

    if schedule_requests:
        scheduler = task_scheduler.TaskScheduler(observers.keys())
        for request in [
                r for name, requests in schedule_requests.items()
                for r in requests
        ]:
            try:
                scheduler.request_order(*request)
            except AssertionError:
                logging.info('[PluginManager] emit_signal(%s) could not '\
                        'add schedule request %s' % (function, request))
                continue
        return scheduler.get_schedule()
    else:
        return observers.keys()
コード例 #5
0
    def test_find_free_compute_resource(self):
        ts = task_scheduler.TaskScheduler()
        r1 = task_scheduler.TaskScheduler.ComputeResource('resource1', 1)
        r2 = task_scheduler.TaskScheduler.ComputeResource('resource2', 2)

        t1 = task_scheduler.TaskScheduler.Task('task1', 1, 100)
        t2 = task_scheduler.TaskScheduler.Task('task2', 2, 200)

        # If no resources available find_free_compute_resource returns None
        self.assertEqual(None, ts.find_free_compute_resource(t1))

        ts.resources = [r1]
        # With a resource that has enough free cores to handle a task
        # find_free_compute_resource should return that resource
        self.assertEqual(r1, ts.find_free_compute_resource(t1))
        # If a task is too large for a resource, find_free_compute_resource
        # return None
        self.assertEqual(None, ts.find_free_compute_resource(t2))

        ts.resources = [r1, r2]
        # With multiple resources a find_free_compute_resource will return
        # the resource with the lowest cores available >= tasks cores_required
        self.assertEqual(r1, ts.find_free_compute_resource(t1))
        self.assertEqual(r2, ts.find_free_compute_resource(t2))
コード例 #6
0
import os
import sys

filepath = os.path.join(os.path.dirname(os.path.realpath(__file__)))
sys.path.insert(0, os.path.join(filepath, '..'))
import task_scheduler

ts = task_scheduler.TaskScheduler()
ts.load_yaml(
    os.path.join(filepath, 'yaml_files', 'resources_noninterger_cores.yaml'),
    os.path.join(filepath, 'yaml_files', 'tasks1.yaml'))
ts.find_schedule()
コード例 #7
0
 def test_initializtion(self):
     ts = task_scheduler.TaskScheduler()
     self.assertEqual({}, ts.tasks)
     self.assertEqual([], ts.resources)