static int getSplitRatio(int nMaps, int nRecords, Configuration conf) { int maxChunksIdeal = getMaxChunksIdeal(conf); int minRecordsPerChunk = getMinRecordsPerChunk(conf); int splitRatio = getSplitRatio(conf);
if (nMaps == 1) { LOG.warn("nMaps == 1. Why use DynamicInputFormat?"); return 1; }
if (nMaps > maxChunksIdeal) return splitRatio;
int nPickups = (int)Math.ceil((float)maxChunksIdeal/nMaps); int nRecordsPerChunk = (int)Math.ceil((float)nRecords/(nMaps*nPickups));
/** * Read bytes starting from the specified position. This requires rawStream is * an instance of {@link PositionedReadable}. */ public int read(long position, byte[] buffer, int offset, int length) throws IOException { if (!(rawStream instanceof PositionedReadable)) { throw new UnsupportedOperationException( "positioned read is not supported by the internal stream"); } throttle(); int readLen = ((PositionedReadable) rawStream).read(position, buffer, offset, length); if (readLen != -1) { bytesRead += readLen; } return readLen; }
/** * Getter for the read-rate from this stream, since creation. * Calculated as bytesRead/elapsedTimeSinceStart. * @return Read rate, in bytes/sec. */ public long getBytesPerSec() { long elapsed = (System.currentTimeMillis() - startTime) / 1000; if (elapsed == 0) { return bytesRead; } else { return bytesRead / elapsed; } }