-
Notifications
You must be signed in to change notification settings - Fork 184
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
Allow custom exertion logic #411
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -74,7 +74,7 @@ use std::fmt::Debug; | |||||
use ::logging::Logger; | ||||||
use ::difference::Semigroup; | ||||||
use lattice::Lattice; | ||||||
use trace::{Batch, BatchReader, Trace, TraceReader}; | ||||||
use trace::{Batch, BatchReader, Trace, TraceReader, ExertionLogic}; | ||||||
use trace::cursor::{Cursor, CursorList}; | ||||||
use trace::Merger; | ||||||
|
||||||
|
@@ -97,6 +97,8 @@ pub struct Spine<B: Batch> where B::Time: Lattice+Ord, B::R: Semigroup { | |||||
upper: Antichain<B::Time>, | ||||||
effort: usize, | ||||||
activator: Option<timely::scheduling::activate::Activator>, | ||||||
/// Logic to indicate whether and how many records we should introduce in the absence of actual updates. | ||||||
exert_logic: ExertionLogic, | ||||||
} | ||||||
|
||||||
impl<B> TraceReader for Spine<B> | ||||||
|
@@ -264,22 +266,21 @@ where | |||||
|
||||||
/// Apply some amount of effort to trace maintenance. | ||||||
/// | ||||||
/// The units of effort are updates, and the method should be | ||||||
/// thought of as analogous to inserting as many empty updates, | ||||||
/// where the trace is permitted to perform proportionate work. | ||||||
fn exert(&mut self, effort: &mut isize) { | ||||||
/// Whether and how much effort to apply is determined by `self.exert_logic`, a closure the user can set. | ||||||
fn exert(&mut self) { | ||||||
// If there is work to be done, ... | ||||||
self.tidy_layers(); | ||||||
if !self.reduced() { | ||||||
// Determine whether we should apply effort independent of updates. | ||||||
if let Some(effort) = self.exert_effort() { | ||||||
|
||||||
// If any merges exist, we can directly call `apply_fuel`. | ||||||
if self.merging.iter().any(|b| b.is_double()) { | ||||||
self.apply_fuel(effort); | ||||||
self.apply_fuel(&mut (effort as isize)); | ||||||
} | ||||||
// Otherwise, we'll need to introduce fake updates to move merges along. | ||||||
else { | ||||||
// Introduce an empty batch with roughly *effort number of virtual updates. | ||||||
let level = (*effort as usize).next_power_of_two().trailing_zeros() as usize; | ||||||
let level = effort.next_power_of_two().trailing_zeros() as usize; | ||||||
self.introduce_batch(None, level); | ||||||
} | ||||||
// We were not in reduced form, so let's check again in the future. | ||||||
|
@@ -289,6 +290,10 @@ where | |||||
} | ||||||
} | ||||||
|
||||||
fn set_exert_logic(&mut self, logic: ExertionLogic) { | ||||||
self.exert_logic = logic; | ||||||
} | ||||||
|
||||||
// Ideally, this method acts as insertion of `batch`, even if we are not yet able to begin | ||||||
// merging the batch. This means it is a good time to perform amortized work proportional | ||||||
// to the size of batch. | ||||||
|
@@ -388,19 +393,20 @@ where | |||||
B::Time: Lattice+timely::progress::Timestamp+Ord+Clone+Debug, | ||||||
B::R: Semigroup, | ||||||
{ | ||||||
/// True iff there is at most one non-empty batch in `self.merging`. | ||||||
/// Determine the amount of effort we should exert in the absence of updates. | ||||||
/// | ||||||
/// When true, there is no maintenance work to perform in the trace, other than compaction. | ||||||
/// We do not yet have logic in place to determine if compaction would improve a trace, so | ||||||
/// for now we are ignoring that. | ||||||
fn reduced(&self) -> bool { | ||||||
let mut non_empty = 0; | ||||||
for index in 0 .. self.merging.len() { | ||||||
if self.merging[index].is_double() { return false; } | ||||||
if self.merging[index].len() > 0 { non_empty += 1; } | ||||||
if non_empty > 1 { return false; } | ||||||
} | ||||||
true | ||||||
/// This method prepares an iterator over batches, including the level, count, and length of each layer. | ||||||
/// It supplies this to `self.exert_logic`, who produces the response of the amount of exertion to apply. | ||||||
fn exert_effort(&self) -> Option<usize> { | ||||||
(self.exert_logic)( | ||||||
Box::new(self.merging.iter().enumerate().rev().map(|(index, batch)| { | ||||||
match batch { | ||||||
MergeState::Vacant => (index, 0, 0), | ||||||
MergeState::Single(_) => (index, 1, batch.len()), | ||||||
MergeState::Double(_) => (index, 2, batch.len()), | ||||||
} | ||||||
})) | ||||||
) | ||||||
} | ||||||
|
||||||
/// Describes the merge progress of layers in the trace. | ||||||
|
@@ -443,6 +449,7 @@ where | |||||
upper: Antichain::from_elem(<B::Time as timely::progress::Timestamp>::minimum()), | ||||||
effort, | ||||||
activator, | ||||||
exert_logic: std::sync::Arc::new(|_batches| None), | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -483,7 +490,7 @@ where | |||||
} | ||||||
|
||||||
// Having performed all of our work, if more than one batch remains reschedule ourself. | ||||||
if !self.reduced() { | ||||||
if !self.exert_effort().is_some() { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooh, I think this is wrong both ways, actually. We want to reschedule if there is exert effort to apply. Oops. Will fix. |
||||||
if let Some(activator) = &self.activator { | ||||||
activator.activate(); | ||||||
} | ||||||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we're referencing
idle_merge_effort
anymore, so we should probably remove it here, and extendoptions
to also take adefault_excert_logic
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm up for waiting just a bit to see how this looks before locking things in. I wrote a bunch of code before realizing that it all needs to cross thread boundaries, and if it turns out that it needs to be SerDe also .. what a mess. :D