use of org.apache.drill.shaded.guava.com.google.common.base.Stopwatch in project drill by apache.
the class ClassPathScanner method scan.
/**
* @param pathsToScan the locations to scan for .class files
* @param packagePrefixes the whitelist of package prefixes to scan
* @param parentResult if there was a prescan, its result
* @return the merged scan
*/
static ScanResult scan(Collection<URL> pathsToScan, Collection<String> packagePrefixes, Collection<String> scannedClasses, Collection<String> scannedAnnotations, ScanResult parentResult) {
Stopwatch watch = Stopwatch.createStarted();
try {
AnnotationScanner annotationScanner = new AnnotationScanner(scannedAnnotations);
SubTypesScanner subTypesScanner = new SubTypesScanner(parentResult.getImplementations());
if (packagePrefixes.size() > 0) {
final FilterBuilder filter = new FilterBuilder();
for (String prefix : packagePrefixes) {
filter.include(FilterBuilder.prefix(prefix));
}
ConfigurationBuilder conf = new ConfigurationBuilder().setUrls(pathsToScan).setMetadataAdapter(// Scanners depend on this
METADATA_ADAPTER).filterInputsBy(filter).setScanners(annotationScanner, subTypesScanner);
// scans stuff, but don't use the funky storage layer
new Reflections(conf);
}
List<ParentClassDescriptor> implementations = new ArrayList<>();
for (String baseTypeName : scannedClasses) {
implementations.add(new ParentClassDescriptor(baseTypeName, new ArrayList<>(subTypesScanner.getChildrenOf(baseTypeName))));
}
List<AnnotatedClassDescriptor> annotated = annotationScanner.getAnnotatedClasses();
verifyClassUnicity(annotated, pathsToScan);
return new ScanResult(packagePrefixes, scannedClasses, scannedAnnotations, annotated, implementations);
} finally {
logger.info(format("Scanning packages %s in locations %s took %dms", packagePrefixes, pathsToScan, watch.elapsed(MILLISECONDS)));
}
}
use of org.apache.drill.shaded.guava.com.google.common.base.Stopwatch in project drill by apache.
the class DirectBufInputStream method read.
public synchronized int read(DrillBuf buf, int off, int len) throws IOException {
buf.clear();
ByteBuffer directBuffer = buf.nioBuffer(0, len);
int lengthLeftToRead = len;
SeekableInputStream seekableInputStream = HadoopStreams.wrap(getInputStream());
while (lengthLeftToRead > 0) {
if (logger.isTraceEnabled()) {
logger.trace("PERF: Disk read start. {}, StartOffset: {}, TotalByteSize: {}", this.streamId, this.startOffset, this.totalByteSize);
}
Stopwatch timer = Stopwatch.createStarted();
int bytesRead = seekableInputStream.read(directBuffer);
if (bytesRead < 0) {
return bytesRead;
}
lengthLeftToRead -= bytesRead;
if (logger.isTraceEnabled()) {
logger.trace("PERF: Disk read complete. {}, StartOffset: {}, TotalByteSize: {}, BytesRead: {}, Time: {} ms", this.streamId, this.startOffset, this.totalByteSize, bytesRead, ((double) timer.elapsed(TimeUnit.MICROSECONDS)) / 1000);
}
}
buf.writerIndex(len);
return len;
}
use of org.apache.drill.shaded.guava.com.google.common.base.Stopwatch in project drill by apache.
the class AffinityCreator method getAffinityMap.
public static <T extends CompleteWork> List<EndpointAffinity> getAffinityMap(List<T> work) {
Stopwatch watch = logger.isDebugEnabled() ? Stopwatch.createStarted() : null;
long totalBytes = work.stream().mapToLong(CompleteWork::getTotalBytes).sum();
ObjectFloatHashMap<DrillbitEndpoint> affinities = new ObjectFloatHashMap<>();
for (CompleteWork entry : work) {
for (ObjectLongCursor<DrillbitEndpoint> cursor : entry.getByteMap()) {
long bytes = cursor.value;
float affinity = totalBytes == 0 ? 0.0F : (float) bytes / (float) totalBytes;
affinities.putOrAdd(cursor.key, affinity, affinity);
}
}
List<EndpointAffinity> affinityList = new LinkedList<>();
for (ObjectFloatCursor<DrillbitEndpoint> d : affinities) {
logger.debug("Endpoint {} has affinity {}", d.key.getAddress(), d.value);
affinityList.add(new EndpointAffinity(d.key, d.value));
}
if (watch != null) {
logger.debug("Took {} ms to get operator affinity", watch.elapsed(TimeUnit.MILLISECONDS));
}
return affinityList;
}
use of org.apache.drill.shaded.guava.com.google.common.base.Stopwatch in project drill by apache.
the class BlockMapBuilder method getEndpointByteMap.
/**
* For a given FileWork, calculate how many bytes are available on each on drillbit endpoint
*
* @param work the FileWork to calculate endpoint bytes for
* @throws IOException
*/
public EndpointByteMap getEndpointByteMap(Set<String> noDrillbitHosts, FileWork work) throws IOException {
Stopwatch watch = Stopwatch.createStarted();
Path fileName = work.getPath();
ImmutableRangeMap<Long, BlockLocation> blockMap = getBlockMap(fileName);
EndpointByteMapImpl endpointByteMap = new EndpointByteMapImpl();
long start = work.getStart();
long end = start + work.getLength();
Range<Long> rowGroupRange = Range.closedOpen(start, end);
// Find submap of ranges that intersect with the rowGroup
ImmutableRangeMap<Long, BlockLocation> subRangeMap = blockMap.subRangeMap(rowGroupRange);
// Iterate through each block in this submap and get the host for the block location
for (Map.Entry<Range<Long>, BlockLocation> block : subRangeMap.asMapOfRanges().entrySet()) {
String[] hosts;
Range<Long> blockRange = block.getKey();
try {
hosts = block.getValue().getHosts();
} catch (IOException ioe) {
throw new RuntimeException("Failed to get hosts for block location", ioe);
}
Range<Long> intersection = rowGroupRange.intersection(blockRange);
long bytes = intersection.upperEndpoint() - intersection.lowerEndpoint();
// For each host in the current block location, add the intersecting bytes to the corresponding endpoint
for (String host : hosts) {
DrillbitEndpoint endpoint = getDrillBitEndpoint(host);
if (endpoint != null) {
endpointByteMap.add(endpoint, bytes);
} else if (noDrillbitHosts != null) {
noDrillbitHosts.add(host);
}
}
}
logger.debug("FileWork group ({},{}) max bytes {}", work.getPath(), work.getStart(), endpointByteMap.getMaxBytes());
logger.debug("Took {} ms to set endpoint bytes", watch.stop().elapsed(TimeUnit.MILLISECONDS));
return endpointByteMap;
}
use of org.apache.drill.shaded.guava.com.google.common.base.Stopwatch in project drill by apache.
the class TestParquetPhysicalPlan method testParseParquetPhysicalPlanRemote.
@Test
@Ignore
public void testParseParquetPhysicalPlanRemote() throws Exception {
DrillConfig config = DrillConfig.create();
try (DrillClient client = new DrillClient(config)) {
client.connect();
ParquetResultsListener listener = new ParquetResultsListener();
Stopwatch watch = Stopwatch.createStarted();
client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Resources.toString(Resources.getResource(fileName), Charsets.UTF_8), listener);
client.close();
}
}
Aggregations