confluent-kafka-go
confluent-kafka-go copied to clipboard
turn off Ack and Nagle?
Description
Is there a way to turn off Ack or Nagle (TCP_NODELAY) for TCP connections? https://chat.openai.com/share/dba5c438-7bcd-41ed-8d14-f7c61199e531
I guess it would affect both sides of transmission? or can it be one-way?
Here is how you do it with redis:
opt := &redis.Options{
Addr: "localhost:6379",
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
conn, err := net.DialTimeout(network, addr, 5*time.Second)
if err != nil {
return nil, err
}
tcpConn, ok := conn.(*net.TCPConn)
if !ok {
return nil, err // Optionally, replace with a more specific error
}
if err := tcpConn.SetNoDelay(true); err != nil {
return nil, err
}
return tcpConn, nil
},
}
and with RabbitMQ:
// CustomDialer connects to RabbitMQ using a custom net.Dialer to disable Nagle's algorithm.
func CustomDialer(pool *RabbitMQConnectionPool) (*amqp.Connection, error) {
//// custom dialer
dialer := &net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}
conn, err := amqp.DialConfig(pool.connString, amqp.Config{
Dial: func(network, addr string) (net.Conn, error) {
c, err := dialer.Dial(network, addr)
if err != nil {
return nil, err
}
// Assuming c is a *net.TCPConn, disable Nagle's algorithm.
if tcpConn, ok := c.(*net.TCPConn); ok {
if err := tcpConn.SetNoDelay(true); err != nil {
vbl.Stdout.WarnF("Failed to disable Nagle's algorithm: %v", err)
// Handle error or proceed, depending on your error handling strategy.
}
}
return c, nil
},
})
return conn, err
}
I am looking for a way to do this with Kafka as well
You either have to disable delayed ACK on the receiving side, or disable the nagle algorithm on the sending side.
For confluent-kafka-go you have to set socket.nagle.disable to true in the config passed to NewProducer to disable the nagle algorithm.