public PartitionAccessor(HostDomainPartition partition, Reader reader) { if (reader == null) { throw new IllegalArgumentException("Reader may not be null!"); } this.partition = partition; this.reader = reader; windowTimer.restart(); countersWindow = new AtomicLongCollection(5, new long[]{0, 0, 0, 0, 0}); }
public AtomicLongCollection(int size, long[] initialValues) { values = new long[size]; set(initialValues); }
public HankResponse get(ByteBuffer key, ReaderResult result) throws IOException { // Increment requests counter LOG.trace("Partition GET"); reader.get(key, result); int l1CacheHit = result.getL1CacheHit() ? 1 : 0; int l2CacheHit = result.getL2CacheHit() ? 1 : 0; if (result.isFound()) { countersWindow.increment(1, 1, result.getBuffer().remaining(), l1CacheHit, l2CacheHit); return HankResponse.value(result.getBuffer()); } else { countersWindow.increment(1, 0, 0, l1CacheHit, l2CacheHit); return NOT_FOUND; } }
public PartitionAccessorRuntimeStatistics getRuntimeStatistics() { // Copy duration and counts long windowDurationNanos = windowTimer.getDuration(); windowTimer.restart(); // Get atomic counters long[] counters = countersWindow.getAsArrayAndSet(0, 0, 0, 0, 0); long numRequestsInWindow = counters[0]; long numHitsInWindow = counters[1]; long responsesNumBytesInWindow = counters[2]; long numL1CacheHitsInWindow = counters[3]; long numL2CacheHitsInWindow = counters[4]; double throughput = 0; double responseDataThroughput = 0; if (windowDurationNanos != 0) { throughput = numRequestsInWindow / (windowDurationNanos / 1000000000d); responseDataThroughput = responsesNumBytesInWindow / (windowDurationNanos / 1000000000d); } return new PartitionAccessorRuntimeStatistics(numRequestsInWindow, numHitsInWindow, throughput, responseDataThroughput, numL1CacheHitsInWindow, numL2CacheHitsInWindow, reader.getCacheStatistics()); }
timer.restart(); long[] requestsCounterValues = requestsCounters.getAsArrayAndSet(0, 0); long numRequests = requestsCounterValues[0]; long numCacheHits = requestsCounterValues[1];
new DomainAndKey.DomainAndKeyMemoryUsageEstimator(), new HankResponseMemoryUsageEstimator()); this.requestsCounters = new AtomicLongCollection(2, new long[]{0, 0}); this.preferredHostEnvironment = options.getPreferredServerEnvironment(); LOG.info("Initializing client using preferred host environment: " + preferredHostEnvironment);
synchronized public long[] getAsArrayAndSet(long... newValues) { long[] result = new long[values.length]; System.arraycopy(values, 0, result, 0, values.length); set(newValues); return result; }