-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci.m
204 lines (177 loc) · 5.67 KB
/
ci.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
function [meanST,Ddetail] = ci(data,nCPU,warmUp)
% CI Complete Information statistical data analyzer (SDA).
% This SDA is based on the method proposed in
% Pérez, J.F., Pacheco-Sanchez, S. and Casale, G.
% An Offline Demand Estimation Method for Multi-Threaded Applications.
% Proceedings of MASCOTS 2013, 2013
%
% D = CI(data,nCPU,warmUp) reads the data and configuration
% parameters from the input parameters, estimates the resource
% demand for each request class and returns it on D.
%
% Configuration file fields:
% data: the input data for the SDA
% nCPU: number of CPUs on which the application is deployed
% warmUp: initial number of samples to avoid when running the SDA
%
%
% Copyright (c) 2012-2013, Imperial College London
% All rights reserved.
% This code is released under the 3-Clause BSD License.
if exist('data','var') == 0
disp('No data provided specified. Terminating without running SDA.');
meanST = [];
obs = [];
return;
end
if exist('nCPU','var') ~= 0
V = nCPU;
else
disp('Number of CPUs not specified. Using default: 1.');
V = 1;
end
% SDA parameters
if exist('warmUp','var') == 0
disp('Warm-up period not specified. Using default: 0.');
warmUp = 0;
end
%other parameters
numExp = 1;
K = size(data,2) - 1;
Ddetail = cell(1,K);
sampleSize = size(data{4,1},1);
for j = 2:K
sampleSize = sampleSize + size(data{4,j},1);
end
if warmUp < sampleSize
sampleSize = sampleSize - warmUp;
else
disp('Warm-up period specified longer than samples available. Terminating without running SDA.');
meanST = [];
obs = [];
return;
end
for k = 1:K
times{k} = [data{3,k}/1000 data{4,k}];
end
%compute departure times
for k = 1:K
for i = 1:size(times{k},1)
times{k}(i,3) = times{k}(i,1) + times{k}(i,2);
end
end
%build array with all events
%first column: time
%second column: 0-arrival, 1-departure
%third column: class
%fourth column: arrival time (only for departures)
timesOrder = [];
for k = 1:K
if size(times{k},2) > 2
%arrivals
timesOrder = [timesOrder;
[times{k}(:,1) zeros(size(times{k},1),1) k*ones(size(times{k},1),1) zeros(size(times{k},1),1) ]
];
%departures
timesOrder = [timesOrder;
[times{k}(:,3) ones(size(times{k},1),1) k*ones(size(times{k},1),1) times{k}(:,1)]
];
end
end
%order events according to time of
timesOrder = sortrows(timesOrder,1);
%STATE
% each row corresponds to a current job
% first column: the class of the job
% second column: the arrival time
% third column: the elapsed service time
state = [];
% time keeping
t = 0;
told = t;
%ACUM
% number of service completions observed for each class (row)
% and total service time per class (second column)
acum = zeros(K,2);
obs = cell(1,K); %holds all the service times observed
%advance until it has observed a total of warmUp requests
i = 1;
while sum(acum(:,1)) < warmUp
t = timesOrder(i,1);
telapsed = t - told;
n = size(state,1);
% add to each job in process the service time elapsed (divided
% by the portion of the server actually dedicated to it in a PS server
r = n;
for j = 1:r
state(j,3) = state(j,3) + telapsed/r;
end
%if the event is an arrival add the job to teh state
if timesOrder(i,2) == 0
state = [state; [timesOrder(i,3) t 0] ];
else
%find job in progress that must leave
k = 1; while state(k,2) ~= timesOrder(i,4); k = k+1; end
%update stats
acum(state(k,1),1) = acum(state(k,1),1) + 1;
acum(state(k,1),2) = acum(state(k,1),2) + state(k,3);
%update state
state = [state(1:k-1,:); state(k+1:end,:)];
end
i = i + 1;
told = t;
end
state_detail = [];
meanST = zeros(K,numExp);
for e = 1:numExp
%actually sampled data
acum = zeros(K,2);
obs = cell(1,K); %holds all the service times observed
while sum(acum(:,1)) < sampleSize %size(timesOrder,1)
t = timesOrder(i,1);
telapsed = t - told;
n = size(state,1);
% add to each job in process the service time elapsed (divided
% by the portion of the server actually dedicated to it in a PS server
%r = min(n,W);
r = n;
for j = 1:r
if length(state(j,:)) <5
state(j,4) = 0;
%state(j,5) = 0;
end
if r <= V %at most as many jobs in service as processors
state(j,3) = state(j,3) + telapsed;
state(j,4) = state(j,4) + telapsed*r;
else %more jobs in service than processors
state(j,3) = state(j,3) + telapsed*V/r;
state(j,4) = state(j,4) + telapsed*V/r*r;
end
end
%if the event is an arrival add the job to the state
if timesOrder(i,2) == 0
state = [state; [timesOrder(i,3) t 0 0 0] ];
else
%find job in progress that must leave
k = 1; while state(k,2) ~= timesOrder(i,4); k = k+1; end
%update stats
acum(state(k,1),1) = acum(state(k,1),1) + 1;
acum(state(k,1),2) = acum(state(k,1),2) + state(k,3);
obs{state(k,1)} = [obs{state(k,1)}; state(k,3)];
%update state
temp = state(k,:);
temp(4) = temp(4)/temp(3);
if temp(3) ~= 0
state_detail = [state_detail; temp];
end
state = [state(1:k-1,:); state(k+1:end,:)];
end
i = i+1;
told = t;
end
meanST(:,e) = acum(:,2)./acum(:,1);
end
for i = 1:size(state_detail,1)
Ddetail{1,state_detail(i,1)} = [Ddetail{1,state_detail(i,1)};state_detail(i,2:4)];
end
%save(output_filename, 'meanST', '-ascii');