Code covered by the BSD License  

Highlights from
Job Estimator

image thumbnail

Job Estimator

by

 

21 Nov 2006 (Updated )

Estimates how long a job will take on a comput cluster of various sizes

plotTasks( job, figHandle)
function varargout = plotTasks( job, figHandle)

if nargin == 1;
    figHandle = gcf;
end

% prepare progress bar
wb = waitbar( 0, 'Finding job manager...' );


% check it has finished
if ~strcmp( job.State, 'finished' )
    delete( wb );
    error('Job has not finished');
else
    waitbar( 0.2, wb, 'Getting list of workers' );
end

% get list of workers used for this job
tasks = job.Tasks;
nTasks = numel( tasks );
workerForTask = cell( nTasks, 1 );
for i = 1:nTasks,
    %waitbar( 0.2 + 0.2*i/nTasks, wb );
    workerForTask{i} = tasks(i).Worker.Name;
end
workers = unique(workerForTask);
nWorkers = numel(workers);

% Get start and end time for job
jobStart  = iConvertJavaDateStringToAbsoluteTime(job.StartTime);
jobFinish = iConvertJavaDateStringToAbsoluteTime(job.FinishTime);
jobLength = (jobFinish - jobStart) * 24 * 3600;
% for each task, get start and end times
taskStart  = zeros(nTasks, 1);
taskFinish = zeros(nTasks, 1);
% For each task which worker did it appear on
taskWorkerIndex = zeros(nTasks, 1);
% For each worker what is the last time a task finished
workerFinish = zeros(nWorkers, 1);
% Define a useage matrix which indicates (on a second by second basis) if a given
% worker is active or not - NOTE the +1 because time is zero-based and matlab
% arrays are one based
useage = false(nWorkers, ceil(jobLength)+1);
for i = 1:nTasks,

    %waitbar( 0.4 + 0.3*i/nTasks, wb, sprintf( 'Examining task %i', i ) );
          
    % Convert to relative time in integer seconds
    thisStart  = round((iConvertJavaDateStringToAbsoluteTime(tasks(i).StartTime)  - jobStart) * 24 * 3600);
    thisFinish = round((iConvertJavaDateStringToAbsoluteTime(tasks(i).FinishTime) - jobStart) * 24 * 3600);
    % Get the worker index for this task
    thisIndex  = find( strcmp( workers, workerForTask{i} ) );    
    % Update the useage matrix with true for this tasks time and worker - note that a 
    % task that runs from 1 sec to 2 sec should only put true in one element of the array
    % hence we increment the start index but NOT the finish index.
    useage(thisIndex, (thisStart+1):thisFinish) = true;
    % Update the workerFinish time for this worker.
    workerFinish(thisIndex) = max(workerFinish(thisIndex), thisFinish);
    % Copy into storage arrays
    taskStart(i)  = thisStart;
    taskFinish(i) = thisFinish;
    taskWorkerIndex(i) = thisIndex;
end

activeWorkerByTime = sum(useage, 1);
timeActiveByWorker = sum(useage, 2);
workerUtilization = timeActiveByWorker./workerFinish;


waitbar( 0.7, wb, 'Creating figure' );
% set up figure
figure1 = figure(1);
clf
axes1 = axes('Position',[0.15 0.40 0.65 0.50],'Parent',figure1);      
box('on')
axes2 = axes('Position',[0.85 0.40 0.05 0.50],'Parent',figure1); 
box('on');
axes3 = axes('Position',[0.15 0.10 0.65 0.20],'Parent',figure1);
box('on');
% axes4 = axes('Position',[0.85 0.10 0.05 0.20],'Parent',figure1);
% box('on');

myColorSet = hot(100);

for i = 1:nTasks,
    myColorIndex = ceil(rand*80);
    myColor = myColorSet(myColorIndex,:);
    line([taskStart(i) taskFinish(i)], ...
         [taskWorkerIndex(i) taskWorkerIndex(i)], ...
         'lineWidth', 4, ...
         'marker'   , '*', ...
         'parent', axes1, ...
         'color',  myColor);
    
end

axis(axes1, [0, jobLength, ...
             0, nWorkers + 1])
title (axes1, 'Timeline of task starts and ends')
ylabel(axes1, 'Worker Number')
%xlabel(axes1, 'Time')

bar(axes3, activeWorkerByTime)
axis(axes3, [0, jobLength, ...
             0, nWorkers])
ylabel(axes3, '# working')
xlabel(axes3, 'Time')
wallTime = max(workerFinish);
cpuTime = sum(useage(:));
%title(axes3, ['Wall time ' num2str(wallTime) ' sec is ' ...
%              num2str(round(100 * wallTime/cpuTime)) '% of '...
%              'CPU time ' num2str(cpuTime) ' sec. Ideal is ' ...
%              num2str(round(cpuTime / nWorkers)) ' sec.'])

barh(axes2, workerUtilization*100);
title(axes2, '% time working')
axis(axes2,[max(min(workerUtilization)*100-5, 0) 100, 0, nWorkers + 1])
xTicks      = get(axes2, 'xTick');

set(axes2, 'xTick'     , [xTicks(1) xTicks(end)])

%ylabel(axes2, 'Worker Number')
%xlabel(axes2, 'Efficiency')

% hist(axes4, workerUtilization)
% title (axes4, 'Histogram')
% xlabel(axes4, 'Efficiency')
% ylabel(axes4, '# of workers')
% waitbar( 1, wb, 'Finishing plot' );


% delete waitbar
delete( wb );

% perhaps return handle to the figure
if nargout > 0
    varargout{1} = f;
end

% -----------------------------------------------------------------------
%
% -----------------------------------------------------------------------
function a = iConvertJavaDateStringToAbsoluteTime(str)
a = datenum(str(4:end), 'mmm dd hh:MM:ss zzz yyyy');
% Copyright 2007 - 2009 The MathWorks, Inc.

Contact us