Sorry, the attachment is here. :)
On Tuesday, March 21, 2017 at 8:44:16 PM UTC+1, Roland Lohner wrote:
>
> Hi Thomas,
>
> The attached test reproduces the case using MVMap<String, HashMap<String,
> Object>>
>
> Regards,
> Roland
>
>
> On Wednesday, March 15, 2017 at 1:13:14 PM UTC+1, Thomas Mueller Graf
> wrote:
>>
>> Hi,
>>
>> OK I see. I'm not sure, maybe this is a bug? Can you reproduce it with a
>> simple test case (for example using <Integer, String>)?
>>
>> Regards,
>> Thomas
>>
>>
>> On Wed, Mar 15, 2017 at 12:20 PM, Roland Lohner <[email protected]> wrote:
>>
>>> Hi Thomas,
>>>
>>> I suspect you misunderstood case B).
>>> In that case only the search function is called.
>>> It means there is no overwrite as there are no put operations, only get
>>> operations are called.
>>>
>>> I am wondering what causes the different used cache size in case B)
>>>
>>> Regarding 1.7G java memory vs. 5G reported cache size anomaly. You are
>>> right.
>>> I have put a special structure as value into MVMap, without using a
>>> proper DataType as valueType.
>>> So MVMap did not have a chance to estimate used cache size.
>>>
>>> Regards, Roland
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "H2 Database" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at https://groups.google.com/group/h2-database.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.
package local;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.HashMap;
import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVStore;
import org.junit.Test;
public class MvStoreCacheSizeTest {
private static final String DB_NAME = "db";
private static final String MAP_NAME = "map";
private final static int BYTE_TO_MB = 1024 * 1024;
private static final int BATCH_COUNT = 5;
private static final int ELEMENT_IN_BATCH_COUNT = 100_000;
@Test
public void test() throws Exception {
System.out.println("INSERT");
MVStore store = openStore(DB_NAME);
MVMap<String, HashMap<String, Object>> map = store.openMap(MAP_NAME);
printStore(store);
int[] cacheSizesDuringInsert = new int[BATCH_COUNT];
for (int i = 0; i < BATCH_COUNT; i++) {
addData(map, i);
store.commit();
printStore(store);
cacheSizesDuringInsert[i] = store.getCacheSizeUsed();
}
store.close();
System.out.println("RETRIEVE");
store = openStore(DB_NAME);
map = store.openMap(MAP_NAME);
printStore(store);
int[] cacheSizesDuringRetrieve = new int[BATCH_COUNT];
for (int i = 0; i < BATCH_COUNT; i++) {
getData(map, i);
printStore(store);
cacheSizesDuringRetrieve[i] = store.getCacheSizeUsed();
}
assertTrue("Cache size during inseting the batches and during retrieving them do not match:\n" +
" during insert: " + Arrays.toString(cacheSizesDuringInsert) + "\n during retrieve: "
+ Arrays.toString(cacheSizesDuringRetrieve),
Arrays.equals(cacheSizesDuringInsert, cacheSizesDuringRetrieve));
}
private MVStore openStore(String path) {
MVStore store = MVStore.open(path);
store.setAutoCommitDelay(0);
store.setReuseSpace(true);
store.setVersionsToKeep(0);
store.setCacheSize(1024);
return store;
}
private void addData(MVMap<String, HashMap<String, Object>> map, int chunkKey) throws Exception {
for (int i = 0; i < ELEMENT_IN_BATCH_COUNT; i++) {
String key = getKey(chunkKey, i);
HashMap<String, Object> innerMap = new HashMap<String, Object>();
innerMap.put("key1", "value1");
innerMap.put("key2", "value2");
map.put(key, innerMap);
}
}
private void getData(MVMap<String, HashMap<String, Object>> map, int chunkKey) throws Exception {
for (int i = 0; i < ELEMENT_IN_BATCH_COUNT; i++) {
map.get(getKey(chunkKey, i));
}
}
private String getKey(int chunkKey, int serial) {
return String.format("%06d", chunkKey) + String.format("%10d", serial);
}
private void printStore(MVStore store) {
Runtime run = Runtime.getRuntime();
run.gc();
System.out.println("\n\nCache full size: " + store.getCacheSizeUsed());
System.out.println("Cache used size: " + store.getCacheSizeUsed());
System.out.println("-------------------------------");
System.out.println("Heap used size: " + (run.totalMemory() - run.freeMemory()) / BYTE_TO_MB);
System.out.println("Heap full size: " + run.totalMemory() / BYTE_TO_MB);
System.out.println("Heap max size: " + run.maxMemory() / BYTE_TO_MB);
System.out.println("Heap free size: " + run.freeMemory() / BYTE_TO_MB);
}
}