return totalAggregationTime.get();
}
public Set<AggregateNumericMetric> run() {
log.info("Starting metrics data aggregation");
Stopwatch stopwatch = Stopwatch.createStarted();
Semaphore permits = new Semaphore(batchSize * parallelism);
log.debug("Allocating " + permits.availablePermits() + " permits");
int num1Hour = 0;
int num6Hour = 0;
int num24Hour = 0;
try {
PersistFunctions persistFunctions = new PersistFunctions(dao, dtService);
final Set<AggregateNumericMetric> oneHourData = new ConcurrentSkipListSet<AggregateNumericMetric>(
AGGREGATE_COMPARATOR);
DateTime endTime = dtService.currentHour();
DateTime end = endTime;
// We set the start time to the retention period minus 1 hour, or 6 days and 23
// hours ago instead of 7 days ago because if we set the start time to the full
// 7 days, then we could end up in a situation where data has expired and
// aggregate metric get overwritten with partial data.
DateTime start = end.minus(configuration.getRawRetention().toPeriod().minusHours(1));
DataAggregator rawAggregator = createRawAggregator(persistFunctions, permits);
rawAggregator.setBatchFinishedListener(new DataAggregator.BatchFinishedListener() {
@Override
public void onFinish(List<AggregateNumericMetric> metrics) {
oneHourData.addAll(metrics);
}
});
num1Hour = rawAggregator.execute(start, end);
end = dtService.get6HourTimeSlice(endTime);
start = dtService.get6HourTimeSlice(endTime).minus(configuration.getRawRetention());
num6Hour = create1HourAggregator(persistFunctions, permits).execute(start, end);
end = dtService.get24HourTimeSlice(endTime);
start = dtService.get24HourTimeSlice(endTime).minus(configuration.getRawRetention());
num24Hour = create6HourAggregator(persistFunctions, permits).execute(start, end);
return oneHourData;
} catch (InterruptedException e) {
log.info("There was an interrupt while waiting for aggregation to finish. Aggregation will be aborted.");
return Collections.emptySet();
}
catch (AbortedException e) {
log.warn("Aggregation has been aborted: " + e.getMessage());
return Collections.emptySet();
} finally {
stopwatch.stop();
totalAggregationTime.addAndGet(stopwatch.elapsed(TimeUnit.MILLISECONDS));
log.info("Finished aggregation of {\"raw schedules\": " + num1Hour + ", \"1 hour schedules\": " + num6Hour +
", \"6 hour schedules\": " + num24Hour + "} in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms");
}
}