confluentinc / confluent-kafka-go

Confluent's Apache Kafka Golang client
Apache License 2.0
4.62k stars 657 forks source link

Small Produced Messages broken up amongst multipel TCP Packets #972

Closed stewartboyd119 closed 8 months ago

stewartboyd119 commented 1 year ago

Description

When producing messages using confluent-kafka-go, I've noticed that if my message's value (with no key and no headers) is 72 bytes and smaller that it is sent as 1 tcp packet to the broker. Above this it will be 2 or more. I don't see a similar behavior in the sarama library. This manifests as larger latencies. When my producer is deployed to our datacenter and communicates with the kafka broker in our datacenter, the 73 bytes message can take 40 ms to be acked as produced by the broker. The 72 byte message takes single milliseconds.

I'm looking for guidance, on why this split my be happening. Is it something in my control (by of config options), and why the sarama producer wouldn't see the same type of packet split.

How to reproduce

Produce a 72 byte message (or 73 byte message with the following snippet) and then monitor outgoing traffic to broker using wireShark (or any network packet inspector).

    var value []byte
    for i := 0; i < valSize; i++ {
        value = append(value, byte(i))
    }

    events := make(chan kafka.Event)
    err := s.kproducer.Produce(&kafka.Message{
        TopicPartition: kafka.TopicPartition{Topic: &topicName, Partition: kafka.PartitionAny},
        Value:          value,
    }, events)

Checklist

Please provide the following information:

milindl commented 1 year ago

Hi, this behaviour is rather anomalous. I can't reproduce it with the same settings, the break up into 2 packets happens at very high message sizes, ~30K bytes, in the latest v2.1.1.

Do you see similar behaviour locally, too @stewartboyd119 , or does it happen only on your datacenter machines?

I suspect there might be some network setting external to this library which might cause this, but then it should probably happen for sarama as well.

Does the same behaviour happen when socket.send.buffer.bytes is not set (and left with default value 0)?

Could you share pcaps or similar which we can look at? As well as debug logs for the application, setting "debug" key in the config to "broker".

milindl commented 8 months ago

Closing this - please reopen with the additional information attached and if this still persists. Thanks!