20260416_2 并行优化phase1后进行snapshot fast path优化,通过四方面关键优化技术消除了验证主链路上snapshot构建是的db访问性能热点问题,性能热点转移到ROA验证处理本身,目前APNIC+ARIN全量同步从500秒压缩到212秒,离rpkclient 112秒差距变小
This commit is contained in:
@@ -392,6 +392,59 @@ mod tests {
|
||||
assert!(err.contains("http read body failed"), "{err}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fetch_to_writer_streams_body_on_success() {
|
||||
let url = spawn_one_shot_http_server("HTTP/1.1 200 OK", b"writer-body");
|
||||
let http = BlockingHttpFetcher::new(HttpFetcherConfig {
|
||||
timeout: Duration::from_secs(2),
|
||||
..HttpFetcherConfig::default()
|
||||
})
|
||||
.expect("http");
|
||||
let mut out = Vec::new();
|
||||
let bytes = http.fetch_to_writer(&url, &mut out).expect("stream");
|
||||
assert_eq!(bytes, 11);
|
||||
assert_eq!(out, b"writer-body");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fetch_to_writer_rejects_non_success_status() {
|
||||
let url = spawn_one_shot_http_server("HTTP/1.1 500 Internal Server Error", b"boom");
|
||||
let http = BlockingHttpFetcher::new(HttpFetcherConfig {
|
||||
timeout: Duration::from_secs(2),
|
||||
..HttpFetcherConfig::default()
|
||||
})
|
||||
.expect("http");
|
||||
let mut out = Vec::new();
|
||||
let err = http.fetch_to_writer(&url, &mut out).unwrap_err();
|
||||
assert!(err.contains("http status"), "{err}");
|
||||
assert!(out.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fetch_to_writer_times_out_on_idle_stream_read() {
|
||||
let listener = TcpListener::bind(("127.0.0.1", 0)).expect("bind");
|
||||
let addr = listener.local_addr().expect("addr");
|
||||
thread::spawn(move || {
|
||||
let (mut stream, _) = listener.accept().expect("accept");
|
||||
let mut buf = [0u8; 1024];
|
||||
let _ = stream.read(&mut buf);
|
||||
stream
|
||||
.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 5\r\nConnection: close\r\n\r\nh")
|
||||
.expect("write partial body");
|
||||
std::thread::sleep(StdDuration::from_secs(2));
|
||||
let _ = stream.write_all(b"ello");
|
||||
});
|
||||
let url = format!("http://{}/", addr);
|
||||
let http = BlockingHttpFetcher::new(HttpFetcherConfig {
|
||||
timeout: Duration::from_secs(1),
|
||||
..HttpFetcherConfig::default()
|
||||
})
|
||||
.expect("http");
|
||||
let mut out = Vec::new();
|
||||
let err = http.fetch_to_writer(&url, &mut out).unwrap_err();
|
||||
assert!(err.contains("http stream body failed"), "{err}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uses_large_body_timeout_selects_rrdp_snapshot_and_delta_not_notification() {
|
||||
assert!(!uses_large_body_timeout(
|
||||
@@ -407,4 +460,23 @@ mod tests {
|
||||
"https://tal.example.test/example.tal"
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn client_for_uri_selects_expected_timeout_profile() {
|
||||
let http = BlockingHttpFetcher::new(HttpFetcherConfig {
|
||||
timeout: Duration::from_secs(3),
|
||||
large_body_timeout: Duration::from_secs(9),
|
||||
..HttpFetcherConfig::default()
|
||||
})
|
||||
.expect("http");
|
||||
|
||||
let (_, profile_short, timeout_short) = http.client_for_uri("https://example.test/root.tal");
|
||||
assert_eq!(profile_short, "short");
|
||||
assert_eq!(timeout_short, Duration::from_secs(3));
|
||||
|
||||
let (_, profile_large, timeout_large) =
|
||||
http.client_for_uri("https://rrdp.example.test/session/1/snapshot.xml");
|
||||
assert_eq!(profile_large, "large_body");
|
||||
assert_eq!(timeout_large, Duration::from_secs(9));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user