-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[worker] feat: add reusable port #4377
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -61,6 +61,15 @@ def _get_free_port(): | |||||||||||||||||||||||
| sock.bind(("", 0)) | ||||||||||||||||||||||||
| return sock.getsockname()[1] | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| @staticmethod | ||||||||||||||||||||||||
| def _get_reusable_free_port(): | ||||||||||||||||||||||||
| listen_sock: socket.socket = socket.socket() | ||||||||||||||||||||||||
| listen_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | ||||||||||||||||||||||||
| listen_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) | ||||||||||||||||||||||||
| listen_sock.bind(("", 0)) | ||||||||||||||||||||||||
| _, port, *_ = listen_sock.getsockname() | ||||||||||||||||||||||||
| return port | ||||||||||||||||||||||||
|
Comment on lines
+66
to
+71
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The socket
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you comment on Gemini's review?
burgerkingeater marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def get_availale_master_addr_port(self): | ||||||||||||||||||||||||
| warnings.warn( | ||||||||||||||||||||||||
| "This function is deprecated due to typo in name; Please use `get_available_master_addr_port` instead", | ||||||||||||||||||||||||
|
|
@@ -71,6 +80,9 @@ def get_availale_master_addr_port(self): | |||||||||||||||||||||||
| def get_available_master_addr_port(self): | ||||||||||||||||||||||||
| return self._get_node_ip().strip("[]"), str(self._get_free_port()) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def get_available_master_addr_reusable_port(self): | ||||||||||||||||||||||||
| return self._get_node_ip().strip("[]"), str(self._get_reusable_free_port()) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # we assume that in each WorkerGroup, there is a Master Worker | ||||||||||||||||||||||||
| class Worker(WorkerHelper): | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also need torch set
socket.SO_REUSEPORTflag when listening on MASTER_PORT.