@Test public void test() { ArrayList<BatchScheduler.ActiveJob> activeJobs = new ArrayList<BatchScheduler.ActiveJob>(); activeJobs.addAll(Arrays.asList(job1,job2,job3,job4,job5,job6,job7,job8,job9,job10)); int numCpusAllocated = 5; int numCpusTotal = 10; double load = 0.4; PartitionStatistics partitionStatistics = new PartitionStatistics(numCpusAllocated, numCpusTotal, load); int userQuotaOde = 2; int userQuotaPde = 2; VCellServerID systemID = relSite; SchedulerDecisions schedulerDecisions = BatchScheduler.schedule(activeJobs, partitionStatistics, userQuotaOde, userQuotaPde, systemID); schedulerDecisions.show(); }
public static SchedulerDecisions schedule(List<ActiveJob> activeJobsAllSites, PartitionStatistics partitionStatistics, int userQuotaOde, int userQuotaPde, VCellServerID systemID) { Hashtable<User, UserQuotaInfo> userQuotaInfoMap = new Hashtable<User, UserQuotaInfo>(); int numPendingJobsAllSites = 0; for (ActiveJob activeJob : activeJobsAllSites) { UserQuotaInfo userQuotaInfo = userQuotaInfoMap.get(activeJob.simulationOwner); if (userQuotaInfo==null) { userQuotaInfo = new UserQuotaInfo(activeJob.simulationOwner); userQuotaInfoMap.put(activeJob.simulationOwner, userQuotaInfo); } if (!activeJob.schedulerStatus.isActive()) { continue; } if (activeJob.schedulerStatus.isWaiting()) { continue; } if (activeJob.schedulerStatus.isDispatched() || activeJob.schedulerStatus.isQueued()) { numPendingJobsAllSites++; } if(activeJob.isPDE) { userQuotaInfo.numPdeRunningJobsAllSites++; } else { userQuotaInfo.numOdeRunningJobsAllSites++; } } SchedulerDecisions schedulerDecisions = new SchedulerDecisions(activeJobsAllSites); ArrayList<ActiveJob> prioritizedJobList = new ArrayList<ActiveJob>(activeJobsAllSites); for (ActiveJob activeJob : activeJobsAllSites) { if (!activeJob.schedulerStatus.isActive()) { schedulerDecisions.setInactive(activeJob); prioritizedJobList.remove(activeJob); continue; } if (!activeJob.schedulerStatus.isWaiting()) { schedulerDecisions.setAlreadyRunningOrQueued(activeJob); prioritizedJobList.remove(activeJob); continue; } } Collections.sort(prioritizedJobList,new Comparator<ActiveJob>(){ @Override public int compare(ActiveJob o1, ActiveJob o2) { UserQuotaInfo userQuotaInfo1 = userQuotaInfoMap.get(o1.simulationOwner); UserQuotaInfo userQuotaInfo2 = userQuotaInfoMap.get(o2.simulationOwner); if (userQuotaInfo1.getNumRunningJobs() != userQuotaInfo2.getNumRunningJobs()){ return Integer.compare(userQuotaInfo1.getNumRunningJobs(), userQuotaInfo2.getNumRunningJobs()); } if (o1.isPDE != o2.isPDE){ if (o1.isPDE){ return 1; }else{ return -1; } } return Long.compare(o1.submitTimestamp, o2.submitTimestamp); } }); int index=0; for (ActiveJob activeJob : prioritizedJobList) { schedulerDecisions.setOrdinal(activeJob, index); index++; } HashSet<User> users = new HashSet<User>(); users.addAll(userQuotaInfoMap.keySet()); for (User user : users){ UserQuotaInfo userQuotaInfo = userQuotaInfoMap.get(user); int numDesiredRunningPDEsAllSites = userQuotaInfo.numPdeRunningJobsAllSites; int numDesiredRunningODEsAllSites = userQuotaInfo.numOdeRunningJobsAllSites; Iterator<ActiveJob> prioritizedJobIter = prioritizedJobList.iterator(); while (prioritizedJobIter.hasNext()){ ActiveJob waitingJob = prioritizedJobIter.next(); if (waitingJob.simulationOwner.equals(user)){ if (waitingJob.isPDE){ if (numDesiredRunningPDEsAllSites < userQuotaPde){ numDesiredRunningPDEsAllSites++; }else{ schedulerDecisions.setHeldUserQuotaPDE(waitingJob); prioritizedJobIter.remove(); } }else{ if (numDesiredRunningODEsAllSites < userQuotaOde){ numDesiredRunningODEsAllSites++; }else{ schedulerDecisions.setHeldUserQuotaODE(waitingJob); prioritizedJobIter.remove(); } } } } } int inUseCPUs = partitionStatistics.numCpusAllocated; int cpusAvailable = Math.max(0, partitionStatistics.numCpusTotal - inUseCPUs); int numJobsSlotsAvailable = Math.max(0, cpusAvailable - numPendingJobsAllSites); for (int i=0;i<prioritizedJobList.size();i++) { ActiveJob nextWaitingJob = prioritizedJobList.get(i); if (i<numJobsSlotsAvailable) { if (nextWaitingJob.serverId.equals(systemID)){ schedulerDecisions.setRunnableThisSite(nextWaitingJob); }else { schedulerDecisions.setRunnableOtherSite(nextWaitingJob); } }else { schedulerDecisions.setHeldClusterResources(nextWaitingJob); } } schedulerDecisions.verify(partitionStatistics); return schedulerDecisions; }
BatchScheduler { public static SchedulerDecisions schedule(List<ActiveJob> activeJobsAllSites, PartitionStatistics partitionStatistics, int userQuotaOde, int userQuotaPde, VCellServerID systemID) { Hashtable<User, UserQuotaInfo> userQuotaInfoMap = new Hashtable<User, UserQuotaInfo>(); int numPendingJobsAllSites = 0; for (ActiveJob activeJob : activeJobsAllSites) { UserQuotaInfo userQuotaInfo = userQuotaInfoMap.get(activeJob.simulationOwner); if (userQuotaInfo==null) { userQuotaInfo = new UserQuotaInfo(activeJob.simulationOwner); userQuotaInfoMap.put(activeJob.simulationOwner, userQuotaInfo); } if (!activeJob.schedulerStatus.isActive()) { continue; } if (activeJob.schedulerStatus.isWaiting()) { continue; } if (activeJob.schedulerStatus.isDispatched() || activeJob.schedulerStatus.isQueued()) { numPendingJobsAllSites++; } if(activeJob.isPDE) { userQuotaInfo.numPdeRunningJobsAllSites++; } else { userQuotaInfo.numOdeRunningJobsAllSites++; } } SchedulerDecisions schedulerDecisions = new SchedulerDecisions(activeJobsAllSites); ArrayList<ActiveJob> prioritizedJobList = new ArrayList<ActiveJob>(activeJobsAllSites); for (ActiveJob activeJob : activeJobsAllSites) { if (!activeJob.schedulerStatus.isActive()) { schedulerDecisions.setInactive(activeJob); prioritizedJobList.remove(activeJob); continue; } if (!activeJob.schedulerStatus.isWaiting()) { schedulerDecisions.setAlreadyRunningOrQueued(activeJob); prioritizedJobList.remove(activeJob); continue; } } Collections.sort(prioritizedJobList,new Comparator<ActiveJob>(){ @Override public int compare(ActiveJob o1, ActiveJob o2) { UserQuotaInfo userQuotaInfo1 = userQuotaInfoMap.get(o1.simulationOwner); UserQuotaInfo userQuotaInfo2 = userQuotaInfoMap.get(o2.simulationOwner); if (userQuotaInfo1.getNumRunningJobs() != userQuotaInfo2.getNumRunningJobs()){ return Integer.compare(userQuotaInfo1.getNumRunningJobs(), userQuotaInfo2.getNumRunningJobs()); } if (o1.isPDE != o2.isPDE){ if (o1.isPDE){ return 1; }else{ return -1; } } return Long.compare(o1.submitTimestamp, o2.submitTimestamp); } }); int index=0; for (ActiveJob activeJob : prioritizedJobList) { schedulerDecisions.setOrdinal(activeJob, index); index++; } HashSet<User> users = new HashSet<User>(); users.addAll(userQuotaInfoMap.keySet()); for (User user : users){ UserQuotaInfo userQuotaInfo = userQuotaInfoMap.get(user); int numDesiredRunningPDEsAllSites = userQuotaInfo.numPdeRunningJobsAllSites; int numDesiredRunningODEsAllSites = userQuotaInfo.numOdeRunningJobsAllSites; Iterator<ActiveJob> prioritizedJobIter = prioritizedJobList.iterator(); while (prioritizedJobIter.hasNext()){ ActiveJob waitingJob = prioritizedJobIter.next(); if (waitingJob.simulationOwner.equals(user)){ if (waitingJob.isPDE){ if (numDesiredRunningPDEsAllSites < userQuotaPde){ numDesiredRunningPDEsAllSites++; }else{ schedulerDecisions.setHeldUserQuotaPDE(waitingJob); prioritizedJobIter.remove(); } }else{ if (numDesiredRunningODEsAllSites < userQuotaOde){ numDesiredRunningODEsAllSites++; }else{ schedulerDecisions.setHeldUserQuotaODE(waitingJob); prioritizedJobIter.remove(); } } } } } int inUseCPUs = partitionStatistics.numCpusAllocated; int cpusAvailable = Math.max(0, partitionStatistics.numCpusTotal - inUseCPUs); int numJobsSlotsAvailable = Math.max(0, cpusAvailable - numPendingJobsAllSites); for (int i=0;i<prioritizedJobList.size();i++) { ActiveJob nextWaitingJob = prioritizedJobList.get(i); if (i<numJobsSlotsAvailable) { if (nextWaitingJob.serverId.equals(systemID)){ schedulerDecisions.setRunnableThisSite(nextWaitingJob); }else { schedulerDecisions.setRunnableOtherSite(nextWaitingJob); } }else { schedulerDecisions.setHeldClusterResources(nextWaitingJob); } } schedulerDecisions.verify(partitionStatistics); return schedulerDecisions; } }
BatchScheduler { public static SchedulerDecisions schedule(List<ActiveJob> activeJobsAllSites, PartitionStatistics partitionStatistics, int userQuotaOde, int userQuotaPde, VCellServerID systemID) { Hashtable<User, UserQuotaInfo> userQuotaInfoMap = new Hashtable<User, UserQuotaInfo>(); int numPendingJobsAllSites = 0; for (ActiveJob activeJob : activeJobsAllSites) { UserQuotaInfo userQuotaInfo = userQuotaInfoMap.get(activeJob.simulationOwner); if (userQuotaInfo==null) { userQuotaInfo = new UserQuotaInfo(activeJob.simulationOwner); userQuotaInfoMap.put(activeJob.simulationOwner, userQuotaInfo); } if (!activeJob.schedulerStatus.isActive()) { continue; } if (activeJob.schedulerStatus.isWaiting()) { continue; } if (activeJob.schedulerStatus.isDispatched() || activeJob.schedulerStatus.isQueued()) { numPendingJobsAllSites++; } if(activeJob.isPDE) { userQuotaInfo.numPdeRunningJobsAllSites++; } else { userQuotaInfo.numOdeRunningJobsAllSites++; } } SchedulerDecisions schedulerDecisions = new SchedulerDecisions(activeJobsAllSites); ArrayList<ActiveJob> prioritizedJobList = new ArrayList<ActiveJob>(activeJobsAllSites); for (ActiveJob activeJob : activeJobsAllSites) { if (!activeJob.schedulerStatus.isActive()) { schedulerDecisions.setInactive(activeJob); prioritizedJobList.remove(activeJob); continue; } if (!activeJob.schedulerStatus.isWaiting()) { schedulerDecisions.setAlreadyRunningOrQueued(activeJob); prioritizedJobList.remove(activeJob); continue; } } Collections.sort(prioritizedJobList,new Comparator<ActiveJob>(){ @Override public int compare(ActiveJob o1, ActiveJob o2) { UserQuotaInfo userQuotaInfo1 = userQuotaInfoMap.get(o1.simulationOwner); UserQuotaInfo userQuotaInfo2 = userQuotaInfoMap.get(o2.simulationOwner); if (userQuotaInfo1.getNumRunningJobs() != userQuotaInfo2.getNumRunningJobs()){ return Integer.compare(userQuotaInfo1.getNumRunningJobs(), userQuotaInfo2.getNumRunningJobs()); } if (o1.isPDE != o2.isPDE){ if (o1.isPDE){ return 1; }else{ return -1; } } return Long.compare(o1.submitTimestamp, o2.submitTimestamp); } }); int index=0; for (ActiveJob activeJob : prioritizedJobList) { schedulerDecisions.setOrdinal(activeJob, index); index++; } HashSet<User> users = new HashSet<User>(); users.addAll(userQuotaInfoMap.keySet()); for (User user : users){ UserQuotaInfo userQuotaInfo = userQuotaInfoMap.get(user); int numDesiredRunningPDEsAllSites = userQuotaInfo.numPdeRunningJobsAllSites; int numDesiredRunningODEsAllSites = userQuotaInfo.numOdeRunningJobsAllSites; Iterator<ActiveJob> prioritizedJobIter = prioritizedJobList.iterator(); while (prioritizedJobIter.hasNext()){ ActiveJob waitingJob = prioritizedJobIter.next(); if (waitingJob.simulationOwner.equals(user)){ if (waitingJob.isPDE){ if (numDesiredRunningPDEsAllSites < userQuotaPde){ numDesiredRunningPDEsAllSites++; }else{ schedulerDecisions.setHeldUserQuotaPDE(waitingJob); prioritizedJobIter.remove(); } }else{ if (numDesiredRunningODEsAllSites < userQuotaOde){ numDesiredRunningODEsAllSites++; }else{ schedulerDecisions.setHeldUserQuotaODE(waitingJob); prioritizedJobIter.remove(); } } } } } int inUseCPUs = partitionStatistics.numCpusAllocated; int cpusAvailable = Math.max(0, partitionStatistics.numCpusTotal - inUseCPUs); int numJobsSlotsAvailable = Math.max(0, cpusAvailable - numPendingJobsAllSites); for (int i=0;i<prioritizedJobList.size();i++) { ActiveJob nextWaitingJob = prioritizedJobList.get(i); if (i<numJobsSlotsAvailable) { if (nextWaitingJob.serverId.equals(systemID)){ schedulerDecisions.setRunnableThisSite(nextWaitingJob); }else { schedulerDecisions.setRunnableOtherSite(nextWaitingJob); } }else { schedulerDecisions.setHeldClusterResources(nextWaitingJob); } } schedulerDecisions.verify(partitionStatistics); return schedulerDecisions; } BatchScheduler(); }
BatchScheduler { public static SchedulerDecisions schedule(List<ActiveJob> activeJobsAllSites, PartitionStatistics partitionStatistics, int userQuotaOde, int userQuotaPde, VCellServerID systemID) { Hashtable<User, UserQuotaInfo> userQuotaInfoMap = new Hashtable<User, UserQuotaInfo>(); int numPendingJobsAllSites = 0; for (ActiveJob activeJob : activeJobsAllSites) { UserQuotaInfo userQuotaInfo = userQuotaInfoMap.get(activeJob.simulationOwner); if (userQuotaInfo==null) { userQuotaInfo = new UserQuotaInfo(activeJob.simulationOwner); userQuotaInfoMap.put(activeJob.simulationOwner, userQuotaInfo); } if (!activeJob.schedulerStatus.isActive()) { continue; } if (activeJob.schedulerStatus.isWaiting()) { continue; } if (activeJob.schedulerStatus.isDispatched() || activeJob.schedulerStatus.isQueued()) { numPendingJobsAllSites++; } if(activeJob.isPDE) { userQuotaInfo.numPdeRunningJobsAllSites++; } else { userQuotaInfo.numOdeRunningJobsAllSites++; } } SchedulerDecisions schedulerDecisions = new SchedulerDecisions(activeJobsAllSites); ArrayList<ActiveJob> prioritizedJobList = new ArrayList<ActiveJob>(activeJobsAllSites); for (ActiveJob activeJob : activeJobsAllSites) { if (!activeJob.schedulerStatus.isActive()) { schedulerDecisions.setInactive(activeJob); prioritizedJobList.remove(activeJob); continue; } if (!activeJob.schedulerStatus.isWaiting()) { schedulerDecisions.setAlreadyRunningOrQueued(activeJob); prioritizedJobList.remove(activeJob); continue; } } Collections.sort(prioritizedJobList,new Comparator<ActiveJob>(){ @Override public int compare(ActiveJob o1, ActiveJob o2) { UserQuotaInfo userQuotaInfo1 = userQuotaInfoMap.get(o1.simulationOwner); UserQuotaInfo userQuotaInfo2 = userQuotaInfoMap.get(o2.simulationOwner); if (userQuotaInfo1.getNumRunningJobs() != userQuotaInfo2.getNumRunningJobs()){ return Integer.compare(userQuotaInfo1.getNumRunningJobs(), userQuotaInfo2.getNumRunningJobs()); } if (o1.isPDE != o2.isPDE){ if (o1.isPDE){ return 1; }else{ return -1; } } return Long.compare(o1.submitTimestamp, o2.submitTimestamp); } }); int index=0; for (ActiveJob activeJob : prioritizedJobList) { schedulerDecisions.setOrdinal(activeJob, index); index++; } HashSet<User> users = new HashSet<User>(); users.addAll(userQuotaInfoMap.keySet()); for (User user : users){ UserQuotaInfo userQuotaInfo = userQuotaInfoMap.get(user); int numDesiredRunningPDEsAllSites = userQuotaInfo.numPdeRunningJobsAllSites; int numDesiredRunningODEsAllSites = userQuotaInfo.numOdeRunningJobsAllSites; Iterator<ActiveJob> prioritizedJobIter = prioritizedJobList.iterator(); while (prioritizedJobIter.hasNext()){ ActiveJob waitingJob = prioritizedJobIter.next(); if (waitingJob.simulationOwner.equals(user)){ if (waitingJob.isPDE){ if (numDesiredRunningPDEsAllSites < userQuotaPde){ numDesiredRunningPDEsAllSites++; }else{ schedulerDecisions.setHeldUserQuotaPDE(waitingJob); prioritizedJobIter.remove(); } }else{ if (numDesiredRunningODEsAllSites < userQuotaOde){ numDesiredRunningODEsAllSites++; }else{ schedulerDecisions.setHeldUserQuotaODE(waitingJob); prioritizedJobIter.remove(); } } } } } int inUseCPUs = partitionStatistics.numCpusAllocated; int cpusAvailable = Math.max(0, partitionStatistics.numCpusTotal - inUseCPUs); int numJobsSlotsAvailable = Math.max(0, cpusAvailable - numPendingJobsAllSites); for (int i=0;i<prioritizedJobList.size();i++) { ActiveJob nextWaitingJob = prioritizedJobList.get(i); if (i<numJobsSlotsAvailable) { if (nextWaitingJob.serverId.equals(systemID)){ schedulerDecisions.setRunnableThisSite(nextWaitingJob); }else { schedulerDecisions.setRunnableOtherSite(nextWaitingJob); } }else { schedulerDecisions.setHeldClusterResources(nextWaitingJob); } } schedulerDecisions.verify(partitionStatistics); return schedulerDecisions; } BatchScheduler(); static final int getMaxOdeJobsPerUser(); static final int getMaxPdeJobsPerUser(); static SchedulerDecisions schedule(List<ActiveJob> activeJobsAllSites, PartitionStatistics partitionStatistics, int userQuotaOde, int userQuotaPde, VCellServerID systemID); }
BatchScheduler { public static SchedulerDecisions schedule(List<ActiveJob> activeJobsAllSites, PartitionStatistics partitionStatistics, int userQuotaOde, int userQuotaPde, VCellServerID systemID) { Hashtable<User, UserQuotaInfo> userQuotaInfoMap = new Hashtable<User, UserQuotaInfo>(); int numPendingJobsAllSites = 0; for (ActiveJob activeJob : activeJobsAllSites) { UserQuotaInfo userQuotaInfo = userQuotaInfoMap.get(activeJob.simulationOwner); if (userQuotaInfo==null) { userQuotaInfo = new UserQuotaInfo(activeJob.simulationOwner); userQuotaInfoMap.put(activeJob.simulationOwner, userQuotaInfo); } if (!activeJob.schedulerStatus.isActive()) { continue; } if (activeJob.schedulerStatus.isWaiting()) { continue; } if (activeJob.schedulerStatus.isDispatched() || activeJob.schedulerStatus.isQueued()) { numPendingJobsAllSites++; } if(activeJob.isPDE) { userQuotaInfo.numPdeRunningJobsAllSites++; } else { userQuotaInfo.numOdeRunningJobsAllSites++; } } SchedulerDecisions schedulerDecisions = new SchedulerDecisions(activeJobsAllSites); ArrayList<ActiveJob> prioritizedJobList = new ArrayList<ActiveJob>(activeJobsAllSites); for (ActiveJob activeJob : activeJobsAllSites) { if (!activeJob.schedulerStatus.isActive()) { schedulerDecisions.setInactive(activeJob); prioritizedJobList.remove(activeJob); continue; } if (!activeJob.schedulerStatus.isWaiting()) { schedulerDecisions.setAlreadyRunningOrQueued(activeJob); prioritizedJobList.remove(activeJob); continue; } } Collections.sort(prioritizedJobList,new Comparator<ActiveJob>(){ @Override public int compare(ActiveJob o1, ActiveJob o2) { UserQuotaInfo userQuotaInfo1 = userQuotaInfoMap.get(o1.simulationOwner); UserQuotaInfo userQuotaInfo2 = userQuotaInfoMap.get(o2.simulationOwner); if (userQuotaInfo1.getNumRunningJobs() != userQuotaInfo2.getNumRunningJobs()){ return Integer.compare(userQuotaInfo1.getNumRunningJobs(), userQuotaInfo2.getNumRunningJobs()); } if (o1.isPDE != o2.isPDE){ if (o1.isPDE){ return 1; }else{ return -1; } } return Long.compare(o1.submitTimestamp, o2.submitTimestamp); } }); int index=0; for (ActiveJob activeJob : prioritizedJobList) { schedulerDecisions.setOrdinal(activeJob, index); index++; } HashSet<User> users = new HashSet<User>(); users.addAll(userQuotaInfoMap.keySet()); for (User user : users){ UserQuotaInfo userQuotaInfo = userQuotaInfoMap.get(user); int numDesiredRunningPDEsAllSites = userQuotaInfo.numPdeRunningJobsAllSites; int numDesiredRunningODEsAllSites = userQuotaInfo.numOdeRunningJobsAllSites; Iterator<ActiveJob> prioritizedJobIter = prioritizedJobList.iterator(); while (prioritizedJobIter.hasNext()){ ActiveJob waitingJob = prioritizedJobIter.next(); if (waitingJob.simulationOwner.equals(user)){ if (waitingJob.isPDE){ if (numDesiredRunningPDEsAllSites < userQuotaPde){ numDesiredRunningPDEsAllSites++; }else{ schedulerDecisions.setHeldUserQuotaPDE(waitingJob); prioritizedJobIter.remove(); } }else{ if (numDesiredRunningODEsAllSites < userQuotaOde){ numDesiredRunningODEsAllSites++; }else{ schedulerDecisions.setHeldUserQuotaODE(waitingJob); prioritizedJobIter.remove(); } } } } } int inUseCPUs = partitionStatistics.numCpusAllocated; int cpusAvailable = Math.max(0, partitionStatistics.numCpusTotal - inUseCPUs); int numJobsSlotsAvailable = Math.max(0, cpusAvailable - numPendingJobsAllSites); for (int i=0;i<prioritizedJobList.size();i++) { ActiveJob nextWaitingJob = prioritizedJobList.get(i); if (i<numJobsSlotsAvailable) { if (nextWaitingJob.serverId.equals(systemID)){ schedulerDecisions.setRunnableThisSite(nextWaitingJob); }else { schedulerDecisions.setRunnableOtherSite(nextWaitingJob); } }else { schedulerDecisions.setHeldClusterResources(nextWaitingJob); } } schedulerDecisions.verify(partitionStatistics); return schedulerDecisions; } BatchScheduler(); static final int getMaxOdeJobsPerUser(); static final int getMaxPdeJobsPerUser(); static SchedulerDecisions schedule(List<ActiveJob> activeJobsAllSites, PartitionStatistics partitionStatistics, int userQuotaOde, int userQuotaPde, VCellServerID systemID);  }