ITPub博客

首页 > 数据库 > > 哈希索引@ SwayDB

哈希索引@ SwayDB

作者:u_9ff4c058a0e0 时间:2022-04-15 14:34:37 0 删除 编辑

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

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

  1. Map<Integer, String, Void> map =
  2. MapConfig
  3. .functionsOff(Paths.get("myMap"), intSerializer(), stringSerializer())
  4. .set随机关键字索引(RandomKeyIndex.disable())
  5. .get();
  6. map.put(1, "one");
  7. map.get(1); //Optional[one]

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


  1. Map<Integer, String, Void> map =
  2. MapConfig
  3. .functionsOff(Paths.get("myMap"), intSerializer(), stringSerializer())
  4. .setRandomKeyIndex(
  5. RandomKeyIndex
  6. .builder()
  7. .maxProbe(10) //re-hash 10 times to resolve hash collision
  8. .minimumNumberOfKeys(20) //minimum keys required
  9. .minimumNumberOfHits(10) //minimum indexed keys required
  10. //use reference format. IndexFormat.copyKeys() can also be used here
  11. //to copy keys directly into the hash-index
  12. .indexFormat(IndexFormat.reference())
  13. .allocateSpace(
  14. (RandomKeyIndex.RequiredSpace optimalSpace) ->
  15. //allocates 3 times more storage than the
  16. //default optimal space for higher hit rate.
  17. optimalSpace.requiredSpace() * 3
  18. )
  19. //allow async IO for all IO operations
  20. .ioStrategy((IOAction ioAction) -> new IOStrategy.AsyncIO(true))
  21. //Use LZ4 and fallback to Snappy.
  22. .compression((UncompressedBlockInfo info) ->
  23. Arrays.asList(
  24. //try running LZ4 with minimum 20.0% compression
  25. Compression.lz4Pair(
  26. new Pair(LZ4Instance.fastestInstance(), new LZ4Compressor.Fast(20.0)),
  27. new Pair(LZ4Instance.fastestInstance(), LZ4Decompressor.fastDecompressor())
  28. ),
  29. //if LZ4 fails try Snappy with 20.0% compression.
  30. new Compression.Snappy(20.0)
  31. )
  32. )
  33. )
  34. .get();
  35. map.put(1, "one");
  36. 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

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69999831/viewspace-3164808/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2022-02-11

  • 博文量
    1828
  • 访问量
    20630