Skip to content

Commit ff31d60

Browse files
Preslav LeConvex, Inc.
Preslav Le
authored and
Convex, Inc.
committed
Double the batch size up to 8, if we only see tombstones (#24275)
Turns out if you do .first() you are only fetching one row at a time. This is a problem since if you have 100 deleted rows, you will end up dong 100 database queries. Instead dynamically resize the batch. I have put a more conservative limit of 8 to see how much it helps but it could be larger. In general, we should perhaps always be using this technique since currently the client just guesses the size_hint. If we use filter, we always fetch 100 rows. Instead we could be using dynamic sizing. Similarly, if the client asks for take(10000) rows, we are going to fetch up to 5k. This might be too large if those rows are big. So some dynamic sizing with proper estimates of size might help there as well. For now, do the simple, obvious thing. GitOrigin-RevId: d8b69fcb370ce97399da7e94a55d0ffc277bfd65
1 parent 477390e commit ff31d60

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: crates/common/src/knobs.rs

+14
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,20 @@ pub static MYSQL_TIMEOUT: LazyLock<u64> = LazyLock::new(|| env_config("MYSQL_TIM
695695
pub static MYSQL_MAX_CONNECTIONS: LazyLock<usize> =
696696
LazyLock::new(|| env_config("MYSQL_MAX_CONNECTIONS", 128));
697697

698+
/// Minimum number of rows to read from MySQL in a single query.
699+
pub static MYSQL_MIN_QUERY_BATCH_SIZE: LazyLock<usize> =
700+
LazyLock::new(|| env_config("MYSQL_MIN_QUERY_BATCH_SIZE", 1));
701+
702+
/// Maximum number of rows to read from MySQL in a single query.
703+
pub static MYSQL_MAX_QUERY_BATCH_SIZE: LazyLock<usize> =
704+
LazyLock::new(|| env_config("MYSQL_MAX_QUERY_BATCH_SIZE", 5000));
705+
706+
/// We dynamically increase the batch size up to this threshold if client keeps
707+
/// fetching more results. This helps correct for tombstones, long prefixes and
708+
/// wrong client size estimates.
709+
pub static MYSQL_MAX_QUERY_DYNAMIC_BATCH_SIZE: LazyLock<usize> =
710+
LazyLock::new(|| env_config("MYSQL_MAX_QUERY_DYNAMIC_BATCH_SIZE", 8));
711+
698712
/// Close a connection after it has been idle for some time. RDS proxy closes
699713
/// connections after idle_client_timeout in mysql.tf, which should be
700714
/// configured to be higher than this.

0 commit comments

Comments
 (0)