zoukankan      html  css  js  c++  java
  • 配置 kafka 同步刷盘

    之前参加 rocketmq 的 meetup,台上有人讲,kafka 不支持同步刷盘,当时没太在意,今天抽空看了下代码:

    kafka 提供了配置参数来支持同步刷盘,和 rocktmq 的做法不同(4.7 的 rmq 在 sync_disk 模式,统一在 GroupCommitService 中刷盘,不阻塞 SendMessageProcessor 线程)

    kafka.log.Log#append

    看下代码片段就好,不深入讲

    // always update the last producer id map offset so that the snapshot reflects the current offset
    // even if there isn't any idempotent data being written
    producerStateManager.updateMapEndOffset(appendInfo.lastOffset + 1)
    
    // increment the log end offset
    updateLogEndOffset(appendInfo.lastOffset + 1)
    
    // update the first unstable offset (which is used to compute LSO)
    updateFirstUnstableOffset()
    
    trace(s"Appended message set with last offset: ${appendInfo.lastOffset}, " +
      s"first offset: ${appendInfo.firstOffset}, " +
      s"next offset: ${nextOffsetMetadata.messageOffset}, " +
      s"and messages: $validRecords")
    
    // 我们所需要的同步刷盘
    if (unflushedMessages >= config.flushInterval)
      flush()
    
    appendInfo

    再看下文档

    public static final String FLUSH_MESSAGES_INTERVAL_CONFIG = "flush.messages";
    public static final String FLUSH_MESSAGES_INTERVAL_DOC = "This setting allows specifying an interval at " +
        "which we will force an fsync of data written to the log. For example if this was set to 1 " +
        "we would fsync after every message; if it were 5 we would fsync after every five messages. " +
        "In general we recommend you not set this and use replication for durability and allow the " +
        "operating system's background flush capabilities as it is more efficient. This setting can " +
        "be overridden on a per-topic basis (see <a href="#topicconfigs">the per-topic configuration section</a>).";
    
    public static final String FLUSH_MS_CONFIG = "flush.ms";
    public static final String FLUSH_MS_DOC = "This setting allows specifying a time interval at which we will " +
        "force an fsync of data written to the log. For example if this was set to 1000 " +
        "we would fsync after 1000 ms had passed. In general we recommend you not set " +
        "this and use replication for durability and allow the operating system's background " +
        "flush capabilities as it is more efficient.";

    所以,可以通过 flush.messages 和 flush.ms 来配置刷盘策略

  • 相关阅读:
    MyBatis环境配置
    log4j配置不同的类多个日志文件
    Http协议头、代理
    Apache二级域名实现
    Flash Builder 4.7 完美破解
    网页设计方面,哪些中英文字体的组合能有好的视觉效果
    网页设计中最常用的字体
    sublime text 3 插件:package control
    大量实用工具类、开源包,该帖绝对值得你收藏!
    10个简化Web开发者工作的HTML5开发工具
  • 原文地址:https://www.cnblogs.com/allenwas3/p/12684443.html
Copyright © 2011-2022 走看看