1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.giraph.ooc; |
20 | |
|
21 | |
import com.google.common.collect.Maps; |
22 | |
import org.apache.giraph.conf.GiraphConstants; |
23 | |
import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration; |
24 | |
import org.apache.giraph.conf.IntConfOption; |
25 | |
import org.apache.giraph.ooc.command.IOCommand.IOCommandType; |
26 | |
import org.apache.log4j.Logger; |
27 | |
|
28 | |
import java.util.Map; |
29 | |
import java.util.Queue; |
30 | |
import java.util.concurrent.ArrayBlockingQueue; |
31 | |
import java.util.concurrent.atomic.AtomicLong; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class OutOfCoreIOStatistics { |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | public static final IntConfOption DISK_BANDWIDTH_ESTIMATE = |
44 | |
new IntConfOption("giraph.diskBandwidthEstimate", 125, |
45 | |
"An estimate of disk bandwidth (MB/s). This number is used just at " + |
46 | |
"the beginning of the computation, and it will be " + |
47 | |
"updated/replaced once a few disk operations happen."); |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | 0 | public static final IntConfOption IO_COMMAND_HISTORY_SIZE = |
53 | |
new IntConfOption("giraph.ioCommandHistorySize", 50, |
54 | |
"Number of most recent IO operations to consider for reporting the" + |
55 | |
"statistics."); |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | 0 | public static final IntConfOption STATS_PRINT_FREQUENCY = |
61 | |
new IntConfOption("giraph.oocStatPrintFrequency", 200, |
62 | |
"Number of updates before stats are printed."); |
63 | |
|
64 | |
|
65 | 0 | private static final Logger LOG = |
66 | 0 | Logger.getLogger(OutOfCoreIOStatistics.class); |
67 | |
|
68 | |
private final AtomicLong diskBandwidthEstimate; |
69 | |
|
70 | |
private final int maxHistorySize; |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
private final double updateCoefficient; |
79 | |
|
80 | |
private final Queue<StatisticsEntry> commandHistory; |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
private final Map<IOCommandType, StatisticsEntry> aggregateStats; |
87 | |
|
88 | 0 | private int numUpdates = 0; |
89 | |
|
90 | 0 | private int statsPrintFrequency = 0; |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
public OutOfCoreIOStatistics(ImmutableClassesGiraphConfiguration conf, |
99 | 0 | int numIOThreads) { |
100 | 0 | this.diskBandwidthEstimate = |
101 | 0 | new AtomicLong(DISK_BANDWIDTH_ESTIMATE.get(conf) * |
102 | |
(long) GiraphConstants.ONE_MB); |
103 | 0 | this.maxHistorySize = IO_COMMAND_HISTORY_SIZE.get(conf); |
104 | 0 | this.updateCoefficient = 1.0 / maxHistorySize; |
105 | |
|
106 | |
|
107 | 0 | this.commandHistory = |
108 | |
new ArrayBlockingQueue<>(maxHistorySize + numIOThreads); |
109 | 0 | this.aggregateStats = Maps.newConcurrentMap(); |
110 | 0 | for (IOCommandType type : IOCommandType.values()) { |
111 | 0 | aggregateStats.put(type, new StatisticsEntry(type, 0, 0, 0)); |
112 | |
} |
113 | 0 | this.statsPrintFrequency = STATS_PRINT_FREQUENCY.get(conf); |
114 | 0 | } |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
public void update(IOCommandType type, long bytesTransferred, |
125 | |
long duration) { |
126 | 0 | StatisticsEntry entry = aggregateStats.get(type); |
127 | 0 | synchronized (entry) { |
128 | 0 | entry.setOccurrence(entry.getOccurrence() + 1); |
129 | 0 | entry.setDuration(duration + entry.getDuration()); |
130 | 0 | entry.setBytesTransferred(bytesTransferred + entry.getBytesTransferred()); |
131 | 0 | } |
132 | 0 | commandHistory.offer( |
133 | |
new StatisticsEntry(type, bytesTransferred, duration, 0)); |
134 | 0 | if (type != IOCommandType.WAIT) { |
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | 0 | diskBandwidthEstimate.set((long) |
143 | |
(updateCoefficient * (bytesTransferred / duration * 1000) + |
144 | 0 | (1 - updateCoefficient) * diskBandwidthEstimate.get())); |
145 | |
} |
146 | 0 | if (commandHistory.size() > maxHistorySize) { |
147 | 0 | StatisticsEntry removedEntry = commandHistory.poll(); |
148 | 0 | entry = aggregateStats.get(removedEntry.getType()); |
149 | 0 | synchronized (entry) { |
150 | 0 | entry.setOccurrence(entry.getOccurrence() - 1); |
151 | 0 | entry.setDuration(entry.getDuration() - removedEntry.getDuration()); |
152 | 0 | entry.setBytesTransferred( |
153 | 0 | entry.getBytesTransferred() - removedEntry.getBytesTransferred()); |
154 | 0 | } |
155 | |
} |
156 | 0 | numUpdates++; |
157 | |
|
158 | 0 | if (numUpdates % statsPrintFrequency == 0) { |
159 | 0 | if (LOG.isInfoEnabled()) { |
160 | 0 | LOG.info(this); |
161 | |
} |
162 | |
} |
163 | 0 | } |
164 | |
|
165 | |
@Override |
166 | |
public String toString() { |
167 | 0 | StringBuffer sb = new StringBuffer(); |
168 | 0 | long waitTime = 0; |
169 | 0 | long loadTime = 0; |
170 | 0 | long bytesRead = 0; |
171 | 0 | long storeTime = 0; |
172 | 0 | long bytesWritten = 0; |
173 | |
for (Map.Entry<IOCommandType, StatisticsEntry> entry : |
174 | 0 | aggregateStats.entrySet()) { |
175 | 0 | synchronized (entry.getValue()) { |
176 | 0 | sb.append(entry.getKey() + ": " + entry.getValue() + ", "); |
177 | 0 | if (entry.getKey() == IOCommandType.WAIT) { |
178 | 0 | waitTime += entry.getValue().getDuration(); |
179 | 0 | } else if (entry.getKey() == IOCommandType.LOAD_PARTITION) { |
180 | 0 | loadTime += entry.getValue().getDuration(); |
181 | 0 | bytesRead += entry.getValue().getBytesTransferred(); |
182 | |
} else { |
183 | 0 | storeTime += entry.getValue().getDuration(); |
184 | 0 | bytesWritten += entry.getValue().getBytesTransferred(); |
185 | |
} |
186 | 0 | } |
187 | 0 | } |
188 | 0 | sb.append(String.format("Average STORE: %.2f MB/s, ", |
189 | 0 | (double) bytesWritten / storeTime * 1000 / 1024 / 1024)); |
190 | 0 | sb.append(String.format("DATA_INJECTION: %.2f MB/s, ", |
191 | 0 | (double) (bytesRead - bytesWritten) / |
192 | |
(waitTime + loadTime + storeTime) * 1000 / 1024 / 1024)); |
193 | 0 | sb.append(String.format("DISK_BANDWIDTH: %.2f MB/s", |
194 | 0 | (double) diskBandwidthEstimate.get() / 1024 / 1024)); |
195 | |
|
196 | 0 | return sb.toString(); |
197 | |
} |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
public long getDiskBandwidth() { |
203 | 0 | return diskBandwidthEstimate.get(); |
204 | |
} |
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
public BytesDuration getCommandTypeStats(IOCommandType type) { |
213 | 0 | StatisticsEntry entry = aggregateStats.get(type); |
214 | 0 | synchronized (entry) { |
215 | 0 | return new BytesDuration(entry.getBytesTransferred(), entry.getDuration(), |
216 | 0 | entry.getOccurrence()); |
217 | 0 | } |
218 | |
} |
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
public static class BytesDuration { |
225 | |
|
226 | |
private long bytes; |
227 | |
|
228 | |
private long duration; |
229 | |
|
230 | |
private int occurrence; |
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | 0 | BytesDuration(long bytes, long duration, int occurrence) { |
239 | 0 | this.bytes = bytes; |
240 | 0 | this.duration = duration; |
241 | 0 | this.occurrence = occurrence; |
242 | 0 | } |
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
public long getBytes() { |
248 | 0 | return bytes; |
249 | |
} |
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
public long getDuration() { |
255 | 0 | return duration; |
256 | |
} |
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | |
public int getOccurrence() { |
262 | 0 | return occurrence; |
263 | |
} |
264 | |
} |
265 | |
|
266 | |
|
267 | |
|
268 | |
|
269 | |
private static class StatisticsEntry { |
270 | |
|
271 | |
private IOCommandType type; |
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | |
private long bytesTransferred; |
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
private long duration; |
282 | |
|
283 | |
|
284 | |
|
285 | |
|
286 | |
private int occurrence; |
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | |
|
296 | |
public StatisticsEntry(IOCommandType type, long bytesTransferred, |
297 | 0 | long duration, int occurrence) { |
298 | 0 | this.type = type; |
299 | 0 | this.bytesTransferred = bytesTransferred; |
300 | 0 | this.duration = duration; |
301 | 0 | this.occurrence = occurrence; |
302 | 0 | } |
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | |
public IOCommandType getType() { |
308 | 0 | return type; |
309 | |
} |
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
public long getBytesTransferred() { |
316 | 0 | return bytesTransferred; |
317 | |
} |
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
public void setBytesTransferred(long bytesTransferred) { |
325 | 0 | this.bytesTransferred = bytesTransferred; |
326 | 0 | } |
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
public long getDuration() { |
332 | 0 | return duration; |
333 | |
} |
334 | |
|
335 | |
|
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
public void setDuration(long duration) { |
341 | 0 | this.duration = duration; |
342 | 0 | } |
343 | |
|
344 | |
|
345 | |
|
346 | |
|
347 | |
public int getOccurrence() { |
348 | 0 | return occurrence; |
349 | |
} |
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
public void setOccurrence(int occurrence) { |
357 | 0 | this.occurrence = occurrence; |
358 | 0 | } |
359 | |
|
360 | |
@Override |
361 | |
public String toString() { |
362 | 0 | if (type == IOCommandType.WAIT) { |
363 | 0 | return String.format("%.2f sec", duration / 1000.0); |
364 | |
} else { |
365 | 0 | return String.format("%.2f MB/s", |
366 | 0 | (double) bytesTransferred / duration * 1000 / 1024 / 2014); |
367 | |
} |
368 | |
} |
369 | |
} |
370 | |
} |