float hitRate = hitRate(store); float missRate = missRate(store); long countSize = countSize(store); float accessRate = hitRate + missRate; if (byteSize(store) > unloadedSize) { return Float.NEGATIVE_INFINITY; } else { return Float.POSITIVE_INFINITY; } else { float cost = (hitRate / countSize) * hitDistributionFunction(hitRate / accessRate); if (Float.isNaN(cost)) { throw new AssertionError(String.format("NaN Eviction Cost [hit:%f miss:%f size:%d]", hitRate, missRate, countSize));
/** * {@inheritDoc} */ public boolean freeSpace(Collection<T> from, long bytes) { if (from == null || from.isEmpty()) { return false; } List<T> random = new ArrayList<T>(from); Collections.shuffle(random); for (int i = 0; i < random.size(); i += SAMPLE_SIZE) { List<T> sorted = random.subList(i, Math.min(SAMPLE_SIZE + i, random.size())); Collections.sort(sorted, new EvictionCostComparator(getDesiredUnloadedSize(sorted), sorted.size() + 1)); for (T store : sorted) { int count; long byteSize = byteSize(store); long countSize = countSize(store); if (countSize == 0 || byteSize == 0) { count = 1; } else { count = (int) Math.max((bytes * countSize) / byteSize, 1L); } if (evict(store, count, bytes)) { return true; } } } return false; }
private long getDesiredUnloadedSize(Collection<T> from) { long unloadedSize = 0L; for (T s : from) { unloadedSize += byteSize(s); } return unloadedSize / from.size(); } }