perf: allow concurrent dataset pushes by narrowing the push-path locks - #1079
Draft
vdusek wants to merge 2 commits into
Draft
perf: allow concurrent dataset pushes by narrowing the push-path locks#1079vdusek wants to merge 2 commits into
vdusek wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1079 +/- ##
==========================================
+ Coverage 91.83% 92.06% +0.22%
==========================================
Files 51 51
Lines 3235 3237 +2
==========================================
+ Hits 2971 2980 +9
+ Misses 264 257 -7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Concurrent pushes to a dataset were serialized end to end, so N concurrent pushes cost N API round-trips instead of overlapping. Two locks were wrapping the network I/O, and because either one alone is enough to serialize, both had to be narrowed for the win to materialize:
Actor.push_datatookcharging_manager.charge_lock()unconditionally and held it acrossawait dataset.push_data(...).ApifyDatasetClient.push_dataadditionally held its per-client_lockacross the chunkedpush_itemscalls.The charge lock exists to keep the limit reservation and the charge that acts on it atomic, which can only matter for pay-per-event runs.
ApifyDatasetClient.push_datamutates no client state at all -_check_and_serializeis a classmethod,_chunk_by_sizeonly uses locals, andpush_itemsis a stateless API call - so outside of charging there is nothing for either lock to protect.Both call sites now go through a single
charge_lock_if_charging()helper in_charging.py, keyed offcharging_manager_ctx. That replaces the near-duplicateDatasetClientPpeMixin._charge_lockand the second, divergentis_pay_per_eventpredicate, so the "do we need the lock?" decision lives in one place for all three call sites. Pay-per-event runs are unchanged and still fully serialized.Two behavior notes:
ApifyDatasetClientpushes anddrop()are no longer mutually exclusive. The lock only ever ordered them within a single client instance in a single process, so a concurrent drop was never actually safe;_lockstill serializesdrop()itself.FileSystemDatasetClient._lock, which guards sequential item numbering and metadata. That lock is load-bearing and there is no network round-trip behind it.Regression tests at both layers, each verified to fail on
master:test_concurrent_push_data_overlapsputs a barrier inside the mockedpush_itemsand proves the API calls now overlap, andtest_push_data_does_not_take_charge_lock_without_pay_per_eventpins theActor.push_datahalf.test_concurrent_actor_push_data_stays_within_budgetguards the opposite direction - it fails if the charge lock is ever skipped for pay-per-event runs.✍️ Drafted by Claude Code