kafka partition and producer relationship - hadoop

I have a kafka cluster with three brokers and one topic with replication factor of three and three partitions. I can see that every broker has a copy of log for all partitions with the same size. There are two producers for this topic.
One day I reduced writing volume of one producer by half. Then I found that all three brokers' inbound traffic reduced which is expected, but only partition 1's leader node's out traffic reduced which I don't understand.
The partition leader's outbound traffic reduced because of replication. But each broker is the leader of one partition, why only one leader's outbound traffic reduced? Is it possible that the producer only writes content to one partition? while I don't think so.
Please help me explain it. The cluster is working fine now, but I need to understand it in case of potential problem.

Assuming you are using Default Partitioner for KafkaProducer, which means two events with the same key are guaranteed to be sent to the same partition.
From From Kafka Documentation
All reads and writes go to the leader of the partition and Followers
consume messages from the leader just as a normal Kafka consumer would
and apply them to their own log.
You could have reduced data ( from a producer) by skiping specific key or set of Keys, which could means no data to particular partition.
This answers why leader's outbound traffic reduced (No records for followers to consume)

Related

does clients get an acknowledgement after a etcd leader replicate data to all other nodes?

Etcd cluster elects a leader under Raft consensus algorithm. When a client sends a write request to the leader, It should write a log in its disk and replicate it to other followers. I am unsure if the client gets an acknowledgment from a leader after all followers replicate the data or after N/2 + 1 nodes replicate the data.
For example, let's say that there are three nodes in the Etcd cluster. Does the client get an acknowledgment after a leader and a follower(two nodes in total) replicate the data? or after all three nodes successfully replicate the data?
If the latter is correct, does it mean that it has more latency when the Etcd cluster has more nodes because the client waits until all nodes replicate the data?
What happens if one of the followers takes too long or fails to replicate it?
This is actually something I've researched previously in ETCD-14501.
It requires N/2+1 acknowledgements before returning to the client.
Does the client get an acknowledgment after a leader and a follower(two nodes in total) replicate the data?
Yes, exactly that.

How does kafka streams attempt to get the same partition for each kafka topic?

If I have multiple application instances, and I am joining two topics, then each instance must get the same partition in order to join on the data. At the same time, it must evenly distribute the partitions among the instances.
If I were to guess, I am thinking that it would randomly request a partition for the first topic, keep that in a context, then request the same partition for all other topics involved in the join?
Can anyone confirm?
When it comes to stream joins, it is best to have the underlying topics co-partitioned. That way you do not really have to thing about any strange behavior.
That means, as Kafka is by default partitioning the data by key, you would use the key that is used in your join condition as a key of the messages in the kafka topics. That way, together with the Range assignment strategy (partition.assignment.strategy) on Consumer side you will have an optimal join.
A required condition is to have the same amount of partitions in both topics.
Read more here.

kafka broker server uneven CPU utilization

We have 3 node of kafka cluster with around 32 topic and 400+ partition
spread across these servers. We have the load evenly distributed amongst
this partition however we are observing that 2 broker server are running
around >60% CPU where as the third one is running just abour 10%. How do we
ensure that all server are running smoothly? Do i need to reassing the
partition (kafka-reassign-parition cmd).
PS: The partition are evenly distributed across all the broker servers.
In some cases, this is a result of the way that individual consumer groups determine which partition to use within the __consumer_offsets topic.
On a high level, each consumer group updates only one partition within this topic. This often results in a __consumer_offsets topic with a highly uneven distribution of message rates.
It may be the case that:
You have a couple very heavy consumer groups, meaning they need to update the __consumer_offsets topic frequently. One of these groups uses a partition that has the 2nd broker as its leader. The other uses a partition that has the 3rd broker as its leader.
This would result in a significant amount of the CPU being utilized for updating this topic, and would only occur on the 2nd and 3rd brokers (as seen in your screenshot).
A detailed blog post is found here

Kafka partitions affect performance

Why do a large number of partitions affect performance of a Kafka cluster? What are the best practice to manage and monitor partitions? What is the best practice on partition count in a cluster?
The kafka controller is responsible to track and update the cluster status to all brokers in the cluster. The controller needs to do more work when the # of partition increases. The controller needs to broadcast kafka topic metadata information to all other brokers. A larger number of partitions means the controller needs to send more data through network.
The # of partitions that a cluster can host depends on the cluster settings. A cluster with more powerful hosts will be able to host more topic partitions. You can monitor # of partitions on your cluster, partition distribution among brokers, and the system metrics (CPU, I/O, network etc.) to see the # of partitions that fit for your setting. We have seen issues after hosting >4000 topic partitions on one host. Generally it is a good practice to keep # of partition replicas under 1000 per host. We can also check controller log to see if there is any topic metadata update failures.

what is difference between partition and replica of a topic in kafka cluster

What is difference between partition and replica of a topic in kafka cluster.
I mean both store the copies of messages in a topic. Then what is the real diffrence?
When you add the message to the topic, you call send(KeyedMessage message) method of the producer API. This means that your message contains key and value. When you create a topic, you specify the number of partitions you want it to have. When you call "send" method for this topic, the data would be sent to only ONE specific partition based on the hash value of your key (by default). Each partition may have a replica, which means that both partitions and its replicas store the same data. The limitation is that both your producer and consumer work only with the main replica and its copies are used only for redundancy.
Refer to the documentation: http://kafka.apache.org/documentation.html#producerapi
And a basic training: http://www.slideshare.net/miguno/apache-kafka-08-basic-training-verisign
Topics are partitioned across multiple nodes so a topic can grow beyond the limits of a node. Partitions are replicated for fault tolerance. Replication and leader takeover is one of the biggest difference between Kafka and other brokers/Flume. From the Apache Kafka site:
Each partition has one server which acts as the "leader" and zero or
more servers which act as "followers". The leader handles all read and
write requests for the partition while the followers passively
replicate the leader. If the leader fails, one of the followers will
automatically become the new leader. Each server acts as a leader for
some of its partitions and a follower for others so load is well
balanced within the cluster.
partition: each topic can be splitted up into partitions for load balancing (you could write into different partitions at the same time) & scalability (the topic can scale up without the instance limitations); within the same partition the records are ordered;
replica: for fault-tolerant durability mainly;
Quotes:
The partitions of the log are distributed over the servers in the Kafka cluster with each server handling data and requests for a share of the partitions. Each partition is replicated across a configurable number of servers for fault tolerance.
There is a quite intuitive tutorial to explain some fundamental concepts in Kafka: https://www.tutorialspoint.com/apache_kafka/apache_kafka_fundamentals.htm
Furthermore, there is a workflow to get you through the confusing jumgle: https://www.tutorialspoint.com/apache_kafka/apache_kafka_workflow.htm
Partitions
A topic consists of a bunch of buckets. Each such bucket is called a partition.
When you want to publish an item, Kafka takes its hash, and appends it into the appropriate bucket.
Replication Factor
This is the number of copies of topic-data you want replicated across the network.
In simple terms, partition is used for scalability and replication is for availability.
Kafka topics are divided into a number of partitions. Any record written to a particular topic goes to particular partition. Each record is assigned and identified by an unique offset. Replication is implemented at partition level. The redundant unit of topic partition is called replica. The logic that decides partition for a message is configurable. Partition helps in reading/writing data in parallel by splitting in different partitions spread over multiple brokers. Each replica has one server acting as leader and others as followers. Leader handles the read/write while followers replicate the data. In case leader fails, any one of the followers is elected as the leader.
Hope this explains!
Further Reading
Partitions store different data of the same type and
Yes, you can store the same message in different topic partitions but your consumers need to handle duplicated messages.
Replicas are a copy of these partitions in other servers.
Your number of replicas will be defined by the number of kafka brokers (servers) of your cluster
Example:
Let's suppose you have a Kafka cluster of 3 brokers and inside you have a topic with name AIRPORT_ARRIVALS that receives messages of Flight information and it has 3 partitions; partition 1 for flight arrivals from airline A, partition 2 from airline B, and partition 3 from airline C. All these messages will be initially written in one broker (leader) and a copy of each message will be stored/replicated to the other 2 Kafka broker (followers). Disclaimer; this example is only for an easier explanation and not an ideal way to define a message key because you could ending up with unbalanced load over specific partitions.
Partitions are the way that Kafka provides redundancy.
Kafka keeps more than one copy of the same partition across multiple brokers.
This redundant copy is called a Replica. If a broker fails, Kafka can still serve consumers with the replicas of partitions that failed broker owned

Resources