public void add(HankTimer timer) { add(timer, 1); }
public RandomReadsRunnable(File[] testFiles, int randomReadBufferSize) throws FileNotFoundException { // Open file channels testChannels = new FileChannel[testFiles.length]; for (int i = 0; i < testFiles.length; ++i) { testChannels[i] = new FileInputStream(testFiles[i]).getChannel(); } timerAggregator = new HankTimerEventAggregator("Random reads", 1); this.randomReadBufferSize = randomReadBufferSize; }
private synchronized void _add(long startTimeNanos, long durationNanos, int underlyingCount) { ++count; // Determine computation window start and end if (startTimeNanos < statsComputationWindowStart) { statsComputationWindowStart = startTimeNanos; } if ((startTimeNanos + durationNanos) > statsComputationWindowEnd) { statsComputationWindowEnd = startTimeNanos + durationNanos; } // Compute statistics double duration = durationNanos / 1000000d; totalDuration += duration; if (duration < minDuration) { minDuration = duration; } if (duration > maxDuration) { maxDuration = duration; } durations[count - 1] = duration; totalUnderlyingCount += underlyingCount; // Dump stats if needed if (count == statsComputationWindow) { // Determine computation window duration statsComputationWindowDuration = Math.abs(statsComputationWindowEnd - statsComputationWindowStart); logStats(); clear(); } }
@Override public void run() { try { Random random = new Random(); // Perform random reads byte[] readBufferArray = new byte[randomReadBufferSize]; ByteBuffer readBuffer = ByteBuffer.wrap(readBufferArray); HankTimer timer = timerAggregator.getTimer(); for (int i = 0; i < NUM_RANDOM_READS; ++i) { readBuffer.clear(); FileChannel testChannel = testChannels[i % testChannels.length]; long randomPosition = Math.abs(random.nextLong()) % (testChannel.size() - randomReadBufferSize); testChannel.position(randomPosition) .read(readBuffer); } timerAggregator.add(timer, NUM_RANDOM_READS); // Close file channels for (FileChannel testChannel : testChannels) { testChannel.close(); } } catch (Exception e) { LOG.error("Failed to perform random reads", e); } } }
/** * @param name * @param statsComputationWindow Number of timers to aggregate before computing and * logging statistics. 0 means no timer aggregation. */ public HankTimerEventAggregator(String name, int statsComputationWindow) { this.name = name; this.statsComputationWindow = statsComputationWindow; this.isActive = statsComputationWindow != 0; this.populationStatistics = null; this.previousPopulationStatistics = new DoublePopulationStatisticsAggregator(); this.durations = new double[statsComputationWindow]; clear(); }
public void add(HankTimer timer, int underlyingCount) { if (!isActive) { return; } _add(timer.getStartTime(), timer.getDuration(), underlyingCount); }
public RuntimeStatisticsAggregator getRuntimeStatistics() { RuntimeStatisticsAggregator runtimeStatisticsAggregator = new RuntimeStatisticsAggregator(); for (PartitionAccessor partitionAccessor : partitionAccessors) { if (partitionAccessor != null) { runtimeStatisticsAggregator.add(partitionAccessor.getRuntimeStatistics()); } } runtimeStatisticsAggregator.setGetRequestsPopulationStatistics( getRequestsTimerAggregator.getAndResetPopulationStatistics()); return runtimeStatisticsAggregator; } }
public HankResponse get(ByteBuffer key, ReaderResult result) throws IOException { HankTimer timer = getRequestsTimerAggregator.getTimer(); try { int partition = partitioner.partition(key, partitionAccessors.length); PartitionAccessor partitionAccessor = partitionAccessors[partition]; if (partitionAccessor == null) { LOG.error("Failed to perform get because of an Exception: wrong host for domain: " + hostDomain.getDomain().getName() + ", partition: " + partition + ", key: " + BytesUtils.bytesToHexString(key) + ", response: " + WRONG_HOST); return WRONG_HOST; } return partitionAccessor.get(key, result); } finally { getRequestsTimerAggregator.add(timer); } }
DomainAccessor(HostDomain hostDomain, PartitionAccessor[] partitionAccessors, Partitioner partitioner, int getTimerAggregatorWindow) throws IOException { this.hostDomain = hostDomain; this.partitionAccessors = partitionAccessors; this.partitioner = partitioner; this.getRequestsTimerAggregator = new HankTimerEventAggregator("GET " + hostDomain.getDomain().getName(), getTimerAggregatorWindow); }