Skip to content

Commit

Permalink
Optimization: Improve query latency
Browse files Browse the repository at this point in the history
  • Loading branch information
akiradeveloper committed Jun 11, 2024
1 parent 7b98ec0 commit bab55ed
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lolraft/src/process/raft_process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct RaftProcess {

queue_tx: thread::EventProducer<thread::QueueEvent>,
replication_tx: thread::EventProducer<thread::ReplicationEvent>,
app_tx: thread::EventProducer<thread::ApplicationEvent>,
}

impl RaftProcess {
Expand Down Expand Up @@ -109,6 +110,7 @@ impl RaftProcess {

queue_tx,
replication_tx,
app_tx,
})
}
}
6 changes: 6 additions & 0 deletions lolraft/src/process/raft_process/responder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ impl RaftProcess {
};
self.query_tx.register(read_index, query)?;

let app_index = self.command_log.user_pointer.load(Ordering::SeqCst);
// This must be `>=` because it is possible both commit_index and app_index are updated.
if app_index >= read_index {
self.app_tx.push_event(thread::ApplicationEvent);
}

rx.await?
} else {
// This check is to avoid looping.
Expand Down
5 changes: 2 additions & 3 deletions lolraft/src/process/thread/query_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ impl Thread {
fn do_loop(self) -> ThreadHandle {
let fut = async move {
loop {
self.consumer
.consume_events(Duration::from_millis(100))
.await;
// I am not sure the timeout here is necessary.
self.consumer.consume_events(Duration::from_secs(1)).await;
while self.advance_once().await {
tokio::task::yield_now().await;
}
Expand Down

0 comments on commit bab55ed

Please sign in to comment.