Kafka broker 写消息的过程

text 复制代码
Producer → Kafka Broker → Replication → Consumer
               |
          Partition chosen (by key or round-robin)
               |
          Message appended to end of log (commit log)

上面的流程是kafka 写操作的大体流程。

kafka 不会特意保留message 在内存中,而是直接写入了disk。

那么消费的时候,如果是最近 produced 的message,即使写入了disk,还是会保留在OS的page cache中。 OS page cache 即使是flush 到了disk,也不会被立刻清除,这个是OS 自己的机制。 所以consumer 读最近生产的消息的时候,还是可以从page cache中读取出来的,而不用从disk 中读取。

  1. Kafka Broker Receives the Message

    决定partition

  2. Message is Appended to a Partition Log

    The selected broker appends the message to the end of the partition log (a sequential write).

    Kafka writes messages to disk efficiently using write-ahead logs (WAL).

  3. Replication (for Fault Tolerance)

    Kafka waits for acknowledgments based on the producer's acks setting:

    acks=0: Producer doesn't wait.

    acks=1: Wait for leader only.

    acks=all: Wait for all replicas to acknowledge.

  4. Message is Made Available to Consumers

    Once the acks is fulfilled, it becomes available for consumers.

    Consumers read sequentially using offsets.

    Kafka keeps messages for a retention period (e.g., 7 days), regardless of whether they've been consumed.

相关推荐
韩楚风3 小时前
【参天引擎】事务生命周期 / MVCC / Undo / ACID / 分布式事务 功能域整体解析
数据库·分布式·mysql·架构·cantian
ACP广源盛139246256736 小时前
GSV6155@ACP# 搭配 AI 服务器、AI PC 完整适配方案
大数据·服务器·人工智能·分布式·单片机·嵌入式硬件
ZENERGY-众壹15 小时前
50MW分布式VPP接入实战:调度中心要求的1分钟频率如何不卡死API
运维·服务器·分布式·光伏运维
富士康质检员张全蛋15 小时前
Kafka的操作 生产消息
分布式·kafka
ClickHouseDB16 小时前
推出 CostBench:一个用于数据仓库成本性能的开放基准
大数据·分布式·spark
liulilittle16 小时前
麻将系统架构
服务器·网络·分布式·游戏·系统架构·通信
952361 天前
Redis - 应用
数据库·redis·分布式·缓存
衣乌安、1 天前
Redis 分布式锁与任务状态
数据库·redis·分布式
半夜修仙1 天前
RabbitMQ的推模式和拉模式
java·分布式·中间件·rabbitmq·github·java-rabbitmq
buligbulig1 天前
Hadoop环境安装和集群创建
大数据·hadoop·分布式