Giter Club home page Giter Club logo

Comments (2)

pascal-hofmann avatar pascal-hofmann commented on June 16, 2024 1

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.

from confluent-kafka-go.

amills-vibeirl avatar amills-vibeirl commented on June 16, 2024

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

from confluent-kafka-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.