zoukankan      html  css  js  c++  java
  • Kafka 配置参数汇总及相关说明

    Kafka为broker,producer和consumer提供了很多的配置参数。 了解并理解这些配置参数对于我们使用kafka是非常重要的。
    本文列出了一些重要的配置参数。
    官方的文档 Configuration比较老了,很多参数有所变动, 有些名字也有所改变。我在整理的过程中根据0.8.2的代码也做了修正。

    Boker配置参数
    下表列出了Boker的重要的配置参数, 更多的配置请参考 kafka.server.KafkaConfig



    name 默认值 描述
    brokerid
    none
    每一个boker都有一个唯一的id作为它们的名字。 这就允许boker切换到别的主机/端口上, consumer依然知道
    enable.zookeeper
    true
    允许注册到zookeeper
    log.flush.interval.messages
    Long.MaxValue
    在数据被写入到硬盘和消费者可用前最大累积的消息的数量
    log.flush.interval.ms
    Long.MaxValue
    在数据被写入到硬盘前的最大时间
    log.flush.scheduler.interval.ms
    Long.MaxValue
    检查数据是否要写入到硬盘的时间间隔。
    log.retention.hours
    168
    控制一个log保留多长个小时
    log.retention.bytes
    -1
    控制log文件最大尺寸
    log.cleaner.enable
    false
    是否log cleaning
    log.cleanup.policy
    delete
    delete还是compat. 其它控制参数还包括log.cleaner.threads,log.cleaner.io.max.bytes.per.second,log.cleaner.dedupe.buffer.size,log.cleaner.io.buffer.size,log.cleaner.io.buffer.load.factor,log.cleaner.backoff.ms,log.cleaner.min.cleanable.ratio,log.cleaner.delete.retention.ms
    log.dir
    /tmp/kafka-logs
    指定log文件的根目录
    log.segment.bytes
    110241024*1024
    单一的log segment文件大小
    log.roll.hours
    24 * 7
    开始一个新的log文件片段的最大时间
    message.max.bytes
    1000000 + MessageSet.LogOverhead
    一个socket 请求的最大字节数
    num.network.threads
    3
    处理网络请求的线程数
    num.io.threads
    8
    处理IO的线程数
    background.threads
    10
    后台线程序
    num.partitions
    1
    默认分区数
    socket.send.buffer.bytes
    102400
    socket SO_SNDBUFF参数
    socket.receive.buffer.bytes
    102400
    socket SO_RCVBUFF参数
    zookeeper.connect
    localhost:2182/kafka
    指定zookeeper连接字符串, 格式如hostname:port/chroot。chroot是一个namespace
    zookeeper.connection.timeout.ms
    6000
    指定客户端连接zookeeper的最大超时时间
    zookeeper.session.timeout.ms
    6000
    连接zk的session超时时间
    zookeeper.sync.time.ms
    2000
    zk follower落后于zk leader的最长时间



    High-levelConsumer配置参数
    下表列出了high-level consumer的重要的配置参数。
    更多的配置请参考 kafka.consumer.ConsumerConfig
      
    name
      
    默认值
    描述
    groupid
    groupid
    一个字符串用来指示一组consumer所在的组
    socket.timeout.ms
    30000
    socket超时时间
    socket.buffersize
    64*1024
    socket receive  buffer
    fetch.size
    300 * 1024
    控制在一个请求中获取的消息的字节数。 这个参数在0.8.x中由fetch.message.max.bytes,fetch.min.bytes取代
    backoff.increment.ms
    1000
    这个参数避免在没有新数据的情况下重复频繁的拉数据。 如果拉到空数据,则多推后这个时间
    queued.max.message.chunks
    2
    high level  consumer内部缓存拉回来的消息到一个队列中。 这个值控制这个队列的大小
    auto.commit.enable
    true
    如果true,consumer定期地往zookeeper写入每个分区的offset
    auto.commit.interval.ms
    10000
    往zookeeper上写offset的频率
    auto.offset.reset
    largest
    如果offset出了返回,则 smallest: 自动设置reset到最小的offset. largest : 自动设置offset到最大的offset. 其它值不允许,会抛出异常.
    consumer.timeout.ms
    -1
    默认-1,consumer在没有新消息时无限期的block。如果设置一个正值, 一个超时异常会抛出
    rebalance.retries.max
    4
    rebalance时的最大尝试次数


    Producer配置参数
    下表列出了producer的重要的参数。
    更多的配置请参考 kafka.producer.ProducerConfig
      
    name
      
    默认值
    描述
    serializer.class
    kafka.serializer.DefaultEncoder
    必须实现kafka.serializer.Encoder接口,将T类型的对象encode成kafka message
    key.serializer.class
    serializer.class
    key对象的serializer类
    partitioner.class
    kafka.producer.DefaultPartitioner
    必须实现kafka.producer.Partitioner,根据Key提供一个分区策略
    producer.type
    sync
    指定消息发送是同步还是异步。异步asyc成批发送用kafka.producer.AyncProducer, 同步sync用kafka.producer.SyncProducer
    metadata.broker.list
    boker list
    使用这个参数传入boker和分区的静态信息,如host1:port1,host2:port2, 这个可以是全部boker的一部分
    compression.codec
    NoCompressionCodec
    消息压缩,默认不压缩
    compressed.topics
    null
    在设置了压缩的情况下,可以指定特定的topic压缩,为指定则全部压缩
    message.send.max.retries
    3
    消息发送最大尝试次数
    retry.backoff.ms
    300
    每次尝试增加的额外的间隔时间
    topic.metadata.refresh.interval.ms
    600000
    定期的获取元数据的时间。当分区丢失,leader不可用时producer也会主动获取元数据,如果为0,则每次发送完消息就获取元数据,不推荐。如果为负值,则只有在失败的情况下获取元数据。
    queue.buffering.max.ms
    5000
    在producer queue的缓存的数据最大时间,仅仅for asyc
    queue.buffering.max.message
    10000
    producer 缓存的消息的最大数量,仅仅for asyc
    queue.enqueue.timeout.ms
    -1
    0当queue满时丢掉,负值是queue满时block,正值是queue满时block相应的时间,仅仅for asyc
    batch.num.messages
    200
    一批消息的数量,仅仅for asyc
    request.required.acks
    0
    0表示producer毋须等待leader的确认,1代表需要leader确认写入它的本地log并立即确认,-1代表所有的备份都完成后确认。 仅仅for sync
    request.timeout.ms
    10000
    确认超时时间

    kafka.serializer.DefaultEncoder
    默认的这个Encoder事实上不做任何处理,接收到什么byte[]就返回什么byte[]:
    1. class DefaultEncoder(props: VerifiableProperties = null) extends Encoder[Array[Byte]] {
    2.   override def toBytes(value: Array[Byte]): Array[Byte] = value
    3. }
    复制代码

    NullEncoder则不管接收什么都返回null:
    1. class NullEncoder[T](props: VerifiableProperties = null) extends Encoder[T] {
    2.   override def toBytes(value: T): Array[Byte] = null
    3. }
    复制代码

    StringEncoder则返回字符串,默认UTF-8格式:
    1. class StringEncoder(props: VerifiableProperties = null) extends Encoder[String] {
    2.   val encoding =
    3.     if(props == null)
    4.       "UTF8"
    5.     else
    6.       props.getString("serializer.encoding", "UTF8")
    7.   override def toBytes(s: String): Array[Byte] =
    8.     if(s == null)
    9.       null
    10.     else
    11.       s.getBytes(encoding)
    12. }
    复制代码

    kafka.producer.DefaultPartitioner
    默认的分区函数为DefaultPartitioner,它根据key的hashcode与分区数取余,得到相应的分区。
    1. class DefaultPartitioner(props: VerifiableProperties = null) extends Partitioner {
    2.   private val random = new java.util.Random
    3.   def partition(key: Any, numPartitions: Int): Int = {
    4.     Utils.abs(key.hashCode) % numPartitions
    5.   }
    6. }
    复制代码

    但是如果key为null时会发送到哪个分区?在一定时间内往一个特定的分区发送,超过一定时间又会随机选择一个,请参考key为null时Kafka会将消息发送给哪个分区?.所以推荐你发送Kafka消息时总是指定一个key,以便消息能均匀的分到每个分区上。

    转载:http://www.aboutyun.com/thread-12211-1-1.html

     
  • 相关阅读:
    invalid byte 1 of 1-byte UTF-8 sequence
    MySQL的时间进位问题
    MyBatis返回主键
    No matching bean of type [xx] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency
    在eclipse中下载包含子模块(Submodules)的git项目
    ERWin & ERStudio图里的实线和虚线的含义[转]
    Win7玩游戏偶尔自动跳转到桌面的解决办法[转]
    SpringMVC静态资源处理[转]
    RocketMQ术语[转]
    手机收不到验证码
  • 原文地址:https://www.cnblogs.com/xtdxs/p/7117347.html
Copyright © 2011-2022 走看看