04-20.eri-test 哈希索引@ SwayDB

Hash-index @ SwayDB

哈希索引将随机读取性能提高了55%!

Hash-index-performance-bar-chart

哈希索引,例如哈希集要么哈希图对于处理随机读取请求很有用。 它们提高了随机访问数据的性能,减少了IOps的总数并节省了CPU时间。 但是对于那些需要很少像这样随机读取

  • 时间序列要么事件源数据可能只需要快速顺序读取。
  • 冷库要么存档数据可能根本不需要随机读取。

A configurable hash-index is required for SwayDB so various data storage requirements could be handled. 以下是要求:

  • (可选)启用或禁用哈希索引。
  • 允许创建完美或接近完美的哈希索引。
  • Create partially indexed hash-indexes with fallback to alternative indexes like binary-search & linear-search.
  • 将密钥直接复制到哈希索引中。
  • 受控并发。
  • 压缩。

Example configuration

下面创建一个持久的地图禁用哈希索引的位置。

Map<Integer, String, Void> map =  
  MapConfig  
    .functionsOff(Paths.get("myMap"), intSerializer(), stringSerializer())  
    .set随机关键字索引(RandomKeyIndex.disable())  
    .get();

map.put(1, "one");  
map.get(1); //Optional[one]

以下启用哈希索引(RandomKeyIndex)与自定义配置。

Map<Integer, String, Void> map =  
  MapConfig  
    .functionsOff(Paths.get("myMap"), intSerializer(), stringSerializer())  
    .setRandomKeyIndex(  
      RandomKeyIndex  
        .builder()  
        .maxProbe(10) //re-hash 10 times to resolve hash collision
        .minimumNumberOfKeys(20) //minimum keys required
        .minimumNumberOfHits(10) //minimum indexed keys required 
        //use reference format. IndexFormat.copyKeys() can also be used here
        //to copy keys directly into the hash-index
        .indexFormat(IndexFormat.reference())
        .allocateSpace(  
          (RandomKeyIndex.RequiredSpace optimalSpace) ->
            //allocates 3 times more storage than the 
            //default optimal space for higher hit rate. 
            optimalSpace.requiredSpace() * 3   
         )  
         //allow async IO for all IO operations
        .ioStrategy((IOAction ioAction) -> new IOStrategy.AsyncIO(true))  
         //Use LZ4 and fallback to Snappy.
        .compression((UncompressedBlockInfo info) ->  
          Arrays.asList(  
             //try running LZ4 with minimum 20.0% compression    
            Compression.lz4Pair(  
              new Pair(LZ4Instance.fastestInstance(), new LZ4Compressor.Fast(20.0)),  
              new Pair(LZ4Instance.fastestInstance(), LZ4Decompressor.fastDecompressor())  
            ),  
            //if LZ4 fails try Snappy with 20.0% compression.    
            new Compression.Snappy(20.0)  
         )  
       )  
    )  
    .get();

map.put(1, "one");  
map.get(1); //Optional[one]

For a detail documentation of the configurations refer to documentation website.

Useful links

from: https://dev.to//simerplaha/hash-index-swaydb-4k8

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值