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

Introduce InstalledSchedulerPool trait #33934

Merged
merged 7 commits into from
Nov 3, 2023

Conversation

ryoqun
Copy link
Member

@ryoqun ryoqun commented Oct 31, 2023

Problem

InstalledScheduler is expected to be backed by multiple threads. thus, it's desirable to be reused to avoid thread recreation cost.

Summary of Changes

introduce some pooling mechanism.

also, finished off all the doc comments.

note that this pr contains only the trait interface bits. the actual impl will be added by later pr.

extracted from: #33070

Comment on lines +48 to +93
/// Schedules, executes, and commits transactions under encapsulated implementation
///
/// The following chart illustrates the ownership/reference interaction between inter-dependent
/// objects across crates:
///
/// ```mermaid
/// graph TD
/// Bank["Arc#lt;Bank#gt;"]
///
/// subgraph solana-runtime
/// BankForks;
/// BankWithScheduler;
/// Bank;
/// LoadExecuteAndCommitTransactions(["load_execute_and_commit_transactions()"]);
/// SchedulingContext;
/// InstalledSchedulerPool{{InstalledSchedulerPool}};
/// InstalledScheduler{{InstalledScheduler}};
/// end
///
/// subgraph solana-unified-scheduler-pool
/// SchedulerPool;
/// PooledScheduler;
/// ScheduleExecution(["schedule_execution()"]);
/// end
///
/// subgraph solana-ledger
/// ExecuteBatch(["execute_batch()"]);
/// end
///
/// ScheduleExecution -. calls .-> ExecuteBatch;
/// BankWithScheduler -. dyn-calls .-> ScheduleExecution;
/// ExecuteBatch -. calls .-> LoadExecuteAndCommitTransactions;
/// linkStyle 0,1,2 stroke:gray,color:gray;
///
/// BankForks -- owns --> BankWithScheduler;
/// BankForks -- owns --> InstalledSchedulerPool;
/// BankWithScheduler -- refs --> Bank;
/// BankWithScheduler -- owns --> InstalledScheduler;
/// SchedulingContext -- refs --> Bank;
/// InstalledScheduler -- owns --> SchedulingContext;
///
/// SchedulerPool -- owns --> PooledScheduler;
/// SchedulerPool -. impls .-> InstalledSchedulerPool;
/// PooledScheduler -. impls .-> InstalledScheduler;
/// PooledScheduler -- refs --> SchedulerPool;
/// ```
Copy link
Member Author

Choose a reason for hiding this comment

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

fyi, this is rendered like this:

image

Comment on lines -1 to -2
//! Currently, there are only two things: minimal InstalledScheduler trait and an auxiliary type
//! called BankWithScheduler.. This file will be populated by later PRs to align with the filename.
Copy link
Member Author

Choose a reason for hiding this comment

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

:byebye:

@ryoqun ryoqun requested a review from apfitzge October 31, 2023 15:13
@ryoqun ryoqun changed the title Introduce InstalledSchedulerPool Introduce InstalledSchedulerPool trait Oct 31, 2023
Copy link

codecov bot commented Oct 31, 2023

Codecov Report

Merging #33934 (d4aee43) into master (136ab21) will decrease coverage by 0.1%.
Report is 5 commits behind head on master.
The diff coverage is 67.4%.

❗ Current head d4aee43 differs from pull request most recent head 5df66e0. Consider uploading reports for the commit 5df66e0 to get more accurate results

@@            Coverage Diff            @@
##           master   #33934     +/-   ##
=========================================
- Coverage    81.9%    81.9%   -0.1%     
=========================================
  Files         809      809             
  Lines      218241   218277     +36     
=========================================
+ Hits       178794   178806     +12     
- Misses      39447    39471     +24     

@ryoqun ryoqun requested a review from apfitzge November 1, 2023 04:17
apfitzge
apfitzge previously approved these changes Nov 2, 2023
Copy link
Contributor

@apfitzge apfitzge left a comment

Choose a reason for hiding this comment

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

lgtm - appreciate you breaking up the big PR into smaller pieces, which makes it significantly easier to review.

@@ -27,6 +100,9 @@ use {mockall::automock, qualifier_attr::qualifiers};
allow(unused_attributes, clippy::needless_lifetimes)
)]
pub trait InstalledScheduler: Send + Sync + Debug + 'static {
fn id(&self) -> SchedulerId;
fn pool(&self) -> InstalledSchedulerPoolArc;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we ever need/use the pool for anything other than a call to return_to_pool?

If that's the case, why not just have a direct function on this trait that consumes the appropriate wrapped type (Box<Self>, I think)?

Copy link
Member Author

@ryoqun ryoqun Nov 2, 2023

Choose a reason for hiding this comment

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

wow, super nice suggestion. this resulted in sizable code reorg: c15aac3 2cac972 d4aee43

esp, visible in the main pr.

@@ -518,10 +513,11 @@ mod tests {
fn test_scheduler_pause() {
solana_logger::setup();

let bank = Arc::new(crate::bank::tests::create_simple_test_bank(42));
let bank = &Arc::new(crate::bank::tests::create_simple_test_bank(42));
Copy link
Contributor

Choose a reason for hiding this comment

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

why all these changes to use an &Arc<..> instead of owned Arc?

Copy link
Member Author

Choose a reason for hiding this comment

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

no strong reason other than to minimize diff. ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

well, thanks for pointing out. i've found way of further reducing the diff: 5df66e0

@ryoqun ryoqun requested a review from apfitzge November 3, 2023 06:45
Copy link
Contributor

@apfitzge apfitzge left a comment

Choose a reason for hiding this comment

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

lgtm!

@ryoqun
Copy link
Member Author

ryoqun commented Nov 3, 2023

I'll merge this, although the ci is running: the last commit is just about & and .clone() stuff, which should well be covered the check1 step, which is green now. and don't want to wait 1 hour just continue to create next pr...

@ryoqun ryoqun merged commit a4a6602 into solana-labs:master Nov 3, 2023
35 of 39 checks passed
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.

2 participants