Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use tcpKeepaliveListener and reuseport together #1320

Open
hawell opened this issue Jun 14, 2022 · 3 comments
Open

use tcpKeepaliveListener and reuseport together #1320

hawell opened this issue Jun 14, 2022 · 3 comments

Comments

@hawell
Copy link

hawell commented Jun 14, 2022

I need the functionality of both tcpKeepaliveListener and reuseport.
something like this:

func ListenAndServe() error {
	s := &fasthttp.Server{
		Handler: handler,
		TCPKeepalive: true,
		TCPKeepalivePeriod: 30 * time.Second,
	}
	ln, err := reuseport.Listen("tcp4", ":8080")
	if err != nil {
		return err
	}
	if tcpln, ok := ln.(*net.TCPListener); ok {
		return s.Serve(tcpKeepaliveListener{
			TCPListener:     tcpln,
			keepalive:       s.TCPKeepalive,
			keepalivePeriod: s.TCPKeepalivePeriod,
		})
	}
	return s.Serve(ln)
}

is there a reason why tcpKeepaliveListener is private?
is there another way to have both functionalities that I'm missing here?
thanks a lot

@erikdubbelboer
Copy link
Collaborator

erikdubbelboer commented Jun 14, 2022

I think it would make more sense if Server.Serve() does what tcpKeepaliveListener does. I would accept a pull request to change this as I currently don't have time to fix this myself.

@stokito
Copy link
Contributor

stokito commented Sep 24, 2022

@erikdubbelboer could you please tell me if I should use the reuseport?
I have a heavy loaded OpenRtb service with huge QPS of short requests that are processed in subsecond.
I can't understand if the reuseport is great then why it's not used by default?
What are cons?

@erikdubbelboer
Copy link
Collaborator

erikdubbelboer commented Sep 24, 2022

If you have to ask if you should use reuseport then you don't need to. This is only for really specific cases where you have multiple processes listening on the same port.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants