use of org.apache.ignite.internal.processors.cache.persistence.pagemem.FullPageIdTable in project ignite by apache.
the class PageIdDistributionTest method _testRealHistory.
/**
* Uncomment and run this test manually to get data to plot histogram for per-element distance from ideal.
* You can use Octave to plot the histogram:
* <pre>
* all = csvread("histo.txt");
* hist(all, 200)
* </pre>
*
* @throws Exception If failed.
*/
public void _testRealHistory() throws Exception {
int capacity = CACHE_IDS.length * PARTS * PAGES;
info("Capacity: " + capacity);
long mem = FullPageIdTable.requiredMemory(capacity);
info(U.readableSize(mem, true));
UnsafeMemoryProvider prov = new UnsafeMemoryProvider(new JavaLogger());
prov.initialize(new long[] { mem });
DirectMemoryRegion region = prov.nextRegion();
try {
long seed = U.currentTimeMillis();
info("Seed: " + seed + "L; //");
Random rnd = new Random(seed);
FullPageIdTable tbl = new FullPageIdTable(region.address(), region.size(), true);
Map<T2<Integer, Integer>, Integer> allocated = new HashMap<>();
for (int i = 0; i < capacity; i++) {
int cacheId = CACHE_IDS[rnd.nextInt(CACHE_IDS.length)];
int partId = rnd.nextInt(PARTS);
T2<Integer, Integer> key = new T2<>(cacheId, partId);
Integer pageIdx = allocated.get(key);
pageIdx = pageIdx == null ? 1 : pageIdx + 1;
if (pageIdx > PAGES)
continue;
tbl.put(cacheId, PageIdUtils.pageId(partId, (byte) 0, pageIdx), 1, 0);
allocated.put(key, pageIdx);
if (i > 0 && i % 100_000 == 0)
info("Done: " + i);
}
int[] scans = new int[capacity];
int cur = 0;
for (T2<Integer, Integer> key : allocated.keySet()) {
Integer alloc = allocated.get(key);
if (alloc != null) {
for (int idx = 1; idx <= alloc; idx++) {
scans[cur] = tbl.distanceFromIdeal(key.get1(), PageIdUtils.pageId(key.get2(), (byte) 0, idx), 0);
assert scans[cur] != -1;
cur++;
}
}
}
try (FileOutputStream out = new FileOutputStream("histo.txt")) {
PrintWriter w = new PrintWriter(new OutputStreamWriter(out));
for (int scan : scans) {
if (scan != 0)
w.println(scan);
}
w.flush();
}
} finally {
prov.shutdown();
}
}
Aggregations