Skip to content

Commit

Permalink
fix: remove delay in publish_batch execution
Browse files Browse the repository at this point in the history
The existing code creates futures for publish_batch with delays to
spread the rpc load evenly in the publish interval however due to the
Rust async design those futures do not get started unless they are
awaited. This results in additional deterministic latency of almost the
publish_interval especially for the publishers who publish many prices.

This change removes the code as even the intended behaviour adds latency
and disrupts the publish interval (the last publish_batch can block the
actor loop).
  • Loading branch information
ali-bahjati committed Feb 23, 2024
1 parent d19023b commit 954e31e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyth-agent"
version = "2.5.0"
version = "2.5.1"
edition = "2021"

[[bin]]
Expand Down
10 changes: 1 addition & 9 deletions src/agent/solana/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,23 +527,15 @@ impl Exporter {
// Split the updates up into batches
let batches = permissioned_updates.chunks(self.config.max_batch_size);

// Publish all the batches, staggering the requests over the publish interval
let num_batches = batches.len();
let mut batch_send_interval = time::interval(
self.config
.publish_interval_duration
.div_f64((num_batches + 1) as f64), // +1 to give enough time for the last batch
);
let mut batch_state = HashMap::new();
let mut batch_futures = vec![];

for batch in batches {
batch_futures.push(self.publish_batch(batch));

for (identifier, info) in batch {
batch_state.insert(*identifier, (*info).clone());
}

batch_send_interval.tick().await;
}

// Wait for all the update requests to complete. Note that this doesn't wait for the
Expand Down

0 comments on commit 954e31e

Please sign in to comment.