Esempio n. 1
0
    def __init__(self):
        self.running = True
        self.resource_queues = {'cpu': [],
                                'memory': [],
                                'bw': []}
        ''' this is to have multiple applications/queues; application = queue '''
        self.task_queue = []  # ready queues; [queue_id]
        self.task_queue_data = {}  # ready queue data; queue_id: [task...]
        # queues with pending tasks, which do not have the input ready
        self.pending_queue_data = {}
        self.task_queue_lock = threading.Lock()
        self.pending_task_queue_lock = threading.Lock()
        logfile = config.LOGDIR + "/scheduler.log"
        taskfile = config.LOGDIR + "/task.log"
        self.logger = WeaselLogger('scheduler', logfile)
        self.task_logger = WeaselLogger('tasklogger', logfile)
        ''' this is the thread that will perform the communication with the local schedulers '''
        self.server_thread = ZmqConnectionThread(
            'resourcemng',
            zmq.ROUTER,
            "*:" + str(
                config.ZMQ_SCHEDULER_PORT),
            self.msg_process_callback)
        ''' this information is for keeping track of files and task dependencies '''
        self.task_to_file = {
        }  # taskid: {'nfiles': 0, 'ntotalfiles':x, 'outputs':[files]}
        # file: {'ntids': ntids, 'tids': [tids], 'ctids': executed_tasks}
        self.file_to_task = {}
        self.result_queue = Queue()
        self.result_consumer_thread = threading.Thread(target=self.get_result)
        self.result_consumer_thread.start()
        ''' idle worker information and client notification '''
        self.waiting_clients = []
        self.workers_empty_dict = {}
        self.workers = []
        self.workers_data = {}
	self.workers_lock = threading.Lock()
        self.workers_empty = 0
        self.task_id = 0
        ''' to notify workers about new queues '''
        self.new_queues = []
        self.new_queues_lock = threading.Lock()
        ''' here I have: the thread that listens for messages
            a queue in which the tasks are put
            the main thread that applies some reconfiguration (?)
        '''
        self.files_to_delete = []
Esempio n. 2
0
    def __init__(self):
        self.identity = 'sched-' + socket.gethostbyname(socket.gethostname())
        self.sched_client_thread = ZmqConnectionThread(
            self.identity,
            zmq.DEALER,
            config.SCHEDULER+":" + str(config.ZMQ_SCHEDULER_PORT),
            self.callback)
        self.monitor_thread = NodeMonitor()
        self.running = True
        logfile = config.LOGDIR + "/local_scheduler.log"
        self.logger = WeaselLogger('local_scheduler', logfile)
        self.capacity = self.monitor_thread.capacity
        self.max_tasks_to_run = {}
        ''' the starting number of tasks is defined based on the slot size '''
        self.ntasks_to_ask = 1
        self.task_id = 1
        self.time_asked_first = time.time()
        self.time_from_last_ask = -1
        ''' this is to keep track of number of running tasks ? '''
        self.running_task = 0
        self.nran_tasks = []
        self.time_from_last_ask = time.time()
        self.queues_asked_for = []
        self.current_ntasks = 1
        self.has_new_task = False
        self.is_profiling = False
        self.first_task = False
        self.task_data = {}
        self.t_avg = {}
        self.task_data_lock = threading.Lock()
        self.running_task_lock = threading.Lock()
        self.average_utilization = {'cpu': 0.0, 'memory': 0.0, 'network': 0.0}
        self.average_task_exec_time = 0.0
        self.sleep_time = config.WAITTIME
        self.past_speed_changes = []
        # 'id': id, 'tpool': threadPool, 'rvector': resource_characteristics
        self.queue_data = {}
	self.task_time = 1
        self.queue_data_lock = threading.Lock()
        self.has_new_queue = False
        self.new_queues = []
        self.message_to_send = None
	''' this is to control how many tasks to run in parallel'''
        self.logger.info("NodeScheduler started...")
        self.nrunning_past_period = []
Esempio n. 3
0
def make_request(identity, header, message):
    request = [identity, header, message]
    return request


def send_message(socket, message):
    socket.send_multipart(message)


def get_reply(socket):
    return socket.recv_multipart()


log_name = 'notification'
notification_logger = WeaselLogger(log_name,
                                   config.LOGDIR + '/' + log_name + '.log')


class ZmqConnectionThread(Thread):
    def __init__(self, identity, socket_type, address, msg_process_callback):
        Thread.__init__(self)
        self.running = True
        self.requests = []
        self.lock = Lock()
        self.msg_process_callback = msg_process_callback
        self.context = get_context()
        self.frontend = tmp_socket(self.context, socket_type, identity,
                                   address)
        self.frontend.setsockopt(zmq.LINGER, 120000)
        self.poll = zmq.Poller()
        self.backup_socket = None