Skip to content

[PERF]: parallelize applying log to segment types #3134

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

Closed

Conversation

codetheweb
Copy link
Contributor

@codetheweb codetheweb commented Nov 14, 2024

Description of changes

Applies log updates to segment types in parallel rather than sequentially:

Screenshot 2024-11-13 at 5 12 05 PM

Pipelining flushes to S3/applying to blockfile is in the next PR in this stack.

Test plan

How are these changes tested?

  • Tests pass locally with pytest for python, yarn test for js, cargo test for rust

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs repository?

n/a

Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

@@ -787,11 +788,12 @@ impl<'me> LogMaterializer<'me> {

// This needs to be public for testing
#[allow(async_fn_in_trait)]
pub trait SegmentWriter<'a> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

lifetime doesn't need to be on the struct

@codetheweb codetheweb marked this pull request as ready for review November 14, 2024 01:19
@codetheweb codetheweb force-pushed the perf-parallelize-applying-log branch from 740db31 to c40d5f2 Compare November 14, 2024 20:35
@codetheweb codetheweb marked this pull request as draft November 15, 2024 00:17
@@ -628,7 +630,7 @@ pub struct RecordSegmentReader<'me> {
user_id_to_id: BlockfileReader<'me, &'me str, u32>,
id_to_user_id: BlockfileReader<'me, u32, &'me str>,
id_to_data: BlockfileReader<'me, u32, DataRecord<'me>>,
curr_max_offset_id: Arc<AtomicU32>,
max_offset_id: u32,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I needed to change this because the shared state led to a bug in the log materialization logic when running multiple materializations in parallel (see comment in compact.rs). Readers should not expose mutable state.

@codetheweb codetheweb force-pushed the perf-parallelize-applying-log branch from 88e8e29 to bfd894f Compare November 15, 2024 00:57
@codetheweb codetheweb marked this pull request as ready for review November 15, 2024 00:57
@codetheweb codetheweb requested a review from rescrv November 15, 2024 00:57
panic!("Error creating record segment reader");
}
RecordSegmentReaderCreationError::UserRecordNotFound(_) => {
_ => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should not panic here / can we use this as a moment to clean up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this line is inside a test; were you referring to something else?

Copy link
Collaborator

@HammadB HammadB left a comment

Choose a reason for hiding this comment

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

  1. Can we clean up the panics we bail out to in metadata segment?
  2. Can we expand the comment for the atomics dance that explains that we view materialization as idempotent and that it should result in the same results on each thread. Otherwise we can have horrible bugs.
  3. Is there anyway to aggressively test this atomics dance?

@codetheweb codetheweb marked this pull request as draft November 20, 2024 01:21
@codetheweb codetheweb force-pushed the perf-parallelize-applying-log branch from 7be9113 to cffe2a3 Compare November 20, 2024 23:01
@codetheweb codetheweb changed the base branch from main to feat-materialize-operator November 20, 2024 23:01
Copy link
Contributor Author

codetheweb commented Nov 20, 2024

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codetheweb codetheweb force-pushed the perf-parallelize-applying-log branch 2 times, most recently from e696cd7 to 851511a Compare November 20, 2024 23:12
@codetheweb codetheweb marked this pull request as ready for review November 20, 2024 23:14
@codetheweb codetheweb force-pushed the feat-materialize-operator branch from e30c087 to cb43e94 Compare November 21, 2024 18:32
@codetheweb codetheweb force-pushed the perf-parallelize-applying-log branch from 92a0f28 to f8ab4ac Compare November 21, 2024 18:32
@codetheweb codetheweb requested review from rescrv and HammadB November 25, 2024 19:44
@@ -309,7 +310,7 @@ impl CompactOrchestrator {
},
};

self.num_write_tasks = partitions.len() as i32;
self.num_write_tasks = partitions.len() as i32 * 3; // 3 different segment types
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems worth calling out as an assumption for when we add the index. I don't know the best way to log it. I'd do a TODO(feat), but we need to agree on what that would mean.

@codetheweb codetheweb force-pushed the feat-materialize-operator branch from cb43e94 to 5e19390 Compare December 3, 2024 01:59
@codetheweb codetheweb force-pushed the feat-materialize-operator branch 3 times, most recently from 1588bc4 to b8d61ce Compare December 3, 2024 02:20
@codetheweb
Copy link
Contributor Author

Superseded by #3359 (new branch was easier than rebasing as approach has changed).

@codetheweb codetheweb closed this Dec 27, 2024
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