Skip to content

Commit 0bbb25f

Browse files
nipunn1313Convex, Inc.
authored andcommitted
Add an env var to make the index worker slow. (#40003)
For good manual debugging. GitOrigin-RevId: d4af82d670b65c7295a0ea5fd421e7ef4d8da4fa
1 parent d9df2a1 commit 0bbb25f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

crates/database/src/index_worker.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::{
1313
time::Duration,
1414
};
1515

16+
use cmd_util::env::env_config;
1617
use common::{
1718
self,
1819
backoff::Backoff,
@@ -116,6 +117,9 @@ static ENTRIES_PER_SECOND: LazyLock<NonZeroU32> = LazyLock::new(|| {
116117
.unwrap()
117118
});
118119

120+
static INDEX_WORKER_SLEEP_TIME: LazyLock<Duration> =
121+
LazyLock::new(|| Duration::from_millis(env_config("INDEX_WORKER_SLEEP_TIME_MS", 0)));
122+
119123
pub struct IndexWorker<RT: Runtime> {
120124
database: Database<RT>,
121125
index_writer: IndexWriter<RT>,
@@ -756,6 +760,9 @@ impl<RT: Runtime> IndexWriter<RT> {
756760
let mut last_logged = self.runtime.system_time();
757761
let mut last_logged_count = 0;
758762
while !stream.is_done() {
763+
if !INDEX_WORKER_SLEEP_TIME.is_zero() {
764+
tokio::time::sleep(*INDEX_WORKER_SLEEP_TIME).await;
765+
}
759766
// Number of documents in the table that have been indexed in this iteration
760767
let mut num_docs_indexed = 0u64;
761768
let mut chunk = BTreeSet::new();

0 commit comments

Comments
 (0)