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

Added support for no synchronization callbacks #1478

Merged
merged 27 commits into from
Oct 3, 2023
Merged

Conversation

Raalsky
Copy link
Contributor

@Raalsky Raalsky commented Sep 29, 2023

Before submitting checklist

  • Did you update the CHANGELOG? (not for test updates, internal changes/refactors or CI/CD setup)
  • Did you ask the docs owner to review all the user-facing changes?

@Raalsky Raalsky requested a review from normandy7 September 29, 2023 09:05
@codecov
Copy link

codecov bot commented Sep 29, 2023

Codecov Report

Attention: 16 lines in your changes are missing coverage. Please review.

Files Coverage Δ
src/neptune/envs.py 100.00% <100.00%> (ø)
src/neptune/internal/init/parameters.py 100.00% <100.00%> (ø)
...c/neptune/internal/operation_processors/factory.py 96.00% <100.00%> (+0.34%) ⬆️
src/neptune/metadata_containers/model.py 93.75% <100.00%> (-4.67%) ⬇️
src/neptune/metadata_containers/model_version.py 95.58% <100.00%> (+0.06%) ⬆️
src/neptune/metadata_containers/project.py 94.33% <100.00%> (-1.89%) ⬇️
src/neptune/metadata_containers/run.py 91.62% <100.00%> (-2.59%) ⬇️
src/neptune/typing.py 100.00% <100.00%> (+100.00%) ⬆️
src/neptune/internal/utils/__init__.py 79.16% <66.66%> (-4.71%) ⬇️
src/neptune/metadata_containers/abstract.py 73.91% <85.71%> (+1.69%) ⬆️
... and 3 more

... and 104 files with indirect coverage changes

📢 Thoughts on this report? Let us know!.

@Raalsky Raalsky changed the title Draft: Added support for no synchronization callbacks Added support for no synchronization callbacks Oct 2, 2023
src/neptune/metadata_containers/model.py Outdated Show resolved Hide resolved
src/neptune/metadata_containers/model.py Outdated Show resolved Hide resolved
def _get_callback(provided: Optional[NeptuneObjectCallback], env_name: str) -> Optional[NeptuneObjectCallback]:
if provided is not None:
return provided
if env_name in os.environ and os.getenv(env_name) == "TRUE":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can simplify it to just

if os.getenv(env_name, "") == "TRUE":

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Will do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

self._op_processor: OperationProcessor = get_operation_processor(
mode=mode,
container_id=self._id,
container_type=self.container_type,
backend=self._backend,
lock=self._lock,
flush_period=flush_period,
async_lag_callback=self._async_lag_callback_method,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async_lag_callback=partial(async_lag_callback, self) if async_lag_callback else None,
async_no_progress_callback=partial(async_no_progress_callback, self) if async_no_progress_callback else None,

?
Then we don't need those two additional methods _async_lag_callback_method, _async_no_progress_callback_method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I was even thinking about that 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

self._lag_exceeded = True

def _check_no_progress(self):
if self._should_call_no_progress_callback:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we rewrite it slightly so that it's less indented?

if not self._should_call_no_progress_callback:
    return
with self._lock:
    if self._should_call_no_progress_callback:
        self._async_no_progress_callback()
        self._should_call_no_progress_callback = False

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, is it necessary to check this condition twice?
if self._should_call_no_progress_callback

Copy link
Contributor Author

@Raalsky Raalsky Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is common pattern as lock acquiring is heavy operation: https://en.wikipedia.org/wiki/Double-checked_locking

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -107,6 +129,20 @@ def wait(self):
if not self._consumer.is_running():
raise NeptuneSynchronizationAlreadyStoppedException()

def _check_lag(self):
if not self._lag_exceeded and self._last_ack and monotonic() - self._last_ack > self._async_lag_threshold:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here a de-dent?

        if (
            self._lag_exceeded or 
            not self._last_ack or 
            monotonic() - self._last_ack <= self._async_lag_threshold
        ):
            return
        
        with self._lock:
            if not self._lag_exceeded:
                self._async_no_progress_callback()
                self._lag_exceeded = True

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you wish 😉

@AleksanderWWW
Copy link
Contributor

LGTM (just a few non-blocking styling questions)
Waiting for some tests 😜

@Raalsky Raalsky merged commit 463ce96 into master Oct 3, 2023
4 checks passed
@Raalsky Raalsky deleted the rj/async-callbacks branch October 3, 2023 06:57
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.

3 participants