Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

chore(concurrency): sleep if there are no tasks #1991

Merged
merged 1 commit into from
Jun 25, 2024

Conversation

Yoni-Starkware
Copy link
Collaborator

@Yoni-Starkware Yoni-Starkware commented Jun 17, 2024

This change is Reviewable

@codecov-commenter
Copy link

codecov-commenter commented Jun 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.45%. Comparing base (c3267c0) to head (db34c50).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1991   +/-   ##
=======================================
  Coverage   78.45%   78.45%           
=======================================
  Files          62       62           
  Lines        8970     8970           
  Branches     8970     8970           
=======================================
  Hits         7037     7037           
  Misses       1486     1486           
  Partials      447      447           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@avi-starkware
Copy link
Collaborator

I don't like using None. It is vague, and it messes up some of the types. When do we want it to be None and when Task::NoTask? Why not use something descriptive?

I propose adding Task::Wait. Task::Wait will trigger the sleep, and Task::NoTask will immediately ask for another task.

@avi-starkware
Copy link
Collaborator

crates/blockifier/src/concurrency/scheduler_test.rs line 219 at r1 (raw file):

#[case::returns_execution_task(0, 10, true)]
#[case::does_not_return_execution_task(10, 0, true)]
fn test_finish_validation(

I renamed the method but forgot to rename the corresponding test.

Suggestion:

fn test_finish_abort(

@avi-starkware
Copy link
Collaborator

crates/blockifier/src/concurrency/scheduler_test.rs line 247 at r1 (raw file):

            assert_eq!(*new_status, TransactionStatus::Executed);
        }
    }

Suggestion:

    let scheduler =
        default_scheduler!(chunk_size: DEFAULT_CHUNK_SIZE, execution_index: execution_index);
    scheduler.set_tx_status(tx_index, TransactionStatus::Executed);
    let mut result = None;
    result = scheduler.finish_abort(tx_index);
    let new_status = scheduler.lock_tx_status(tx_index);
    if execution_index > tx_index {
        assert_eq!(result, Some(Task::ExecutionTask(tx_index)));
        assert_eq!(*new_status, TransactionStatus::Executing);
    } else {
        assert!(result.is_none());
        assert_eq!(*new_status, TransactionStatus::ReadyToExecute);
    }

@avi-starkware
Copy link
Collaborator

crates/blockifier/src/concurrency/scheduler_test.rs line 247 at r1 (raw file):

            assert_eq!(*new_status, TransactionStatus::Executed);
        }
    }

Oops, the status should be TransactionStatus::Aborting.

Copy link
Collaborator

@avi-starkware avi-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 4 files reviewed, 4 unresolved discussions (waiting on @noaov1 and @Yoni-Starkware)


crates/blockifier/src/concurrency/scheduler_test.rs line 216 at r1 (raw file):

#[rstest]
#[case::not_aborted(0, 10, false)]

We no longer have the not aborted flow inside this method (if it's not aborted we simply don't call the method).

Here's a PR that fixes this test, in case you don't want all these changes in your PR:
#1993


crates/blockifier/src/concurrency/scheduler_test.rs line 219 at r1 (raw file):

Previously, avi-starkware wrote…

I renamed the method but forgot to rename the corresponding test.

Here's a PR that fixes this test, in case you don't want all these changes in your PR:
#1993


crates/blockifier/src/concurrency/scheduler_test.rs line 222 at r1 (raw file):

    #[case] tx_index: TxIndex,
    #[case] execution_index: TxIndex,
    #[case] aborted: bool,

We no longer have the not aborted flow inside this method (if it's not aborted we simply don't call the method).

Here's a PR that fixes this test, in case you don't want all these changes in your PR:
#1993


crates/blockifier/src/concurrency/scheduler_test.rs line 247 at r1 (raw file):

Previously, avi-starkware wrote…

Oops, the status should be TransactionStatus::Aborting.

Here's a PR that fixes this test, in case you don't want all these changes in your PR:
#1993

Copy link
Collaborator Author

@Yoni-Starkware Yoni-Starkware left a comment

Choose a reason for hiding this comment

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

None means that you're not holding any task and you need to query the scheduler.
NoTask means that there are no pending tasks at all (and you can go to sleep).
I needed to distinguish between these cases because I didn't want to sleep, for example, after every execute.

Not sure I like Wait, it's too specific - it describes what you do if there are no tasks. I can do nothing or call spin_loop for example

But I agree it's not ideal.I'll think

Reviewable status: 0 of 4 files reviewed, 4 unresolved discussions (waiting on @noaov1)

Copy link
Collaborator Author

@Yoni-Starkware Yoni-Starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 4 files reviewed, 4 unresolved discussions (waiting on @avi-starkware and @noaov1)


crates/blockifier/src/concurrency/scheduler_test.rs line 216 at r1 (raw file):

Previously, avi-starkware wrote…

We no longer have the not aborted flow inside this method (if it's not aborted we simply don't call the method).

Here's a PR that fixes this test, in case you don't want all these changes in your PR:
#1993

Done.


crates/blockifier/src/concurrency/scheduler_test.rs line 219 at r1 (raw file):

Previously, avi-starkware wrote…

Here's a PR that fixes this test, in case you don't want all these changes in your PR:
#1993

Done.


crates/blockifier/src/concurrency/scheduler_test.rs line 222 at r1 (raw file):

Previously, avi-starkware wrote…

We no longer have the not aborted flow inside this method (if it's not aborted we simply don't call the method).

Here's a PR that fixes this test, in case you don't want all these changes in your PR:
#1993

Done.


crates/blockifier/src/concurrency/scheduler_test.rs line 247 at r1 (raw file):

Previously, avi-starkware wrote…

Here's a PR that fixes this test, in case you don't want all these changes in your PR:
#1993

Done.

Copy link
Collaborator Author

@Yoni-Starkware Yoni-Starkware left a comment

Choose a reason for hiding this comment

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

@avi-starkware I changed it a bit, WDYT?

Reviewable status: 0 of 4 files reviewed, all discussions resolved (waiting on @noaov1)

@avi-starkware
Copy link
Collaborator

I understood your usage of None and Task::NoTask after looking at how you use it in the code. My question was rhetorical - I meant to say that someone seeing this code for the first time will have a hard time understanding the distinction between the two.

Copy link
Collaborator Author

@Yoni-Starkware Yoni-Starkware left a comment

Choose a reason for hiding this comment

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

finish_abort can only return a re-execution task, so using option there is not so bad IMO
I can also change validate to return a boolean, something like this

                    if let Some(re_execute_task) = self.validate(tx_index) {
                        task = re_execute_task;
                        continue;
                    }

==>>

                    let should_re_execute = self.validate(tx_index) {
                    if should_re_execute {
                        task = Task::ExecuteTask(tx_index);
                        continue;
                    }

Reviewable status: 0 of 4 files reviewed, all discussions resolved (waiting on @noaov1)

@avi-starkware
Copy link
Collaborator

How about something like:
1.Task::GetNextTask/ Task::AskForTask / Task::GetTask / Task::Empty
2. Task::NoTaskAvailable / Task::NoneAvailable / Task::Pending
This will make it clear what each is supposed to mean, with no prescribed wait.
I like it when all options are enum members, because it makes it so that each member clearly occupies a single match arm. With None, the flow of a match arm splits into cases, making it less clean.

Also, note that when we add dependencies, execute will also return a task in some cases, making the if let Some appear twice in the worker loop...

Copy link
Collaborator Author

@Yoni-Starkware Yoni-Starkware left a comment

Choose a reason for hiding this comment

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

Good point, thanks.
Done (cc @noaov1)

Reviewable status: 0 of 4 files reviewed, all discussions resolved (waiting on @noaov1)

@Yoni-Starkware Yoni-Starkware force-pushed the yoni/worker/sleep-when-no-task branch 2 times, most recently from 240a886 to f52883d Compare June 19, 2024 03:55
avi-starkware
avi-starkware previously approved these changes Jun 24, 2024
Copy link
Collaborator

@avi-starkware avi-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 4 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @noaov1)

@avi-starkware
Copy link
Collaborator

crates/blockifier/src/concurrency/scheduler.rs line 105 at r5 (raw file):

        }

        Task::NoTaskAvailable

This case will usually mean that the status of the transaction wasn't right for Execution/Validation.

Suggestion:

Task::AskForTask

@avi-starkware
Copy link
Collaborator

crates/blockifier/src/concurrency/scheduler_test.rs line 61 at r5 (raw file):

    0,
    TransactionStatus::ReadyToExecute,
    Task::NoTaskAvailable

Suggestion:

    Task::AskForTask

Copy link
Collaborator Author

@Yoni-Starkware Yoni-Starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @avi-starkware and @noaov1)


crates/blockifier/src/concurrency/scheduler.rs line 105 at r5 (raw file):

Previously, avi-starkware wrote…

This case will usually mean that the status of the transaction wasn't right for Execution/Validation.

This means that there is no task available, and we should wait, right?

@avi-starkware
Copy link
Collaborator

crates/blockifier/src/concurrency/scheduler.rs line 105 at r5 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

This means that there is no task available, and we should wait, right?

When we reach this line, it is usually because the transaction's status at the execution_index is not ReadyToExecute.

Copy link
Collaborator Author

@Yoni-Starkware Yoni-Starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @avi-starkware and @noaov1)


crates/blockifier/src/concurrency/scheduler.rs line 105 at r5 (raw file):

Previously, avi-starkware wrote…

When we reach this line, it is usually because the transaction's status at the execution_index is not ReadyToExecute.

Done.

Copy link
Collaborator Author

@Yoni-Starkware Yoni-Starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 5 files reviewed, 3 unresolved discussions (waiting on @avi-starkware and @noaov1)


crates/blockifier/src/concurrency/scheduler.rs line 95 at r6 (raw file):

        let index_to_execute = self.execution_index.load(Ordering::Acquire);

        if min(index_to_validate, index_to_execute) >= self.chunk_size {

@barak-b-starkware FYI: I restored this check in order to know when to stop the busy loop

Copy link
Collaborator

@avi-starkware avi-starkware left a comment

Choose a reason for hiding this comment

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

Reviewed 5 of 5 files at r6, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @noaov1)

@Yoni-Starkware Yoni-Starkware merged commit 001940a into main Jun 25, 2024
9 checks passed
@Yoni-Starkware Yoni-Starkware deleted the yoni/worker/sleep-when-no-task branch June 25, 2024 06:28
gswirski pushed a commit to reilabs/blockifier that referenced this pull request Jun 26, 2024
Co-authored-by: glihm <glihm@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants