perf: optimize DNS query hot path #15
@@ -3,14 +3,13 @@ use std::net::Ipv4Addr;
|
|||||||
|
|
||||||
use numa::buffer::BytePacketBuffer;
|
use numa::buffer::BytePacketBuffer;
|
||||||
use numa::cache::DnsCache;
|
use numa::cache::DnsCache;
|
||||||
use numa::header::{DnsHeader, ResultCode};
|
use numa::header::ResultCode;
|
||||||
use numa::packet::DnsPacket;
|
use numa::packet::DnsPacket;
|
||||||
use numa::question::{DnsQuestion, QueryType};
|
use numa::question::{DnsQuestion, QueryType};
|
||||||
use numa::record::DnsRecord;
|
use numa::record::DnsRecord;
|
||||||
|
|
||||||
fn make_response(domain: &str) -> DnsPacket {
|
fn make_response(domain: &str) -> DnsPacket {
|
||||||
let mut pkt = DnsPacket::new();
|
let mut pkt = DnsPacket::new();
|
||||||
pkt.header = DnsHeader::new();
|
|
||||||
pkt.header.id = 0x1234;
|
pkt.header.id = 0x1234;
|
||||||
pkt.header.response = true;
|
pkt.header.response = true;
|
||||||
pkt.header.recursion_desired = true;
|
pkt.header.recursion_desired = true;
|
||||||
@@ -93,7 +92,7 @@ fn bench_cache_lookup_hit(c: &mut Criterion) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn bench_cache_lookup_miss(c: &mut Criterion) {
|
fn bench_cache_lookup_miss(c: &mut Criterion) {
|
||||||
let mut cache = DnsCache::new(10_000, 60, 86400);
|
let cache = DnsCache::new(10_000, 60, 86400);
|
||||||
|
|
||||||
c.bench_function("cache_lookup_miss", |b| {
|
c.bench_function("cache_lookup_miss", |b| {
|
||||||
b.iter(|| cache.lookup(black_box("nonexistent.com"), QueryType::A))
|
b.iter(|| cache.lookup(black_box("nonexistent.com"), QueryType::A))
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ fn make_response(domain: &str) -> DnsPacket {
|
|||||||
|
|
||||||
/// Simulates the complete cached query pipeline (sans network I/O):
|
/// Simulates the complete cached query pipeline (sans network I/O):
|
||||||
/// parse → cache lookup → TTL adjust → serialize response
|
/// parse → cache lookup → TTL adjust → serialize response
|
||||||
fn simulate_cached_pipeline(query_wire: &[u8], cache: &mut numa::cache::DnsCache) -> usize {
|
fn simulate_cached_pipeline(query_wire: &[u8], cache: &numa::cache::DnsCache) -> usize {
|
||||||
let mut buf = BytePacketBuffer::from_bytes(query_wire);
|
let mut buf = BytePacketBuffer::from_bytes(query_wire);
|
||||||
let query = DnsPacket::from_buffer(&mut buf).unwrap();
|
let query = DnsPacket::from_buffer(&mut buf).unwrap();
|
||||||
let q = &query.questions[0];
|
let q = &query.questions[0];
|
||||||
@@ -71,7 +71,7 @@ fn bench_pipeline_throughput(c: &mut Criterion) {
|
|||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
for _ in 0..count {
|
for _ in 0..count {
|
||||||
let wire = &query_wires[idx % query_wires.len()];
|
let wire = &query_wires[idx % query_wires.len()];
|
||||||
simulate_cached_pipeline(wire, &mut cache);
|
simulate_cached_pipeline(wire, &cache);
|
||||||
idx += 1;
|
idx += 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user