0

Hi I am trying to use MapDB offheap memory using 2.0.8, i tried 1.0.8 as well

db = DBMaker.newMemoryDirectDB().transactionDisable().asyncWriteFlushDelay(100).make();

my tests:

@Test
public void testMapDBInsertionHash() {
    @SuppressWarnings("rawtypes")
    Map glimpses = db.hashMap("hashGlimpse") ;
    long start = System.currentTimeMillis();
    for (int i = 0; i < ITEMS; i++) {
        if (i == 1000) {
            glimpses.put(i, FIXED_STRING);
            continue;
        }
        glimpses.put(i, RandomStringUtils.randomAlphabetic(10));
    }
    System.out.println(
            "HashMap: Entries in map:" + glimpses.size() + " in: " + (System.currentTimeMillis() - start) + " ms.");
    System.out.println("1000th entry:" + glimpses.get(1000));
}

-- Native:

@Test
public void testJavaInsertionHash() {
    Map<Integer, String> glimpses = new HashMap<>();
    long start = System.currentTimeMillis();
    for (int i = 0; i < ITEMS; i++) {
        if (i == 1000) {
            glimpses.put(i, FIXED_STRING);
            continue;
        }
        glimpses.put(i, RandomStringUtils.randomAlphabetic(10));
    }
    System.out.println(
            "HashMap: Entries in map:" + glimpses.size() + " in: " + (System.currentTimeMillis() - start) + " ms.");
    System.out.println("1000th entry:" + glimpses.get(1000));
}

MapDB is 10 times slower than native java hashMap I am using -XX:MaxDirectMemorySize=64M

What am I missing?

thanks

ameet chaubal
  • 1,440
  • 16
  • 37
  • Hi, did you manage to find out if something was missing ? – ic3 Feb 05 '16 at 08:39
  • The problem is serialization & D serialization when you put things off heap you definitely need these two items and the Ser/dser used for that purpose is very important I found another product called FST that has a better Ser/dser and gives better performance you may want to check that out – ameet chaubal Feb 05 '16 at 13:17
  • Looks like you are writing a String to it, mapdb might be doing something with that string like converting it into the form it would use to store on to disk if that is the case it wont be able to match a regular hashmap which does no conversion on the value itself. If you do need mapdb and for it to be fast you will want to override how mapdb writes out strings as it is not particularly efficient – Luke Dec 11 '19 at 22:43

0 Answers0