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

[nbs] background thread writes index records #7885

Closed
wants to merge 15 commits into from

Conversation

max-hoffman
Copy link
Contributor

@max-hoffman max-hoffman commented May 22, 2024

This uses a buffered channel to avoid blocking on indexLookup writes. The main side effect is that lookups can be out of order.

@max-hoffman
Copy link
Contributor Author

#benchmark

Copy link

@coffeegoddd
Copy link
Contributor

@max-hoffman DOLT

comparing_percentages
100.000000 to 100.000000
version result total
56b9764 ok 5937457
version total_tests
56b9764 5937457
correctness_percentage
100.0

@max-hoffman
Copy link
Contributor Author

#benchmark

Copy link

@coffeegoddd
Copy link
Contributor

@max-hoffman DOLT

comparing_percentages
100.000000 to 100.000000
version result total
778f389 ok 5937457
version total_tests
778f389 5937457
correctness_percentage
100.0

@coffeegoddd
Copy link
Contributor

@max-hoffman DOLT

test_name from_latency_median to_latency_median is_faster
tpcc-scale-factor-1 90.78 89.16 0
test_name server_name server_version tps test_name server_name server_version tps is_faster
tpcc-scale-factor-1 dolt fa83e8d 23.99 tpcc-scale-factor-1 dolt 778f389 24.08 0

@max-hoffman max-hoffman requested a review from reltuk May 23, 2024 18:59
Copy link
Contributor

@reltuk reltuk left a comment

Choose a reason for hiding this comment

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

A few comments, generally looks sane but I would approach is slightly different in the details in a few places.

@@ -94,11 +96,22 @@ func openJournalWriter(ctx context.Context, path string) (wr *journalWriter, exi
return nil, true, err
}

return &journalWriter{
sendEg, ctx := errgroup.WithContext(ctx)
recvEg, ctx := errgroup.WithContext(ctx)
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 like a weird lifecycle change for the ctx that gets passed here. All of the sudden this context needs to be valid for the entire duration of the journalWriter, instead of just for the duration of this call...

Comment on lines 517 to 522
wr.sendEg.Go(func() error {
select {
case wr.indexCh <- r:
}
return nil
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Sending these async with unbounded concurrency seems a step too far...what's the point of not enqueuing it onto the buffered channel directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

blocking on buffered channel is better? i wasn't really sure, the cleanup that way is definitely easier

err = writeIndexLookup(wr.indexWriter, l)
case lookupMeta:
l.checkSum = wr.batchCrc
wr.batchCrc = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this become a local variable of this goroutine func? If not, where else is accessing it and why its current access from that place threadsafe?

Comment on lines 188 to 190
if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There seems to a problem with the error handling and communication here. Before this change, an error writing the index would cause the write call to report an error. Now, this write call and future write calls will not report an error, and we will not see an error at Close() as currently written either. Which is, maybe fine, but we will also stop reading from indexChan, and that does not seem fine, since the write path expects to be able to write to indexChan.

You've already taken the write lock on the sender side. An easy way forward is to just set indexChan to nil and report the error in a shared variable indexWriteErr and make future writes return that thing? Potentially restart the goroutine on a future write if you want to get back the old semantics?

@coffeegoddd
Copy link
Contributor

@max-hoffman DOLT

comparing_percentages
100.000000 to 100.000000
version result total
7a54ec5 ok 5937457
version total_tests
7a54ec5 5937457
correctness_percentage
100.0

@coffeegoddd
Copy link
Contributor

@max-hoffman DOLT

read_tests from_latency_median to_latency_median is_faster
covering_index_scan 2.97 2.97 0
groupby_scan 17.32 17.32 0
index_join 5.18 5.28 0
index_join_scan 2.18 2.22 0
index_scan 52.89 53.85 0
oltp_point_select 0.51 0.51 0
oltp_read_only 8.43 8.43 0
select_random_points 0.81 0.81 0
select_random_ranges 0.97 0.97 0
table_scan 54.83 54.83 0
types_table_scan 137.35 134.9 0
write_tests from_latency_median to_latency_median is_faster
oltp_delete_insert 6.55 6.55 0
oltp_insert 3.19 3.19 0
oltp_read_write 15.83 15.83 0
oltp_update_index 3.43 3.43 0
oltp_update_non_index 3.3 3.36 0
oltp_write_only 7.3 7.43 0
types_delete_insert 7.3 7.3 0

@coffeegoddd
Copy link
Contributor

@max-hoffman DOLT

comparing_percentages
100.000000 to 100.000000
version result total
2f520f9 ok 5937457
version total_tests
2f520f9 5937457
correctness_percentage
100.0

@coffeegoddd
Copy link
Contributor

@max-hoffman DOLT

comparing_percentages
100.000000 to 100.000000
version result total
2a8e08c ok 5937457
version total_tests
2a8e08c 5937457
correctness_percentage
100.0

@coffeegoddd
Copy link
Contributor

@max-hoffman DOLT

comparing_percentages
100.000000 to 100.000000
version result total
7cbd760 ok 5937457
version total_tests
7cbd760 5937457
correctness_percentage
100.0

Copy link

Additional work is required for integration with DoltgreSQL.

Copy link

Additional work is required for integration with DoltgreSQL.

@coffeegoddd
Copy link
Contributor

@max-hoffman DOLT

comparing_percentages
100.000000 to 100.000000
version result total
6b050d8 ok 5937457
version total_tests
6b050d8 5937457
correctness_percentage
100.0

@max-hoffman
Copy link
Contributor Author

#benchmark

Copy link

Copy link

Additional work is required for integration with DoltgreSQL.

@coffeegoddd
Copy link
Contributor

@max-hoffman DOLT

comparing_percentages
100.000000 to 100.000000
version result total
3a881c2 ok 5937457
version total_tests
3a881c2 5937457
correctness_percentage
100.0

@coffeegoddd
Copy link
Contributor

@max-hoffman DOLT

test_name from_latency_median to_latency_median is_faster
tpcc-scale-factor-1 84.47 84.47 0
test_name server_name server_version tps test_name server_name server_version tps is_faster
tpcc-scale-factor-1 dolt 9022625 25.42 tpcc-scale-factor-1 dolt 3a881c2 25.13 0

@max-hoffman
Copy link
Contributor Author

#benchmark

Copy link

@coffeegoddd
Copy link
Contributor

@max-hoffman DOLT

read_tests from_latency_median to_latency_median is_faster
covering_index_scan 2.97 2.97 0
groupby_scan 17.32 17.63 0
index_join 5.18 5.28 0
index_join_scan 2.22 2.22 0
index_scan 52.89 52.89 0
oltp_point_select 0.51 0.51 0
oltp_read_only 8.28 8.28 0
select_random_points 0.81 0.81 0
select_random_ranges 0.97 0.97 0
table_scan 54.83 54.83 0
types_table_scan 134.9 134.9 0
write_tests from_latency_median to_latency_median is_faster
oltp_delete_insert 6.21 6.21 0
oltp_insert 2.97 3.02 0
oltp_read_write 15.0 15.0 0
oltp_update_index 3.19 3.19 0
oltp_update_non_index 3.07 3.13 0
oltp_write_only 6.55 6.67 0
types_delete_insert 6.91 6.91 0

@coffeegoddd
Copy link
Contributor

@max-hoffman DOLT

test_name from_latency_p95 to_latency_p95 is_faster
tpcc-scale-factor-1 86.0 84.47 0
test_name server_name server_version tps test_name server_name server_version tps is_faster
tpcc-scale-factor-1 dolt 2a77c61 24.56 tpcc-scale-factor-1 dolt 3a881c2 24.58 0

@coffeegoddd
Copy link
Contributor

@max-hoffman DOLT

read_tests from_latency_median to_latency_median is_faster
covering_index_scan 2.91 3.07 0
groupby_scan 17.01 17.32 0
index_join 5.28 5.28 0
index_join_scan 2.18 2.22 0
index_scan 51.94 52.89 0
oltp_point_select 0.5 0.51 0
oltp_read_only 8.13 8.28 0
select_random_points 0.8 0.81 0
select_random_ranges 0.95 0.97 0
table_scan 53.85 54.83 0
types_table_scan 132.49 134.9 0
write_tests from_latency_median to_latency_median is_faster
oltp_delete_insert 6.21 6.21 0
oltp_insert 3.07 3.07 0
oltp_read_write 14.73 15.27 0
oltp_update_index 3.19 3.25 0
oltp_update_non_index 3.13 3.19 0
oltp_write_only 6.67 6.79 0
types_delete_insert 6.91 7.04 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants