Source:
public Map<MetricQuery, List<MetricScanner>> getMetricScanners(List<MetricQuery> queries) { requireNotDisposed(); requireArgument(queries != null, "Metric Queries cannot be null."); _logger.trace("Active Threads in the pool = " + ((ThreadPoolExecutor) _executorService).getActiveCount()); double percentage = 0.05; long start = System.currentTimeMillis(); Map<MetricQuery, List<MetricScanner>> scannerMap = new HashMap<>(); for (MetricQuery query : queries) { Long chunkTime = (Long) Math.round((query.getEndTimestamp() - query.getStartTimestamp()) * percentage); int additionalChunks = -1; scannerMap.put(query, new ArrayList<>()); Map<MetricQuery, List<Metric>> metricMap; MetricQuery miniQuery; Long startTime; Long stopTime; do { additionalChunks++; startTime = query.getStartTimestamp() + chunkTime * additionalChunks; stopTime = Math.max(query.getEndTimestamp(), startTime + chunkTime); miniQuery = new MetricQuery(query.getScope(), query.getMetric(), query.getTags(), startTime, stopTime); List<MetricQuery> miniQueries = new ArrayList<>(); miniQueries.add(miniQuery); metricMap = getMetrics(miniQueries); } while (!metricMap.containsKey(miniQuery) && (startTime + chunkTime) < query.getEndTimestamp()); if (!metricMap.containsKey(miniQuery)) {scannerMap.put(miniQuery, new ArrayList<>()); continue;} List<Metric> miniMetrics = metricMap.get(miniQuery); for (Metric miniMetric : miniMetrics) { MetricScanner scanner = new MetricScanner(miniMetric, query, this, stopTime); scannerMap.get(query).add(scanner); } } _logger.debug("Time to get Scanners = " + (System.currentTimeMillis() - start)); return scannerMap; }

Target:
public Map<MetricQuery, List<MetricScanner>> getMetricScanners(List<MetricQuery> queries) { requireNotDisposed(); requireArgument(queries != null, "Metric Queries cannot be null."); _logger.trace("Active Threads in the pool = " + ((ThreadPoolExecutor) _executorService).getActiveCount()); double percentage = 0.05; long start = System.currentTimeMillis(); Map<MetricQuery, List<MetricScanner>> scannerMap = new HashMap<>(); for (MetricQuery query : queries) { Long chunkTime = (Long) Math.round((query.getEndTimestamp() - query.getStartTimestamp()) * percentage); int additionalChunks = -1; scannerMap.put(query, new ArrayList<>()); Map<MetricQuery, List<Metric>> metricMap; MetricQuery miniQuery; Long startTime; Long stopTime; do { additionalChunks++; startTime = query.getStartTimestamp() + chunkTime * additionalChunks; stopTime = Math.min(query.getEndTimestamp(), startTime + chunkTime); miniQuery = new MetricQuery(query.getScope(), query.getMetric(), query.getTags(), startTime, stopTime); List<MetricQuery> miniQueries = new ArrayList<>(); miniQueries.add(miniQuery); metricMap = getMetrics(miniQueries); } while (!metricMap.containsKey(miniQuery) && (startTime + chunkTime) < query.getEndTimestamp()); if (!metricMap.containsKey(miniQuery)) {scannerMap.put(miniQuery, new ArrayList<>()); continue;} List<Metric> miniMetrics = metricMap.get(miniQuery); for (Metric miniMetric : miniMetrics) { MetricScanner scanner = new MetricScanner(miniMetric, query, this, stopTime); scannerMap.get(query).add(scanner); } } _logger.debug("Time to get Scanners = " + (System.currentTimeMillis() - start)); return scannerMap; }