Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package examples;
 
 import org.mapdb.DB;
 
 import java.io.File;
 import java.util.Map;
Demonstrates how BTree parameters affects performance. BTreeMap has two key parameters which affects its performance:

Maximal node size

Controls how but BTree node can get, before it splits. All keys and values in BTree node are stored and deserialized together. Large nodes means fewer disk access (tree structure is shallower), but also more data to read (more keys to be deserialized).

Store values inside node

Value may be stored inside or outside of BTree node. It is recommended to store large values outside nodes.

Sample output

  Node size |  small vals  |  large vals  |  large vals outside node
     6      |       25 s   |       89 s   |    49 s   |
    18      |       25 s   |      144 s   |    50 s   |
    32      |       57 s   |      175 s   |    31 s   |
    64      |       53 s   |      231 s   |    49 s   |
   120      |       73 s   |       98 s   |    49 s   |
 
    static final int[] nodeSizes = {6, 18, 32, 64, 120};
    public static void main(String[] args) {
        Random r = new Random();
        ..println(" Node size |  small vals  |  large vals  |  large vals outside node" );
        for(int nodeSize:){
            . .print("    "+nodeSize+"      |");
            for(int j=0;j<3;j++){
                boolean useSmallValues = (j==0);
                boolean valueOutsideOfNodes = (j==2);
                DB db = DBMaker
                        .newFileDB(new File("/mnt/big/adsasd"))
                        .deleteFilesAfterClose()
                        .closeOnJvmShutdown()
                        .transactionDisable()
                        .cacheSize(10) //use small cache size, to simulate much larger store with relatively small cache.
                        .make();
                Map<Long,Stringmap =
                        (valueOutsideOfNodes?
                                (db.createTreeMap("test").valuesOutsideNodesEnable()):
                                db.createTreeMap("test"))
                    .nodeSize(nodeSize)
                    .make();
                long startTime = System.currentTimeMillis();
                for(int i=0;i<1e6;i++){
                    long key = r.nextLong();
                    String value =  useSmallValues?
                            //small value
                            "abc"+key:
                            //large value
                            "qwdkqwdoqpwfwe-09fewkljklcejewfcklajewjkleawckjlaweklcwelkcwecklwecjwekecklwecklaa"
                                    +"kvlskldvklsdklcklsdvkdflvvvvvvvvvvvvvvvvvvvvvvvsl;kzlkvlksdlkvklsdklvkldsklk"
                                    +key;
                    map.put(keyvalue);
                }
                ..print("    ");
                ..print((System.currentTimeMillis()-startTime)/1000+" s");
                ..print("   |");
                db.close();
            }
            ..println("");
        }
    }
New to GrepCode? Check out our FAQ X