Skip to content

Record and expose SharedMemoryArray async deletion settings - #1493

Open
hparik11 wants to merge 6 commits into
google:mainfrom
hparik11:fix-1479-async-del-settings
Open

hparik11 wants to merge 6 commits into
google:mainfrom
hparik11:fix-1479-async-del-settings

Conversation

@hparik11

Copy link
Copy Markdown

Fixes #1479.

enable_async_del is process-wide and first-call-wins, but until now nothing recorded what was actually applied: the bound lived only as the initial value of a private semaphore, and a later call with different arguments returned silently and changed nothing. I ran into the same wall the issue describes while sizing shared memory for a prefetch pipeline, so here is a fix along the lines of the proposal in the issue.

What this does:

  • Adds a small frozen dataclass, AsyncDelSettings (num_threads, max_outstanding_requests), and a SharedMemoryArray.async_del_settings() classmethod that returns the settings in effect, or None while deletion is still synchronous. It is also exported from grain.multiprocessing.
  • enable_async_del now records the settings it applies, after the existing max(max_outstanding_requests, num_threads) normalization, under the lock it already takes, so the recorded bound is the bound actually in effect.
  • A later enable_async_del call with the same settings is a quiet no-op, same as today. A later call with different settings logs a warning through absl logging naming both the requested and the in-effect values, and leaves the first call's settings in place. I went with a warning rather than an exception because mp_prefetch calls enable_async_del(1) at every worker start, so raising there would break existing pipelines that enabled deletion earlier with their own bound.
  • _disable_async_del clears the recorded settings along with the pool and the semaphore.

Tests: six new cases in shared_memory_array_test.py covering no settings before the first enable, the settings recorded by the first enable, the recorded bound after it is raised to num_threads, a same-settings re-enable staying quiet, a conflicting re-enable warning and keeping the first settings, and the settings being cleared on disable. I ran the full file locally (after generating the proto bindings and building the extension the way setup.py does): with this change, all 18 tests pass. With only the source change reverted and the new tests kept, the six new tests fail and the 12 pre-existing tests still pass.

On the CLA: I have signed the Google Individual CLA and it is on file for my account, so that side is sorted. Happy to adjust the shape if you would prefer different names or a different signal for the conflicting call.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SharedMemoryArray: no way to read the async deletion bound in effect, and a later enable_async_del with another bound is silently ignored

1 participant