mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-08-05 20:19:45 +00:00
a7aae67c43
Replace all UnsafeCell-based counters with safe alternatives: - New ShardedCounter: per-thread TLS accumulation (thread_local crate) with periodic publish to static AtomicU64. Zero atomic RMW on hot path. - ACL RuleStatsTracker: remove unsafe Arc<RuleStats> raw pointer mutation, use two ShardedCounter fields. - ZCPacket: replace set_len on uninitialized BytesMut with write_bytes + copy_nonoverlapping before set_len. - StatsManager UnsafeCounter/MetricData: remove UnsafeCell and unsafe impl Send/Sync, wrap ShardedCounter. last_updated uses AtomicU64 epoch millis. - Throughput: replace UnsafeCell with AtomicU64. - secure_datagram: fix grace-window test timestamp.
52 lines
1.6 KiB
Rust
52 lines
1.6 KiB
Rust
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
|
|
use easytier::tunnel::packet_def::{ZCPacket, ZCPacketType};
|
|
|
|
fn bench_new_with_payload(c: &mut Criterion) {
|
|
let mut group = c.benchmark_group("zc_new_with_payload");
|
|
for size in [64usize, 1500] {
|
|
let payload = vec![0xabu8; size];
|
|
group.bench_with_input(BenchmarkId::from_parameter(size), &payload, |b, payload| {
|
|
b.iter(|| {
|
|
std::hint::black_box(ZCPacket::new_with_payload(std::hint::black_box(payload)));
|
|
});
|
|
});
|
|
}
|
|
group.finish();
|
|
}
|
|
|
|
fn bench_new_for_foreign_network(c: &mut Criterion) {
|
|
let payload = vec![0xabu8; 64];
|
|
let foreign_packet = ZCPacket::new_with_payload(&payload);
|
|
let network_name = "bench-network".to_string();
|
|
|
|
c.bench_function("zc_new_for_foreign_network_64b", |b| {
|
|
b.iter(|| {
|
|
std::hint::black_box(ZCPacket::new_for_foreign_network(
|
|
std::hint::black_box(&network_name),
|
|
42,
|
|
std::hint::black_box(&foreign_packet),
|
|
));
|
|
});
|
|
});
|
|
}
|
|
|
|
fn bench_convert_type(c: &mut Criterion) {
|
|
let payload = vec![0xabu8; 64];
|
|
let packet = ZCPacket::new_with_payload(&payload);
|
|
|
|
c.bench_function("zc_convert_type_tcp_64b", |b| {
|
|
b.iter(|| {
|
|
let p = std::hint::black_box(packet.clone());
|
|
std::hint::black_box(p.convert_type(ZCPacketType::TCP));
|
|
});
|
|
});
|
|
}
|
|
|
|
criterion_group!(
|
|
benches,
|
|
bench_new_with_payload,
|
|
bench_new_for_foreign_network,
|
|
bench_convert_type
|
|
);
|
|
criterion_main!(benches);
|