Skip to content

Optimise sync_pull to pull frames in batches#2089

Merged
penberg merged 1 commit intotursodatabase:mainfrom
avinassh:sync-pull-batch
Jun 9, 2025
Merged

Optimise sync_pull to pull frames in batches#2089
penberg merged 1 commit intotursodatabase:mainfrom
avinassh:sync-pull-batch

Conversation

@avinassh
Copy link
Copy Markdown
Member

@avinassh avinassh commented Jun 1, 2025

Previously, we pulled frames one by one. This patch changes it pull frames in batches. Currently, the batch size is set to 128 (the maximum supported by the server)

@avinassh
Copy link
Copy Markdown
Member Author

avinassh commented Jun 1, 2025

This PR should be merged once the server side changes are deployed. Changing it to draft for now.

@avinassh avinassh marked this pull request as draft June 1, 2025 15:51
Comment thread libsql/src/sync.rs
@avinassh avinassh force-pushed the sync-pull-batch branch 2 times, most recently from 8213b7c to 2c3c88c Compare June 3, 2025 13:36
@khuezy
Copy link
Copy Markdown

khuezy commented Jun 3, 2025

Hi @avinassh I'm testing the remote_sync example and it's stuck on let conn = db.connect().unwrap(); for about 24 seconds before it runs print!("Syncing with remote database...");

The local db was already synced prior.

@avinassh
Copy link
Copy Markdown
Member Author

avinassh commented Jun 3, 2025

@khuezy Thanks for checking! Do note that this PR branch does not give performance boost as expected, since server side changes are not deployed. However, what you mentioned sounds like a bug. Can you DM me the trace logs, please?

@avinassh avinassh force-pushed the sync-pull-batch branch 3 times, most recently from 69619e0 to aaf8ec4 Compare June 6, 2025 13:20
@avinassh avinassh marked this pull request as ready for review June 9, 2025 03:19
@avinassh avinassh requested review from Copilot, levydsa and penberg June 9, 2025 05:16
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimises the frame pull operation by switching from a one-by-one pull to batch pulling, thereby enhancing performance.

  • Introduces a new constant for the pull batch size and updates the related API.
  • Replaces pull_one_frame with pull_frames to retrieve frames in batches with additional error handling and logging.
  • Makes the timing function in the remote client module public for tracking HTTP request duration.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
libsql/src/sync.rs Adds pull batch size constant and new pull_frames method with enhanced error checking and logging.
libsql/src/replication/remote_client.rs Updates the timing function to public visibility to support the new pull_frames functionality.
Comments suppressed due to low confidence (2)

libsql/src/replication/remote_client.rs:21

  • [nitpick] Confirm that making the 'time' function public is intentional. If it's meant only for internal use, consider keeping it private to limit the module's public API surface.
pub async fn time<O>(fut: impl Future<Output = O>) -> (O, Duration) {

libsql/src/sync.rs:949

  • [nitpick] Consider enhancing the error logging here by including the expected number of frame chunks (e.g. frames.len() divided by FRAME_SIZE) alongside the actual byte length received, to aid troubleshooting.
if frames.len() % FRAME_SIZE != 0 {

Previously, we pulled frames one by one. This patch changes it pull
frames in batches. Currently, the batch size is set to 128 (the
maximum supported by the server)
@penberg penberg added this pull request to the merge queue Jun 9, 2025
Merged via the queue into tursodatabase:main with commit 99c7308 Jun 9, 2025
19 checks passed
@avinassh avinassh deleted the sync-pull-batch branch June 9, 2025 06:45
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.

4 participants