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

Minimize scope of expensive lock #30679

Merged
merged 6 commits into from
Mar 20, 2024
Merged
Changes from 2 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
14 changes: 10 additions & 4 deletions sdks/python/apache_beam/runners/worker/sdk_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,12 +607,18 @@ def _schedule_periodic_shutdown(self):
# type: () -> None
def shutdown_inactive_bundle_processors():
# type: () -> None
inactive_descriptor_ids = []
cur_time = time.time()
damccorm marked this conversation as resolved.
Show resolved Hide resolved
with self._lock:
for descriptor_id, last_access_time in self.last_access_times.items():
if (time.time() - last_access_time >
# Shutdown can be expensive, keep out of lock
damccorm marked this conversation as resolved.
Show resolved Hide resolved
for descriptor_id, last_access_time in access_times:
damccorm marked this conversation as resolved.
Show resolved Hide resolved
if (cur_time - last_access_time >
DEFAULT_BUNDLE_PROCESSOR_CACHE_SHUTDOWN_THRESHOLD_S):
BundleProcessorCache._shutdown_cached_bundle_processors(
self.cached_bundle_processors[descriptor_id])
inactive_descriptor_ids.append(descriptor_id)

for descriptor_id in inactive_descriptor_ids:
BundleProcessorCache._shutdown_cached_bundle_processors(
self.cached_bundle_processors[descriptor_id])

self.periodic_shutdown = PeriodicThread(
DEFAULT_BUNDLE_PROCESSOR_CACHE_SHUTDOWN_THRESHOLD_S,
Expand Down
Loading