Search code examples
javatreesetmapdb

MapDb treeset key doesn't come with expire property


I use mapdb's direct memory to act as my off-heap memory. Because there are a lot of sortedset in my application, so I used mapdb treeset cache mechanism to store my values.

Code as below:

@PostConstruct
private void initDbEngine() {
    try {
        dbEngine = DBMaker
                .memoryDirectDB()
                .closeOnJvmShutdown()
                .concurrencyScale(16)
                .make();
        logger.error("dbEngine init ok...");
    } catch (Exception ex) {
        logger.error(OffheapCacheConst.PACKAGE_CONTAINER, ex);
        throw ex;
    }
}



private SortedSet initSortedSetContainer(String containerName) {
    try {
        SortedSet sortedSet = dbEngine
                .treeSet(containerName)
                // why below three properties not exist????
                //.expireAfterCreate(86400 * 30 * 12, TimeUnit.SECONDS)
                //.expireAfterUpdate(86400 * 30 * 12, TimeUnit.SECONDS)
                //.expireAfterGet(86400 * 30 * 12, TimeUnit.SECONDS)
                .maxNodeSize(16)
                .createOrOpen();
        return sortedSet;
    } catch (Exception ex) {
        logger.error(OffheapCacheConst.PACKAGE_CONTAINER, ex);
        throw ex;
    }
}

But when I tried to find the expireAfterCreate/expireAfterUpdate/expireAfterGet property, I got none. Just wondering, why treeset didn't get these properties attached?

Any more ideas that I can do key expiration with mapdb's treeset?


Solution

  • Finally we discard the option to use mapdb as offheap cache because its performance doesn't fit for our requirement. I have done the benchmark with ohc and result below:

    Benchmark                     Mode  Cnt       Score       Error  Units
    OhcBenchmark.testOhcGet      thrpt   20  923806.733 ± 19007.928  ops/s
    OhcBenchmark.testOhcHGet     thrpt   20  242194.462 ± 11365.323  ops/s
    OhcBenchmark.testOhcHGetAll  thrpt   20  265504.651 ± 15110.371  ops/s
    OhcBenchmark.testOhcHSet     thrpt   20  204028.508 ± 59620.923  ops/s
    OhcBenchmark.testOhcSAdd     thrpt   20   10097.188 ±   607.277  ops/s
    OhcBenchmark.testOhcSet      thrpt   20  417034.685 ± 69965.252  ops/s
    OhcBenchmark.testOhcSmember  thrpt   20  329536.900 ± 15128.885  ops/s
    OhcBenchmark.testOhcZAdd     thrpt   20  222422.422 ± 33836.662  ops/s
    OhcBenchmark.testOhcZRange   thrpt   20  155268.857 ±  5373.339  ops/s
    
    
    Benchmark                              Mode  Cnt      Score      Error  Units
    MapdbCacheBenchmark.testMapdbGet      thrpt   20  43376.407 ± 6046.811  ops/s
    MapdbCacheBenchmark.testMapdbHGet     thrpt   20  45982.205 ± 2212.897  ops/s
    MapdbCacheBenchmark.testMapdbHGetAll  thrpt   20  48149.936 ± 1819.886  ops/s
    MapdbCacheBenchmark.testMapdbHSet     thrpt   20  18269.013 ± 1133.118  ops/s
    MapdbCacheBenchmark.testMapdbSAdd     thrpt   20    246.944 ±   31.502  ops/s
    MapdbCacheBenchmark.testMapdbSet      thrpt   20  28922.292 ± 1618.363  ops/s
    MapdbCacheBenchmark.testMapdbSmember  thrpt   20  50328.641 ± 3519.970  ops/s
    MapdbCacheBenchmark.testMapdbZAdd     thrpt   20  14729.551 ±  658.754  ops/s
    MapdbCacheBenchmark.testMapdbZRange   thrpt   20  37038.027 ± 1795.458  ops/s
    

    Also, ohc supports key expire, that's what we need. Mapdb can't set expire time for a key in the Map.