MCPcopy Create free account
hub / github.com/e2wugui/zeze / main2

Method main2

ZezeJava/ZezeJavaTest/src/Benchmark/BenchRocksDb.java:38–96  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

36 }
37
38 public static void main2(String[] args) throws Exception {
39 System.out.println("begin");
40 RocksDB.loadLibrary();
41 var dbHome = "~$BenchRocksDb";
42 Application.renameAndDeleteDirectory(new File(dbHome));
43 var cache = new LRUCache(8 * 1024 * 1024);
44 var cfg = new BlockBasedTableConfig();
45 cfg.setBlockCache(cache);
46 Options commonOptions = new Options()
47 .setCreateIfMissing(true)
48 .setDbWriteBufferSize(64 << 20) // total write buffer bytes, include all the columns
49 // .setRowCache(cache)
50 .setTableFormatConfig(cfg)
51 .setKeepLogFileNum(5);
52 try (var rocksDb = RocksDB.open(commonOptions, dbHome)) {
53 var k = new byte[4];
54 var v = new byte[100];
55 ThreadLocalRandom.current().nextBytes(v);
56 var t = System.nanoTime();
57 for (int i = 0; i < 100000; i++) {
58 ByteBuffer.intBeHandler.set(k, 0, i);
59 rocksDb.put(RocksDatabase.getDefaultWriteOptions(), k, v);
60 }
61 System.out.println((System.nanoTime() - t) / 1_000_000 + " ms");
62 t = System.nanoTime();
63 for (int i = 0; i < 100000; i++) {
64 ByteBuffer.intBeHandler.set(k, 0, i);
65 rocksDb.get(RocksDatabase.getDefaultReadOptions(), k);
66 }
67 System.out.println((System.nanoTime() - t) / 1_000_000 + " ms");
68 var wb = new WriteBatch();
69 t = System.nanoTime();
70 for (int i = 0; i < 100000; i++) {
71 ByteBuffer.intBeHandler.set(k, 0, i);
72 wb.clear();
73 wb.put(k, v);
74 rocksDb.write(RocksDatabase.getDefaultWriteOptions(), wb);
75 }
76 System.out.println((System.nanoTime() - t) / 1_000_000 + " ms");
77 wb.clear();
78 t = System.nanoTime();
79 for (int i = 0; i < 100000; i++) {
80 ByteBuffer.intBeHandler.set(k, 0, i);
81 wb.put(k, v);
82 }
83 rocksDb.write(RocksDatabase.getDefaultWriteOptions(), wb);
84 System.out.println((System.nanoTime() - t) / 1_000_000 + " ms");
85
86// for (int i = 0; i < 256; i++)
87// rocksDb.put(new byte[]{(byte)i}, new byte[i]);
88// for (int i = 0; i < 256; i++)
89// System.out.println(rocksDb.get(new byte[]{(byte)i}).length);
90 System.out.println(rocksDb.getProperty("rocksdb.estimate-table-readers-mem"));
91 System.out.println(rocksDb.getProperty("rocksdb.cur-size-all-mem-tables"));
92 System.out.println(cache.getUsage());
93 System.out.println(cache.getPinnedUsage());
94 }
95 System.out.println("end");

Callers

nothing calls this directly

Calls 12

getDefaultReadOptionsMethod · 0.95
currentMethod · 0.80
getPropertyMethod · 0.80
openMethod · 0.65
putMethod · 0.65
getMethod · 0.65
clearMethod · 0.65
writeMethod · 0.65
nextBytesMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected