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

support reuse_port option when creating server #2679

Closed
hubo1016 opened this issue Jan 22, 2018 · 9 comments
Closed

support reuse_port option when creating server #2679

hubo1016 opened this issue Jan 22, 2018 · 9 comments

Comments

@hubo1016
Copy link
Contributor

@hubo1016 hubo1016 commented Jan 22, 2018

Python supports reuse_port socket option when creating server

https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.AbstractEventLoop.create_server

With reuse_port you can start multiple processes binding with the same port, easily creating a load-balanced server. While it is possible to start each process on different port, it can be done much easier with reuse_port option.

@asvetlov
Copy link
Member

@asvetlov asvetlov commented Jan 22, 2018

Could be done by adding reuse_port parameter to TCPSite and family.
reuse_address should be supported as well.

@pfreixes
Copy link
Contributor

@pfreixes pfreixes commented Jan 22, 2018

From my knowledge and tests reuse port is fundamentally broken for epoll

https://idea.popcount.org/2017-03-20-epoll-is-fundamentally-broken-22/

There is a flag that is available since kernel 4.5 that allows you to achieve the same behaviour. Also glibc has to be at least 2.24. Most of the distributions do not have it.

Also take into account that this is only appliable for new connections which have the worst code path in terms of performance. Most scenarios relay on long live conections to achieve maximum performance.

@hubo1016
Copy link
Contributor Author

@hubo1016 hubo1016 commented Jan 22, 2018

@pfreixes Execuse me, I didn't find any relationship between reuse_port option to the link.
The underlying create_server() call in Python asyncio supports this option, it should not be any problem to allow user to set it...

@pfreixes
Copy link
Contributor

@pfreixes pfreixes commented Jan 22, 2018

Because of that @hubo1016

With reuse_port you can start multiple processes binding with the same port, easily creating a load-balanced server. While it is possible to start each process on different port, it can be done much easier with reuse_port option.

@hubo1016
Copy link
Contributor Author

@hubo1016 hubo1016 commented Jan 23, 2018

@pfreixes As far as I know, reuse_port does not create duplicated sockets, it creates independent sockets binding on the same port. dup() issues should not be related to this I think?
After all, if underlying Python implementation supports it, then we should support it and leave the choices to users.

@asvetlov
Copy link
Member

@asvetlov asvetlov commented Jan 26, 2018

@hubo1016 please prepare a Pull Request

@hubo1016
Copy link
Contributor Author

@hubo1016 hubo1016 commented Jan 27, 2018

@asvetlov
OK, I will try

@asvetlov
Copy link
Member

@asvetlov asvetlov commented Jan 29, 2018

Fixed by #2693

@asvetlov asvetlov closed this Jan 29, 2018
@lock
Copy link

@lock lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.