Skip to content

Commit

Permalink
Separate default timeout from max timeout.
Browse files Browse the repository at this point in the history
Ensure that environment variables are cast to integers.
Increase max timeout (for now) for get_ursulas/bucket_sampling.
  • Loading branch information
derekpierre committed Sep 9, 2024
1 parent 69a35e2 commit 8224acc
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions porter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,25 @@ class Porter(Learner):

DEFAULT_PORT = 9155

MAX_GET_URSULAS_TIMEOUT = os.getenv("PORTER_MAX_GET_URSULAS_TIMEOUT", default=30)
MAX_BUCKET_SAMPLING_TIMEOUT = os.getenv(
"PORTER_MAX_BUCKET_SAMPLING_TIMEOUT", default=30
DEFAULT_GET_URSULAS_TIMEOUT = int(
os.getenv("PORTER_DEFAULT_GET_URSULAS_TIMEOUT", default=15)
)
MAX_DECRYPTION_TIMEOUT = os.getenv(
"PORTER_MAX_DECRYPTION_TIMEOUT",
default=ThresholdDecryptionClient.DEFAULT_DECRYPTION_TIMEOUT,
MAX_GET_URSULAS_TIMEOUT = int(
os.getenv("PORTER_MAX_GET_URSULAS_TIMEOUT", default=30)
)

DEFAULT_BUCKET_SAMPLING_TIMEOUT = int(
os.getenv("PORTER_DEFAULT_GET_URSULAS_TIMEOUT", default=25)
)
MAX_BUCKET_SAMPLING_TIMEOUT = int(
os.getenv("PORTER_MAX_BUCKET_SAMPLING_TIMEOUT", default=45)
)

MAX_DECRYPTION_TIMEOUT = int(
os.getenv(
"PORTER_MAX_DECRYPTION_TIMEOUT",
default=ThresholdDecryptionClient.DEFAULT_DECRYPTION_TIMEOUT,
)
)

_interface_class = PorterInterface
Expand Down Expand Up @@ -182,7 +194,9 @@ def get_ursulas(
min_version: Optional[str] = None,
) -> List[UrsulaInfo]:
timeout = self._configure_timeout(
"sampling", timeout, self.MAX_GET_URSULAS_TIMEOUT
"sampling",
timeout or self.DEFAULT_GET_URSULAS_TIMEOUT,
self.MAX_GET_URSULAS_TIMEOUT,
)
duration = duration or 0
parse_min_version = parse(min_version) if min_version else None
Expand Down Expand Up @@ -328,7 +342,9 @@ def bucket_sampling(
min_version: Optional[str] = None,
) -> Tuple[List[ChecksumAddress], int]:
timeout = self._configure_timeout(
"bucket_sampling", timeout, self.MAX_BUCKET_SAMPLING_TIMEOUT
"bucket_sampling",
timeout or self.DEFAULT_BUCKET_SAMPLING_TIMEOUT,
self.MAX_BUCKET_SAMPLING_TIMEOUT,
)
duration = duration or 0
parse_min_version = parse(min_version) if min_version else None
Expand Down Expand Up @@ -473,7 +489,7 @@ def make_sure_ursula_is_online(ursula_address) -> ChecksumAddress:
)

# TODO determine "best" value here without env var or parameterize
stagger_timeout = os.getenv("PORTER_STAGGER_TIMEOUT", default=1)
stagger_timeout = int(os.getenv("PORTER_STAGGER_TIMEOUT", default=1))

worker_pool = WorkerPool(
worker=make_sure_ursula_is_online,
Expand Down

0 comments on commit 8224acc

Please sign in to comment.