Skip to content

Commit 08f01fa

Browse files
authored
Cache WorkerState host property (#9044)
1 parent a3509e6 commit 08f01fa

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

distributed/scheduler.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,16 @@
3232
)
3333
from contextlib import suppress
3434
from functools import partial
35-
from typing import TYPE_CHECKING, Any, ClassVar, Literal, NamedTuple, cast, overload
35+
from typing import (
36+
TYPE_CHECKING,
37+
Any,
38+
ClassVar,
39+
Final,
40+
Literal,
41+
NamedTuple,
42+
cast,
43+
overload,
44+
)
3645

3746
import psutil
3847
import tornado.web
@@ -413,7 +422,7 @@ class WorkerState:
413422

414423
#: This worker's unique key. This can be its connected address
415424
#: (such as ``"tcp://127.0.0.1:8891"``) or an alias (such as ``"alice"``).
416-
address: str
425+
address: Final[str]
417426

418427
pid: int
419428
name: Hashable
@@ -513,6 +522,9 @@ class WorkerState:
513522
#: on the worker.
514523
needs_what: dict[TaskState, int]
515524

525+
#: The hostname / IP address identifying the machine this worker is on.
526+
host: Final[str]
527+
516528
__slots__ = tuple(__annotations__)
517529

518530
def __init__(
@@ -564,6 +576,7 @@ def __init__(
564576
self.needs_what = {}
565577
self._network_occ = 0
566578
self._occupancy_cache = None
579+
self.host = get_address_host(self.address)
567580

568581
def __hash__(self) -> int:
569582
return self._hash
@@ -584,10 +597,6 @@ def has_what(self) -> Set[TaskState]:
584597
"""
585598
return self._has_what.keys()
586599

587-
@property
588-
def host(self) -> str:
589-
return get_address_host(self.address)
590-
591600
@property
592601
def memory(self) -> MemoryState:
593602
"""Polished memory metrics for the worker.

0 commit comments

Comments
 (0)