-
Notifications
You must be signed in to change notification settings - Fork 579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OnHeap:MappingCount statistic is reporting more entries than maximum allowed #2414
Comments
If you could provide a reproducible test case that would be great... otherwise I'm struggling for motivation. |
Take this class: public class MappingCount {
public static void main(String[] args) throws IOException {
StatisticsService statisticsService = new DefaultStatisticsService();
try (CacheManager cacheManager = newCacheManagerBuilder().using(statisticsService).using(new DefaultManagementRegistryConfiguration().setCacheManagerAlias("my-cache-manager"))
.withCache("cache", newCacheConfigurationBuilder(Integer.class, Integer.class, newResourcePoolsBuilder().heap(100, EntryUnit.ENTRIES).offheap(1, MemoryUnit.MB)).build())
.build(true)) {
Cache<Integer, Integer> cache = cacheManager.getCache("cache", Integer.class, Integer.class);
int TOTAL_ENTRIES = 1_000_000;
for (int i = 0; i < TOTAL_ENTRIES; i++) {
cache.put(i, i);
}
new Thread() {
{setDaemon(true);}
@Override
public void run() {
while (!Thread.currentThread().isInterrupted()) {
System.out.println(statisticsService.getCacheStatistics("cache").getTierStatistics().get("OnHeap").getMappings());
try {
sleep(200);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}.start();
Random rnd = new Random();
CountDownLatch start = new CountDownLatch(1);
for (int i = 0; i < Runtime.getRuntime().availableProcessors(); i++) {
new Thread() {
{setDaemon(true);}
@Override
public void run() {
try {
start.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
while (!Thread.currentThread().isInterrupted()) {
cache.get(rnd.nextInt(TOTAL_ENTRIES));
try {
sleep(5);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}.start();
}
start.countDown();
System.in.read();
}
}
} On my computer it prints something like:
But if you comment
And if I completely remove any sleep or yield to keep the
it often goes above the max number of entries. |
Code inspection shows that to not be true. Capacity enforcement is performed after the entries are put in the heap. This means max entries can rise above threshold by the number of threads accessing the cache. |
If we configure a cache with 100 entries (i.e. heap) in TinyPounder.
We pounding it hard (max value)
And we immediately go to look at the sizing information (OnHeap:MappingCount vs # of max entries allowed).
We can see during a short period of time that the MappingCount reported is 101 whereas the max number of entries is 100.
@henri-tremblay told me that we shouldn't have this behaviour since eviction is done before adding new values
CC @anthonydahanne @boyusun-SAG
I do not have a unit test to automatically reproduce that. I just did with the TinyPounder and management console.
The text was updated successfully, but these errors were encountered: