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 default scheduler port for LocalCluster #8760

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions distributed/cli/dask_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
enable_proctitle_on_children,
enable_proctitle_on_current,
)
from distributed.scheduler import DEFAULT_SCHEDULER_PORT

logger = logging.getLogger("distributed.scheduler")

Expand Down Expand Up @@ -165,9 +166,9 @@ def main(

if port is None and (not host or not re.search(r":\d", host)):
if isinstance(protocol, list):
port = [8786] + [0] * (len(protocol) - 1)
port = [DEFAULT_SCHEDULER_PORT] + [0] * (len(protocol) - 1)
else:
port = 8786
port = DEFAULT_SCHEDULER_PORT

if isinstance(protocol, list) or isinstance(port, list):
if (not isinstance(protocol, list) or not isinstance(port, list)) or len(
Expand Down
3 changes: 2 additions & 1 deletion distributed/cli/dask_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import click

from distributed.deploy.old_ssh import SSHCluster
from distributed.scheduler import DEFAULT_SCHEDULER_PORT

logger = logging.getLogger("distributed.dask_ssh")

Expand All @@ -30,7 +31,7 @@
)
@click.option(
"--scheduler-port",
default=8786,
default=DEFAULT_SCHEDULER_PORT,
show_default=True,
type=int,
help="Specify scheduler port number.",
Expand Down
33 changes: 26 additions & 7 deletions distributed/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,13 +717,32 @@ async def listen(self, port_or_addr=None, allow_offload=True, **kwargs):
else:
addr = port_or_addr
assert isinstance(addr, str)
listener = await listen(
addr,
self.handle_comm,
deserialize=self.deserialize,
allow_offload=allow_offload,
**kwargs,
)
try:
listener = await listen(
addr,
self.handle_comm,
deserialize=self.deserialize,
allow_offload=allow_offload,
**kwargs,
)
except OSError:
fallback_port_or_addr = kwargs.get("fallback_port_or_addr", None)
if not fallback_port_or_addr:
raise
warnings.warn(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is what causes the test distributed/deploy/tests/test_local.py::test_Client_twice to fail, if I just comment the warning, it passes. Should I remove the warning, change it to logger invocation instead, or is there some means of making the test accept a warning occurrence?

f"Address {addr} is already in use.\n"
f"Falling back to {fallback_port_or_addr} instead",
UserWarning,
stacklevel=2,
)
listener = await listen(
fallback_port_or_addr,
self.handle_comm,
deserialize=self.deserialize,
allow_offload=allow_offload,
**kwargs,
)

self.listeners.append(listener)

def handle_comm(self, comm: Comm) -> NoOpAwaitable:
Expand Down
2 changes: 1 addition & 1 deletion distributed/deploy/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def __init__(
start=None,
host=None,
ip=None,
scheduler_port=0,
scheduler_port=None,
silence_logs=logging.WARN,
dashboard_address=":8787",
worker_dashboard_address=None,
Expand Down
20 changes: 17 additions & 3 deletions distributed/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@
"stealing": WorkStealing,
}

DEFAULT_SCHEDULER_PORT = 8786


class ClientState:
"""A simple object holding information about a client."""
Expand Down Expand Up @@ -3674,7 +3676,6 @@ class Scheduler(SchedulerState, ServerNode):
Time we expect certain functions to take, e.g. ``{'sum': 0.25}``
"""

default_port = 8786
_instances: ClassVar[weakref.WeakSet[Scheduler]] = weakref.WeakSet()

worker_ttl: float | None
Expand Down Expand Up @@ -3785,8 +3786,18 @@ def __init__(
interface=interface,
protocol=protocol,
security=security,
default_port=self.default_port,
default_port=DEFAULT_SCHEDULER_PORT,
)
if port is None:
self._fallback_start_addresses = addresses_from_user_args(
host=host,
port=0,
interface=interface,
protocol=protocol,
security=security,
)
else:
self._fallback_start_addresses = []

http_server_modules = dask.config.get("distributed.scheduler.http.routes")
show_dashboard = dashboard or (dashboard is None and dashboard_address)
Expand Down Expand Up @@ -4199,11 +4210,14 @@ async def start_unsafe(self) -> Self:

self._clear_task_state()

for addr in self._start_address:
for addr, fallback_addr in itertools.zip_longest(
self._start_address, self._fallback_start_addresses
):
await self.listen(
addr,
allow_offload=False,
handshake_overrides={"pickle-protocol": 4, "compression": None},
fallback_port_or_addr=fallback_addr,
**self.security.get_listen_args("scheduler"),
)
self.ip = get_address_host(self.listen_address)
Expand Down
3 changes: 2 additions & 1 deletion distributed/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
from distributed.node import ServerNode
from distributed.proctitle import enable_proctitle_on_children
from distributed.protocol import deserialize
from distributed.scheduler import DEFAULT_SCHEDULER_PORT
from distributed.scheduler import TaskState as SchedulerTaskState
from distributed.security import Security
from distributed.utils import (
Expand Down Expand Up @@ -2480,7 +2481,7 @@ def _bind_port(port):
s.listen(1)
yield s

default_ports = [8786]
default_ports = [DEFAULT_SCHEDULER_PORT]

while time() - start < _TEST_TIMEOUT:
try:
Expand Down
Loading