Ejemplo n.º 1
0
    def scheduleJobs(self):
        print("Sheduling Round")
        real_time = time.time()
        if self.platform_model == "simu":
            schedule_cycle(self.platform, self.env.now, "default")

            # retrieve jobs to launch
            jids_to_launch = []
            for jid, job in iteritems(self.platform.assigned_jobs):
                print("job.start_time %s" % job.start_time)
                if (job.start_time == self.env.now) and (job.state == "Waiting"):
                    self.waiting_jids.remove(jid)
                    jids_to_launch.append(jid)
                    job.state = "Running"
                    print("tolaunch: %s" % jid)
                    self.platform.running_jids.append(jid)

        else:
            print("call meta_schedule('internal')")
            meta_schedule("internal", plt)

            result = db.query(Job).filter(Job.state == "toLaunch").order_by(Job.id).all()

            for job_db in result:
                set_job_state(job_db.id, "Running")
                jid = self.db_jid2s_jid[job_db.id]
                self.waiting_jids.remove(jid)
                jids_to_launch.append(jid)
                self.jobs[jid].state = "Running"
                print("_tolaunch: %s" % jid)
                self.platform.running_jids.append(jid)

        print("Ids of jobs to launch: ", *jids_to_launch)
        print("Time befort scheduling round: ", self.bs._current_time, self.sched_delay)
        # update time
        real_sched_time = time.time() - real_time
        if self.sched_delay == -1:
            self.bs.consume_time(real_sched_time)  # TODO
        else:
            self.bs.consume_time(self.sched_delay)

        self.env.now = self.bs._current_time

        print("Time after scheduling round: ", self.bs._current_time)
        # send to uds
        if len(jids_to_launch) > 0:
            scheduled_jobs = []
            jobs_res = {}
            for jid in jids_to_launch:
                ds_job = self.jobs[jid].ds_job
                res = itvs2batsim_str0(self.jobs[jid].res_set)
                scheduled_jobs.append(ds_job)
                jobs_res[ds_job.id] = res

            self.bs.start_jobs(scheduled_jobs, jobs_res)
Ejemplo n.º 2
0
    def sched(self):

        next_job_arrival = self.job_arrival()

        while True:

            print('Wait for job arrivals or job endings', self.env.now)

            events = list(self.evt_running_jobs)
            if next_job_arrival is not None:
                print("append next_job_arrival evt")
                events.append(next_job_arrival)
            any_of_events = AnyOf(self.env, events)
            ev = yield any_of_events

            for k, v in iteritems(ev.todict()):
                if k == next_job_arrival:
                    print("job arrives !", v)
                    for jid in v:
                        self.waiting_jids.add(jid)
                    next_job_arrival = self.job_arrival()

                else:
                    print("job endings !", k, v)
                    # if k in self.evt_running_jobs:
                    # print("remove ev: ", k)
                    self.evt_running_jobs.remove(k)
                    self.jobs[v].state = "Terminated"
                    self.platform.completed_jids.append(v)
                    self.platform.running_jids.remove(v)

            now = self.env.now

            if ((next_job_arrival is None)
                    and not self.waiting_jids
                    and not self.evt_running_jobs):
                print("All job submitted, no more waiting or running jobs ...", now)
                self.env.exit()

            print("call schedule_cycle.... ", now)

            schedule_cycle(self.platform, now, "test")

            # launch jobs if needed
            for jid, job in iteritems(self.platform.assigned_jobs):
                if job.start_time == now:
                    self.waiting_jids.remove(jid)
                    job.state = "Running"
                    print("launch:", jid)
                    evt_running_job = self.env.timeout(job.run_time, jid)
                    self.evt_running_jobs.add(evt_running_job)

                    self.platform.running_jids.append(jid)
Ejemplo n.º 3
0
def test_db_job_sorting_simple_priority_no_waiting_time():

    config['JOB_SORTING'] = "simple_priority"

    plt = Platform()
    now = plt.get_time()

    # add some resources
    for i in range(4):
        db['Resource'].create(network_address="localhost")

    # add some job with priority
    for  i in range(10):
        priority = str(float(i)/10.0)
        insert_job(res=[(60, [('resource_id=4', "")])],
                   submission_time=now,
                   types=['priority='+priority])

        
    schedule_cycle(plt, plt.get_time())

    req = db['GanttJobsPrediction'].query\
                                   .order_by(db['GanttJobsPrediction'].start_time)\
                                   .all()
    flag = True

    print(req)
    for r in req:
        print(r.moldable_id, r.start_time)
    for i, r in enumerate(req):
        if i != 0:
            print(r.moldable_id, prev_id)
            if r.moldable_id > prev_id:
                flag = False
                break
        prev_id = r.moldable_id

    assert flag
Ejemplo n.º 4
0
    def sched_loop(self):
        nb_completed_jobs = 0
        while nb_completed_jobs < self.nb_jobs:

            now_float, jobs_submitted, new_jobs_completed = read_bat_msg(self.sock)

            # now_str = "10"
            # jobs_submitted = [1]
            # new_jobs_completed = []

            if jobs_submitted:
                for jid in jobs_submitted:
                    self.waiting_jids.add(jid)
                    if self.platform_model == "batsim-db":
                        print('set_job_state("Waiting"):', self.jobs[jid].db_jid)
                        set_job_state(self.jobs[jid].db_jid, "Waiting")

            nb_completed_jobs += len(new_jobs_completed)

            print("new job completed: %s" % new_jobs_completed)

            for jid in new_jobs_completed:
                jobs_completed.append(jid)
                if jid in self.platform.running_jids:
                    self.platform.running_jids.remove(jid)
                if self.platform_model == "batsim-db":
                    set_job_state(self.jobs[jid].db_jid, "Terminated")

            now = int(now_float)
            self.env.now = now  # TODO can be remove ???
            real_time = time.time()

            print("jobs running: %s" % self.platform.running_jids)
            print("jobs waiting: %s" % self.waiting_jids)
            print("jobs completed: %s" % jobs_completed)

            jids_to_launch = []

            if self.platform_model == "simu":
                print("call schedule_cycle.... %s" % now)
                schedule_cycle(self.platform, now, "default")

                # retrieve jobs to launch
                jids_to_launch = []
                for jid, job in iteritems(self.platform.assigned_jobs):
                    print("job.start_time %s" % job.start_time)
                    if (job.start_time == now) and (job.state == "Waiting"):
                        self.waiting_jids.remove(jid)
                        jids_to_launch.append(jid)
                        job.state = "Running"
                        print("tolaunch: %s" % jid)
                        self.platform.running_jids.append(jid)

            else:
                print("call meta_schedule('internal')")
                meta_schedule("internal", plt)
                # Launching phase
                # Retrieve job to Launch

                result = db.query(Job).filter(Job.state == "toLaunch").order_by(Job.id).all()

                for job_db in result:
                    set_job_state(job_db.id, "Running")
                    jid = self.db_jid2s_jid[job_db.id]
                    self.waiting_jids.remove(jid)
                    jids_to_launch.append(jid)
                    self.jobs[jid].state = "Running"
                    print("_tolaunch: %s" % jid)
                    self.platform.running_jids.append(jid)

            real_sched_time = time.time() - real_time
            if self.sched_delay == -1:
                now_float += real_sched_time
            else:
                now_float += self.sched_delay
            send_bat_msg(self.sock, now_float, jids_to_launch, self.jobs)