Load Balancing
Posted: Thu Oct 30, 2008 12:14 am
Hi,
We are using a LoadBalancing routine to run "N" jobs in parallel from a given list of jobs. Given below is the code snippet for the same.
The code below achieves the following functionality :- It starts N jobs in parallel but only after all the N jobs finish execution it takes the next set of "N" jobs to run.
We want to modify the code such that as soon as one among the "N" job finished execution we want to start the next job in sequence.
Please let us know how can this be achieved by modifying the existing code given below.
Thanks,
* Array holding the jobs to run.
DIM SubFileRunListArray(30)
MAT SubFileRunListArray=0
DIM JobHandleArray(ParallelJobsToRun)
MAT JobHandleArray=0
* Setup to run "N" parallel jobs
Loop Until SubFileRunListArray(i) = 0
For j=1 To ParallelJobsToRun Step 1
If JobHandleArray(j)=0
Then
vJobName=SubFileRunListArray(i)
JobHandleArray(j) = DSAttachJob(vJobName, DSJ.ERRNONE)
JobHandleArray(j) = DSPrepareJob(JobHandleArray(j))
If NOT(JobHandleArray(j)) Then
Call DSLogWarn("Job Attach Failed: " : vJobName, "LoadBalancing")
End
ErrCode = DSRunJob(JobHandleArray(j), DSJ.RUNNORMAL)
i=i+1
end
NEXT j
* Check if any of the jobs started above is finished. In that case make that jobs handle as null. Then start the next jobs in seq.
For k=1 To ParallelJobsToRun Step 1
JobCurrStatus=DSGetJobInfo(JobHandleArray(k),DSJ.JOBSTATUS)
JobName=DSGetJobInfo(JobHandleArray(k),DSJ.JOBNAME)
If JobCurrStatus=DSJS.RUNNING
Then
Call DSLogInfo("Running ":JobName, "LoadBalancing")
ErrCode=DSWaitForJob(JobHandleArray(k))
JobHandleArray(k)=0
End
If JobCurrStatus=DSJS.RUNFAILED Or JobCurrStatus=DSJS.CRASHED
Then
Call DSLogWarn("Aborted ":JobName, "LoadBalancing")
JobHandleArray(k)=0
End
If JobCurrStatus=DSJS.RUNOK Or JobCurrStatus=DSJS.RUNWARN
Then
Call DSLogInfo ("Finished ":JobName, "LoadBalancing")
JobHandleArray(k)=0
End
Next k
LeftJobs = ctrJobsToRun - i
If LeftJobs < ParallelJobsToRun
Then
ParallelJobsToRun = LeftJobs +1
End
Repeat
We are using a LoadBalancing routine to run "N" jobs in parallel from a given list of jobs. Given below is the code snippet for the same.
The code below achieves the following functionality :- It starts N jobs in parallel but only after all the N jobs finish execution it takes the next set of "N" jobs to run.
We want to modify the code such that as soon as one among the "N" job finished execution we want to start the next job in sequence.
Please let us know how can this be achieved by modifying the existing code given below.
Thanks,
* Array holding the jobs to run.
DIM SubFileRunListArray(30)
MAT SubFileRunListArray=0
DIM JobHandleArray(ParallelJobsToRun)
MAT JobHandleArray=0
* Setup to run "N" parallel jobs
Loop Until SubFileRunListArray(i) = 0
For j=1 To ParallelJobsToRun Step 1
If JobHandleArray(j)=0
Then
vJobName=SubFileRunListArray(i)
JobHandleArray(j) = DSAttachJob(vJobName, DSJ.ERRNONE)
JobHandleArray(j) = DSPrepareJob(JobHandleArray(j))
If NOT(JobHandleArray(j)) Then
Call DSLogWarn("Job Attach Failed: " : vJobName, "LoadBalancing")
End
ErrCode = DSRunJob(JobHandleArray(j), DSJ.RUNNORMAL)
i=i+1
end
NEXT j
* Check if any of the jobs started above is finished. In that case make that jobs handle as null. Then start the next jobs in seq.
For k=1 To ParallelJobsToRun Step 1
JobCurrStatus=DSGetJobInfo(JobHandleArray(k),DSJ.JOBSTATUS)
JobName=DSGetJobInfo(JobHandleArray(k),DSJ.JOBNAME)
If JobCurrStatus=DSJS.RUNNING
Then
Call DSLogInfo("Running ":JobName, "LoadBalancing")
ErrCode=DSWaitForJob(JobHandleArray(k))
JobHandleArray(k)=0
End
If JobCurrStatus=DSJS.RUNFAILED Or JobCurrStatus=DSJS.CRASHED
Then
Call DSLogWarn("Aborted ":JobName, "LoadBalancing")
JobHandleArray(k)=0
End
If JobCurrStatus=DSJS.RUNOK Or JobCurrStatus=DSJS.RUNWARN
Then
Call DSLogInfo ("Finished ":JobName, "LoadBalancing")
JobHandleArray(k)=0
End
Next k
LeftJobs = ctrJobsToRun - i
If LeftJobs < ParallelJobsToRun
Then
ParallelJobsToRun = LeftJobs +1
End
Repeat