Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Kafka partition

Shulou Source: shulou.com Published: 2022-06-03 07:43:38 09月23日 Update

1. The function of introducing partition under topic:

Topic is a logical concept and partition is a physical concept.

For performance reasons, if the messages in the topic are stored in only one broker, then the broker will become a bottleneck and cannot scale horizontally. Kafka allocates partition to different servers in the cluster as much as possible through the algorithm.

Partition can also be understood as the encapsulation of segment. One partition corresponds to multiple segment. A segment contains a data file and an index file

Second, kafka partition allocation strategy:

Partition.assignment.strategy= range (default) or roundrobin

Range strategy: sort by partition order, consumers by alphabetical order.

The number of partitions divided by the total number of consumer threads determines how many partitions each consumer thread consumes. If not, the first few consumer threads will consume an extra partition.

Suppose there are 3 consumers and 11 divisions.

C1-0 will consume 0, 1, 2, 3 zones

C1-2 will consume 4, 5, 6, 7 zones

C1-3 will consume 8, 9, 10 zones

Roundrobin strategy: partitions are sorted by hashcode, consumers are sorted alphabetically

Suppose there are 3 consumers and 11 divisions.

C1-0 will consume 0, 3, 6, 9 zones

C1-2 will consume 1, 4, 7, 10 zones

C1-3 will consume 2, 5, 8 zones

Note:

1. A partition can only be consumed by one consumer, but a consumer can consume data from multiple partitions.

2. The new api reserves the possibility of implementing the allocation policy class org.apache.kafka.clients.consumer.RangeAssignor.

3. Zone modification. / kafka-topics.sh-- alter-- topic topic1-- zookeeper zkip:2181/kafka-- partitions 6

Tags: Consumption consumer policy sorting threading allocation multiple letter data file concept different number function possibility as far as possible performance total server level Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information macOS Redmi Huawei Shulou Technology