incubator-hugegraph icon indicating copy to clipboard operation
incubator-hugegraph copied to clipboard

[Question] How to limit the flow on hstore side ?

Open shirleyStorage opened this issue 2 years ago • 3 comments

Problem Type (问题类型)

struct / logic (架构 / 逻辑设计问题)

Before submit

  • [X] 我已经确认现有的 Issues 与 FAQ 中没有相同 / 重复问题 (I have confirmed and searched that there are no similar problems in the historical issue and documents)

Environment (环境信息)

  • Server Version: 1.0.0 (Apache Release Version)
  • Backend: RocksDB x nodes, HDD or SSD
  • OS: xx CPUs, xx G RAM, Ubuntu 2x.x / CentOS 7.x
  • Data Size: xx vertices, xx edges

Your Question (问题描述)

How to limit the flow on hstore side?

Vertex/Edge example (问题点 / 边数据举例)

No response

Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)

No response

shirleyStorage avatar Sep 04 '24 13:09 shirleyStorage

To limit the flow on the hstore side in Apache HugeGraph, you can use the scanIterator method with a specified limit. The scanIterator method allows you to set a limit on the number of entries returned during the scan. Here is an example:

HgStoreTestUtil.println("-- test limit 1 to 10 --");
for (int i = 1; i <= 10; i++) {
    HgStoreTestUtil.println("- limit " + i + " -");
    int limit = i;
    HgKvIterator<HgKvEntry> iterator = session.scanIterator(tableName, 
        HgStoreTestUtil.toOwnerKey(keyName + "-0"),
        HgStoreTestUtil.toOwnerKey(keyName + "-1"), limit);
    int count = 0;
    while (iterator.hasNext()) {
        count++;
        HgKvEntry entry = iterator.next();
        HgStoreTestUtil.println(entry);
    }
    Assert.assertEquals(limit, count);
}

In this example, the scanIterator method is called with a limit parameter that controls the number of entries returned. The loop iterates from 1 to 10, setting different limits for each iteration. This effectively limits the flow of data on the hstore side [1].

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Sep 04 '24 13:09 dosubot[bot]

@dosu When multiple servers access the hstore together, is there any configuration to implement read/write traffic control on the hstore?

shirleyStorage avatar Sep 04 '24 13:09 shirleyStorage

Yes, HugeGraph provides several configuration options to control read/write traffic on the hstore (RocksDB). Here are some key options:

  1. TOTAL_MEMORY_SIZE: Limits the total memory of memtables for all databases.

    public static final ConfigOption<Long> TOTAL_MEMORY_SIZE = new ConfigOption<>(
        "rocksdb.total_memory_size",
        "Limit total memory of memtables for all dbs",
        rangeInt(0L, Long.MAX_VALUE),
        48L * Bytes.GB
    );
    
  2. WRITE_BUFFER_RATIO: Specifies the write buffer ratio.

    public static final ConfigOption<Double> WRITE_BUFFER_RATIO = new ConfigOption<>(
        "rocksdb.write_buffer_ratio",
        "write buffer ratio",
        rangeDouble(0.0, 1.0),
        0.66
    );
    
  3. WRITE_BUFFER_ALLOW_STALL: Enables stalling of writes when memory usage exceeds buffer size.

    public static final ConfigOption<Boolean> WRITE_BUFFER_ALLOW_STALL = new ConfigOption<>(
        "rocksdb.write_buffer_allow_stall",
        "if set true, it will enable stalling of writes when memory_usage() exceeds buffer_size. It will wait for flush to complete and memory usage to drop down",
        disallowEmpty(),
        false
    );
    
  4. DELAYED_WRITE_RATE: Sets the rate limit in bytes/s of user write requests when compaction gets behind.

    public static final ConfigOption<Long> DELAYED_WRITE_RATE = new ConfigOption<>(
        "rocksdb.delayed_write_rate",
        "The rate limit in bytes/s of user write requests when need to slow down if the compaction gets behind.",
        rangeInt(1L, Long.MAX_VALUE),
        64L * Bytes.MB
    );
    
  5. MAX_TOTAL_WAL_SIZE: Sets the total size of WAL files in bytes.

    public static final ConfigOption<Long> MAX_TOTAL_WAL_SIZE = new ConfigOption<>(
        "rocksdb.max_total_wal_size",
        "Total size of WAL files in bytes. Once WALs exceed this size, we will start forcing the flush of column families related, 0 means no limit.",
        rangeInt(0L, Long.MAX_VALUE),
        0L
    );
    
  6. DB_MEMTABLE_SIZE: Sets the total size of write buffers in bytes across all column families.

    public static final ConfigOption<Long> DB_MEMTABLE_SIZE = new ConfigOption<>(
        "rocksdb.db_write_buffer_size",
        "Total size of write buffers in bytes across all column families, 0 means no limit.",
        rangeInt(0L, Long.MAX_VALUE),
        0L
    );
    
  7. MEMTABLE_SIZE: Specifies the amount of data in bytes to build up in memory.

    public static final ConfigOption<Long> MEMTABLE_SIZE = new ConfigOption<>(
        "rocksdb.write_buffer_size",
        "Amount of data in bytes to build up in memory.",
        rangeInt(Bytes.MB, Long.MAX_VALUE),
        32L * Bytes.MB
    );
    
  8. MAX_MEMTABLES: Sets the maximum number of write buffers that are built up in memory.

    public static final ConfigOption<Integer> MAX_MEMTABLES = new ConfigOption<>(
        "rocksdb.max_write_buffer_number",
        "The maximum number of write buffers that are built up in memory.",
        rangeInt(1, Integer.MAX_VALUE),
        32
    );
    
  9. MIN_MEMTABLES_TO_MERGE: Specifies the minimum number of write buffers that will be merged together.

    public static final ConfigOption<Integer> MIN_MEMTABLES_TO_MERGE = new ConfigOption<>(
        "rocksdb.min_write_buffer_number_to_merge",
        "The minimum number of write buffers that will be merged together.",
        rangeInt(1, Integer.MAX_VALUE),
        16
    );
    
  10. MAX_MEMTABLES_TO_MAINTAIN: Sets the total maximum number of write buffers to maintain in memory.

    public static final ConfigOption<Integer> MAX_MEMTABLES_TO_MAINTAIN = new ConfigOption<>(
        "rocksdb.max_write_buffer_number_to_maintain",
        "The total maximum number of write buffers to maintain in memory.",
        rangeInt(0, Integer.MAX_VALUE),
        0
    );
    
  11. LEVEL0_SLOWDOWN_WRITES_TRIGGER: Sets the soft limit on the number of level-0 files for slowing down writes.

    public static final ConfigOption<Integer> LEVEL0_SLOWDOWN_WRITES_TRIGGER = new ConfigOption<>(
        "rocksdb.level0_slowdown_writes_trigger",
        "Soft limit on number of level-0 files for slowing down writes.",
        rangeInt(-1, Integer.MAX_VALUE),
        256
    );
    
  12. LEVEL0_STOP_WRITES_TRIGGER: Sets the hard limit on the number of level-0 files for stopping writes.

    public static final ConfigOption<Integer> LEVEL0_STOP_WRITES_TRIGGER = new ConfigOption<>(
        "rocksdb.level0_stop_writes_trigger",
        "Hard limit on number of level-0 files for stopping writes.",
        rangeInt(-1, Integer.MAX_VALUE),
        1024
    );
    
  13. MAX_BG_JOBS: Sets the maximum number of background jobs (compactions and flushes).

    public static final ConfigOption<Integer> MAX_BG_JOBS = new ConfigOption<>(
        "rocksdb.max_background_jobs",
        "The maximum number of background jobs (compactions and flushes).",
        rangeInt(1, Integer.MAX_VALUE),
        8
    );
    
  14. MAX_OPEN_FILES: Sets the maximum number of open files that can be used by the database.

    public static final ConfigOption<Integer> MAX_OPEN_FILES = new ConfigOption<>(
        "rocksdb.max_open_files",
        "The maximum number of open files that can be used by the database.",
        rangeInt(-1, Integer.MAX_VALUE),
        1024
    );
    
  15. DELETE_OBSOLETE_FILE_PERIOD: Sets the period in seconds to delete obsolete files.

    public static final ConfigOption<Long> DELETE_OBSOLETE_FILE_PERIOD = new ConfigOption<>(
        "rocksdb.delete_obsolete_files_period",
        "The period in seconds to delete obsolete files.",
        rangeInt(0L, Long.MAX_VALUE),
        6 * 3600L
    );
    
  16. NUM_LEVELS: Sets the number of levels for the database.

    public static final ConfigOption<Integer> NUM_LEVELS = new ConfigOption<>(
        "rocksdb.num_levels",
        "Set the number of levels for this database.",
        rangeInt(1, Integer.MAX_VALUE),
        7
    );
    
  17. COMPACTION_STYLE: Sets the compaction style for RocksDB.

    public static final ConfigConvOption<String, CompactionStyle> COMPACTION_STYLE = new ConfigConvOption<>(
        "rocksdb.compaction_style",
        "Set compaction style for RocksDB: LEVEL/UNIVERSAL/FIFO.",
        allowValues("LEVEL", "UNIVERSAL", "FIFO"),
        CompactionStyle::valueOf,
        "LEVEL"
    );
    
  18. LEVELS_COMPRESSIONS: Sets the compression algorithms for different levels of RocksDB.

    public static final ConfigListConvOption<String, CompressionType> LEVELS_COMPRESSIONS = new ConfigListConvOption<>(
        "rocksdb.compression_per_level",
        "The compression algorithms for different levels of RocksDB, allowed values are none/snappy/z/bzip2/lz4/lz4hc/xpress/zstd.",
        inValues("none", "snappy", "z", "bzip2", "lz4", "lz4hc", "xpress", "zstd"),
        CompressionType::getCompressionType,
        "none", "none", "snappy", "snappy", "snappy", "snappy", "snappy"
    );
    
  19. BOTTOMMOST_COMPRESSION: Sets the compression algorithm for the bottommost level of RocksDB.

    public static final ConfigConvOption<String, CompressionType> BOTTOMMOST_COMPRESSION = new ConfigConvOption<>(
        "rocksdb.bottommost_compression",
        "The compression algorithm for the bottommost level of RocksDB, allowed values are none/snappy/z/bzip2/lz4/lz4hc/xpress/zstd.",
        allowValues("none", "snappy", "z", "bzip2", "lz4", "lz4hc", "xpress", "zstd"),
        CompressionType::getCompressionType,
        "none"
    );
    
  20. COMPRESSION: Sets the compression algorithm for compressing blocks of RocksDB.

    public static final ConfigConvOption<String, CompressionType> COMPRESSION = new ConfigConvOption<>(
        "rocksdb.compression",
        "The compression algorithm for compressing blocks of RocksDB, allowed values are none/snappy/z/bzip2/lz4/lz4hc/xpress/zstd.",
        allowValues("none", "snappy", "z", "bzip2", "lz4", "lz4hc", "xpress", "zstd"),
        CompressionType::getCompressionType,
        "snappy"
    );
    

These options allow fine-tuning of the read/write performance and behavior of the RocksDB storage engine used by HugeGraph [1][2][3].

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Sep 04 '24 13:09 dosubot[bot]