-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(iroh-dns-server): Move db ops into an actor and implement wr…
…ite batching (#2995) ## Description Batch to make write go brrr.... - move all db interactions into an actor - inside the actor, have two nested loops, inner loop keeps write txn open - txn is closed when a number of msgs have been written or some time has elapsed, whatever comes first ## Breaking Changes None ## Benches This branch: ``` Benchmarking dns_server_writes/1000: Collecting 10 samples in estimated 9.4698 s dns_server_writes/1000 time: [171.28 ms 174.05 ms 176.58 ms] thrpt: [5.6631 Kelem/s 5.7455 Kelem/s 5.8384 Kelem/s] change: time: [-6.8425% -3.3112% -0.0384%] (p = 0.10 > 0.05) thrpt: [+0.0384% +3.4246% +7.3451%] No change in performance detected. ``` arqu/dns-bench: ``` Benchmarking dns_server_writes/1000: Warming up for 3.0000 s dns_server_writes/1000 time: [6.2530 s 6.3920 s 6.5351 s] thrpt: [153.02 elem/s 156.45 elem/s 159.92 elem/s] change: time: [+3881.0% +3974.8% +4080.8%] (p = 0.00 < 0.05) thrpt: [-97.608% -97.546% -97.488%] Performance has regressed. ``` ## Downsides The downside of write batching is that in case of a crash or hard program termination we lose the last MAX_BATCH_TIME seconds and MAX_BATCH_SIZE writes. I think that this is acceptable since discovery information is republished. --------- Co-authored-by: dignifiedquire <[email protected]> Co-authored-by: Asmir Avdicevic <[email protected]>
- Loading branch information
1 parent
26c5248
commit cd9c188
Showing
5 changed files
with
224 additions
and
59 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use anyhow::Result; | ||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; | ||
use iroh::{discovery::pkarr::PkarrRelayClient, dns::node_info::NodeInfo, key::SecretKey}; | ||
use iroh_dns_server::{config::Config, server::Server, ZoneStore}; | ||
use tokio::runtime::Runtime; | ||
|
||
const LOCALHOST_PKARR: &str = "http://localhost:8080/pkarr"; | ||
|
||
async fn start_dns_server(config: Config) -> Result<Server> { | ||
let store = ZoneStore::persistent(Config::signed_packet_store_path()?)?; | ||
Server::spawn(config, store).await | ||
} | ||
|
||
fn benchmark_dns_server(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("dns_server_writes"); | ||
group.sample_size(10); | ||
for iters in [10_u64, 100_u64, 250_u64, 1000_u64].iter() { | ||
group.throughput(Throughput::Elements(*iters)); | ||
group.bench_with_input(BenchmarkId::from_parameter(iters), iters, |b, &iters| { | ||
b.iter(|| { | ||
let rt = Runtime::new().unwrap(); | ||
rt.block_on(async move { | ||
let config = Config::load("./config.dev.toml").await.unwrap(); | ||
let server = start_dns_server(config).await.unwrap(); | ||
|
||
let secret_key = SecretKey::generate(); | ||
let node_id = secret_key.public(); | ||
|
||
let pkarr_relay = LOCALHOST_PKARR.parse().expect("valid url"); | ||
let relay_url = Some("http://localhost:8080".parse().unwrap()); | ||
let pkarr = PkarrRelayClient::new(pkarr_relay); | ||
let node_info = NodeInfo::new(node_id, relay_url, Default::default()); | ||
let signed_packet = node_info.to_pkarr_signed_packet(&secret_key, 30).unwrap(); | ||
|
||
let start = std::time::Instant::now(); | ||
for _ in 0..iters { | ||
pkarr.publish(&signed_packet).await.unwrap(); | ||
} | ||
let duration = start.elapsed(); | ||
|
||
server.shutdown().await.unwrap(); | ||
|
||
duration | ||
}) | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
criterion_group!(benches, benchmark_dns_server); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters