Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 73 additions & 45 deletions 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
Expand Up @@ -103,7 +103,7 @@ proptest = "1.11" # Property-based testing for comprehensive coverage
yenc = "0.2.2" # For benchmark comparison only

[target.'cfg(all(target_os = "linux", any(target_arch = "x86_64", target_arch = "aarch64")))'.dev-dependencies]
iai-callgrind = "0.16.1" # Instruction-count benchmarking for hot path comparisons
gungraun = "0.19.4" # Callgrind instruction/branch/cache benchmarking

[features]
default = []
Expand Down
4 changes: 2 additions & 2 deletions benches/cache_miss_roundtrip_callgrind.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Callgrind benchmarks for the real cache-miss proxy roundtrip path.
//! Gungraun benchmarks for the real cache-miss proxy roundtrip path.
//!
//! These benches drive a client socket through a live per-command proxy with
//! metadata-only cache enabled or no configured cache. Each `ARTICLE` request
Expand All @@ -17,7 +17,7 @@ macro_rules! supported {
}

supported! {
use iai_callgrind::{
use gungraun::{
Callgrind, LibraryBenchmarkConfig, library_benchmark, library_benchmark_group, main,
};
use nntp_proxy::config::{Cache, Config, Server};
Expand Down
4 changes: 2 additions & 2 deletions benches/request_classifier_callgrind.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Callgrind benchmarks for NNTP request verb classification.
//! Gungraun benchmarks for NNTP request verb classification.
//!
//! The `request_line_*` benches exercise the current borrowed request-line parser.
//!
Expand All @@ -14,7 +14,7 @@ macro_rules! supported {
}

supported! {
use iai_callgrind::{
use gungraun::{
Callgrind, EntryPoint, LibraryBenchmarkConfig, library_benchmark, library_benchmark_group, main,
};
use nntp_proxy::protocol::{RequestContext, RequestKind};
Expand Down
51 changes: 49 additions & 2 deletions benches/request_serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ impl FixedSink {
}

#[inline]
fn write_request_slices(sink: &mut FixedSink, request: &RequestContext) -> usize {
sink.clear();
fn append_request_slices(sink: &mut FixedSink, request: &RequestContext) -> usize {
sink.write(request.verb());
if !request.args().is_empty() {
sink.write(b" ");
Expand All @@ -58,6 +57,12 @@ fn write_request_slices(sink: &mut FixedSink, request: &RequestContext) -> usize
sink.len()
}

#[inline]
fn write_request_slices(sink: &mut FixedSink, request: &RequestContext) -> usize {
sink.clear();
append_request_slices(sink, request)
}

fn request_context(line: &[u8]) -> RequestContext {
RequestContext::parse(line).expect("valid request line")
}
Expand Down Expand Up @@ -126,6 +131,48 @@ mod mixed_batch {
}
}

mod upstream_window {
use super::{Bencher, FixedSink, append_request_slices, black_box, request_context};

const WINDOW: &[&str] = &[
"ARTICLE <a00@example.com>\r\n",
"ARTICLE <a01@example.com>\r\n",
"ARTICLE <a02@example.com>\r\n",
"ARTICLE <a03@example.com>\r\n",
"ARTICLE <a04@example.com>\r\n",
"ARTICLE <a05@example.com>\r\n",
"ARTICLE <a06@example.com>\r\n",
"ARTICLE <a07@example.com>\r\n",
"ARTICLE <a08@example.com>\r\n",
"ARTICLE <a09@example.com>\r\n",
"ARTICLE <a10@example.com>\r\n",
"ARTICLE <a11@example.com>\r\n",
"ARTICLE <a12@example.com>\r\n",
"ARTICLE <a13@example.com>\r\n",
"ARTICLE <a14@example.com>\r\n",
"ARTICLE <a15@example.com>\r\n",
];

#[divan::bench(sample_count = 1000, sample_size = 100)]
fn sixteen_article_window(bencher: Bencher) {
let requests = WINDOW
.iter()
.map(|line| request_context(line.as_bytes()))
.collect::<Vec<_>>();

bencher
.counter(divan::counter::ItemsCount::new(requests.len()))
.bench(|| {
let mut sink = FixedSink::default();
sink.clear();
requests
.iter()
.map(|request| append_request_slices(black_box(&mut sink), black_box(request)))
.sum::<usize>()
});
}
}

mod response_shape {
use super::{Bencher, StatusCode, black_box, request_context};

Expand Down
17 changes: 16 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@
package = import ./nix/package.nix {
inherit pkgs craneLib cargoToml;
};

gungraunRunner = pkgs.rustPlatform.buildRustPackage rec {
pname = "gungraun-runner";
version = "0.19.4";
src = pkgs.fetchFromGitHub {
owner = "gungraun";
repo = "gungraun";
rev = "v${version}";
hash = "sha256-KWQ4wMNIdKY9FTmPd9ZdlSuCpQQBFhIKD2Ereo3JQaI=";
};
cargoHash = "sha256-+3toaUDLCmExC3EvNv1GEdUbHSBeShurp2Y+zvE/t0k=";
cargoBuildFlags = ["-p" pname];
cargoInstallFlags = ["-p" pname];
doCheck = false;
};
in {
apps.default =
(flake-utils.lib.mkApp {
Expand All @@ -142,7 +157,7 @@
};

devShells.default = pkgs.mkShell {
nativeBuildInputs = basicNativeBuildInputs;
nativeBuildInputs = basicNativeBuildInputs ++ [gungraunRunner];
buildInputs = devBuildInputs;

shellHook = ''
Expand Down
5 changes: 3 additions & 2 deletions scripts/audit-advisories
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ run cargo deny check advisories

tree_for bincode
tree_for paste
tree_for proc-macro-error2
tree_for proc-macro-error3
tree_for gungraun

echo
echo "Upstream projects to watch:"
echo "- foyer: https://github.com/foyer-rs/foyer"
echo "- iai-callgrind: https://github.com/iai-callgrind/iai-callgrind"
echo "- gungraun: https://github.com/gungraun/gungraun"
Loading