Skip to content
This repository was archived by the owner on Oct 13, 2026. It is now read-only.
Merged
Changes from 1 commit
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
Next Next commit
fix: subtract time spent leasing from max snooze value
  • Loading branch information
acocuzzo committed Oct 28, 2022
commit 01f7ff4319508bc570dd8a335ffe2968102157b7
8 changes: 6 additions & 2 deletions google/cloud/pubsub_v1/subscriber/_protocol/leaser.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def maintain_leases(self) -> None:
repeats.
"""
while not self._stop_event.is_set():
start_time = time.time()
# Determine the appropriate duration for the lease. This is
# based off of how long previous messages have taken to ack, with
# a sensible default and within the ranges allowed by Pub/Sub.
Expand Down Expand Up @@ -204,11 +205,14 @@ def maintain_leases(self) -> None:
# We determine the appropriate period of time based on a random
# period between:
# minimum: MAX_BATCH_LATENCY (to prevent duplicate modacks being created in one batch)
# maximum: 90% of the deadline
# maximum: 90% of the deadline,
# minus the time spent since the start of this while loop.
# This maximum time attempts to prevent ack expiration before new lease modacks arrive at the server.
# This use of jitter (http://bit.ly/2s2ekL7) helps decrease contention in cases
# where there are many clients.
snooze = random.uniform(_MAX_BATCH_LATENCY, deadline * 0.9)
snooze = random.uniform(
_MAX_BATCH_LATENCY, (deadline * 0.9) - (start_time - time.time())
)
_LOGGER.debug("Snoozing lease management for %f seconds.", snooze)
self._stop_event.wait(timeout=snooze)

Expand Down
⌂ 换网址