-
Notifications
You must be signed in to change notification settings - Fork 25
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
Moving collect to a better place in OPRF IPA #835
Merged
Merged
Changes from all 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -349,6 +349,8 @@ where | |||||
/// Takes an input stream of `PrfShardedIpaInputRecordRow` which is assumed to have all records with a given PRF adjacent | ||||||
/// and converts it into a stream of vectors of `PrfShardedIpaInputRecordRow` having the same PRF. | ||||||
/// | ||||||
/// Filters out any users that only have a single row, since they will produce no attributed conversions. | ||||||
/// | ||||||
fn chunk_rows_by_user<IS, BK, TV, TS>( | ||||||
input_stream: IS, | ||||||
first_row: PrfShardedIpaInputRow<BK, TV, TS>, | ||||||
|
@@ -361,13 +363,16 @@ where | |||||
{ | ||||||
unfold(Some((input_stream, first_row)), |state| async move { | ||||||
let (mut s, last_row) = state?; | ||||||
let last_row_prf = last_row.prf_of_match_key; | ||||||
let mut last_row_prf = last_row.prf_of_match_key; | ||||||
let mut current_chunk = vec![last_row]; | ||||||
while let Some(row) = s.next().await { | ||||||
if row.prf_of_match_key == last_row_prf { | ||||||
current_chunk.push(row); | ||||||
} else { | ||||||
} else if current_chunk.len() > 1 { | ||||||
return Some((current_chunk, Some((s, row)))); | ||||||
} else { | ||||||
last_row_prf = row.prf_of_match_key; | ||||||
current_chunk = vec![row]; | ||||||
} | ||||||
} | ||||||
Some((current_chunk, None)) | ||||||
|
@@ -435,8 +440,11 @@ where | |||||
let first_row = first_row.unwrap(); | ||||||
let rows_chunked_by_user = chunk_rows_by_user(input_stream, first_row); | ||||||
|
||||||
let mut collected = rows_chunked_by_user.collect::<Vec<_>>().await; | ||||||
collected.sort_by(|a, b| std::cmp::Ord::cmp(&b.len(), &a.len())); | ||||||
|
||||||
// Convert to a stream of async futures that represent the result of executing the per-user circuit | ||||||
let stream_of_per_user_circuits = pin!(rows_chunked_by_user.then(|rows_for_user| { | ||||||
let stream_of_per_user_circuits = pin!(stream_iter(collected).then(|rows_for_user| { | ||||||
let num_user_rows = rows_for_user.len(); | ||||||
let contexts = ctx_for_row_number[..num_user_rows - 1].to_owned(); | ||||||
let record_ids = record_id_for_row_depth[..num_user_rows].to_owned(); | ||||||
|
@@ -458,16 +466,15 @@ where | |||||
})); | ||||||
|
||||||
// Execute all of the async futures (sequentially), and flatten the result | ||||||
let collected_per_user_results = stream_of_per_user_circuits.collect::<Vec<_>>().await; | ||||||
let per_user_attribution_outputs = sh_ctx.parallel_join(collected_per_user_results).await?; | ||||||
let flattenned_stream = per_user_attribution_outputs.into_iter().flatten(); | ||||||
let flattenned_stream = seq_join(sh_ctx.active_work(), stream_of_per_user_circuits) | ||||||
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.
|
||||||
.flat_map(|x| stream_iter(x.unwrap())); | ||||||
|
||||||
// modulus convert breakdown keys and trigger values | ||||||
let converted_bks_and_tvs = convert_bits( | ||||||
prime_field_ctx | ||||||
.narrow(&Step::ModulusConvertBreakdownKeyBitsAndTriggerValues) | ||||||
.set_total_records(num_outputs), | ||||||
stream_iter(flattenned_stream), | ||||||
flattenned_stream, | ||||||
0..BK::BITS + TV::BITS, | ||||||
); | ||||||
|
||||||
|
Oops, something went wrong.
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.
this sort may be a bottleneck in the future - we can't kick off processing until we receive the very last PRF shard. We should probably start thinking about how things will look like with multiple shards - I would assume that some sort of consistent hashing is required to map PRF pseudonyms to shards, meaning that each shard will have to wait until the very last event is sent to it and mapper indicated that no more events will be send.
In this model, the approach proposed here works, but we will have to keep all impressions and conversions in memory while receiving them from the mapper, i.e. no streaming
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 agree this is seriously sub-optimal. I think we should land this code, but re-evaluate this once we have the shuffling and sharding in place to see how we can deal with it.