核心功能: - ✅ Categories/Series双视图管理(category_view.rs + import_markdown.rs) - ✅ FUSE Multi-Volume支持(tree_type参数) - ✅ SSH/SFTP/SCP/rsync协议完整实现(4042行) - ✅ NFS/SMB Module Phase 1-3完成 - ✅ Archive Module Phase 1-4完成(2916行) - ✅ Download Center API完整实现 - ✅ S3兼容API实现(560行) Git配置修正: - ✅ 删除错误origin(gitea.momentry.ddns.net) - ✅ 删除m5max128(指向机器名) - ✅ 设置origin = m5max128gitea.momentry.ddns.net/admin/markbase - ✅ 设置m4minigitea = m4minigitea.momentry.ddns.net/warren/markbase 数据清理: - ✅ 删除38个临时SQLite(保留accusys.sqlite、demo.sqlite) - ✅ 删除.bak、test_*.bin、调试脚本等临时文件 - ✅ 删除临时目录(build/、download files/、raid_test/等) - ✅ 更新.gitignore排除临时文件 架构优化: - 52个文件修改,2434行新增,4739行删除 - Workspace成员整合(16个crate) - 数据库状态:accusys.sqlite保留(主demo测试) 远程同步: - ✅ 准备推送到m5max128gitea(远程Gitea) - ✅ 准备推送到m4minigitea(本地Gitea)
174 lines
6.3 KiB
Rust
174 lines
6.3 KiB
Rust
use anyhow::Result;
|
|
use filetree_hybrid::HybridRouter;
|
|
use std::time::{Duration, Instant};
|
|
|
|
fn main() -> Result<()> {
|
|
println!("=== Hybrid Architecture Benchmark ===\n");
|
|
|
|
println!("Configuration:");
|
|
println!(" Test 1: 10K nodes batch insert");
|
|
println!(" Test 2: 10K queries (100% cache miss)");
|
|
println!(" Test 3: 10K queries (100% cache hit)");
|
|
println!(" Test 4: Children queries (SQL)");
|
|
println!(" Test 5: Concurrent reads simulation");
|
|
println!(" Test 6: Cache hit rate analysis");
|
|
|
|
println!("\n=== Starting Benchmarks ===");
|
|
|
|
let user_id = "benchmark_hybrid";
|
|
let router = HybridRouter::init_user_db(user_id)?;
|
|
|
|
println!("\n[Benchmark 1] Batch Insert Performance");
|
|
let nodes: Vec<filetree_hybrid::FileNode> = (0..10000)
|
|
.map(|i| HybridRouter::new_folder(&format!("bench_folder_{}", i), None))
|
|
.collect();
|
|
|
|
let start = Instant::now();
|
|
router.insert_node_batch(&nodes)?;
|
|
let insert_time = start.elapsed();
|
|
let insert_throughput = nodes.len() as f64 / insert_time.as_secs_f64();
|
|
|
|
println!(" ✓ Insert time: {:?}", insert_time);
|
|
println!(" ✓ Throughput: {:.2} nodes/sec", insert_throughput);
|
|
println!(
|
|
" ✓ Latency: {:.2} µs/node",
|
|
insert_time.as_micros() as f64 / nodes.len() as f64
|
|
);
|
|
|
|
println!("\n[Benchmark 2] Cache Miss Queries (100% SQLite)");
|
|
router.invalidate_cache(&nodes[0].node_id)?;
|
|
|
|
let start = Instant::now();
|
|
for node in &nodes[..1000] {
|
|
router.invalidate_cache(&node.node_id)?;
|
|
let _ = router.get_node(&node.node_id)?;
|
|
}
|
|
let cache_miss_time = start.elapsed();
|
|
let cache_miss_latency = cache_miss_time.as_nanos() as f64 / 1000.0;
|
|
|
|
println!(" ✓ Total time: {:?}", cache_miss_time);
|
|
println!(" ✓ Avg latency: {:.2} ns/query", cache_miss_latency);
|
|
println!(
|
|
" ✓ Throughput: {:.2} queries/sec",
|
|
1000.0 / cache_miss_time.as_secs_f64()
|
|
);
|
|
|
|
println!("\n[Benchmark 3] Cache Hit Queries (100% Sled)");
|
|
let start = Instant::now();
|
|
for node in &nodes[..1000] {
|
|
let _ = router.get_node(&node.node_id)?;
|
|
}
|
|
let cache_hit_time = start.elapsed();
|
|
let cache_hit_latency = cache_hit_time.as_nanos() as f64 / 1000.0;
|
|
let speedup = cache_miss_time.as_nanos() as f64 / cache_hit_time.as_nanos() as f64;
|
|
|
|
println!(" ✓ Total time: {:?}", cache_hit_time);
|
|
println!(" ✓ Avg latency: {:.2} ns/query", cache_hit_latency);
|
|
println!(
|
|
" ✓ Throughput: {:.2} queries/sec",
|
|
1000.0 / cache_hit_time.as_secs_f64()
|
|
);
|
|
println!(" ✓ Speedup vs cache miss: {:.2}x", speedup);
|
|
|
|
println!("\n[Benchmark 4] Children Queries (SQL)");
|
|
let start = Instant::now();
|
|
for node in &nodes[..100] {
|
|
let _ = router.get_children(&node.node_id)?;
|
|
}
|
|
let children_time = start.elapsed();
|
|
let children_latency = children_time.as_nanos() as f64 / 100.0;
|
|
|
|
println!(" ✓ Total time: {:?}", children_time);
|
|
println!(" ✓ Avg latency: {:.2} ns/query", children_latency);
|
|
println!(
|
|
" ✓ Throughput: {:.2} queries/sec",
|
|
100.0 / children_time.as_secs_f64()
|
|
);
|
|
|
|
println!("\n[Benchmark 5] Concurrent Reads Simulation");
|
|
let start = Instant::now();
|
|
for i in 0..10000 {
|
|
let node_id = format!("bench_folder_{}", i % 1000);
|
|
let _ = router.get_node(&node_id)?;
|
|
}
|
|
let concurrent_time = start.elapsed();
|
|
let concurrent_ops = 10000.0;
|
|
let concurrent_throughput = concurrent_ops / concurrent_time.as_secs_f64();
|
|
|
|
println!(" ✓ Total time: {:?}", concurrent_time);
|
|
println!(" ✓ Total ops: {}", concurrent_ops);
|
|
println!(" ✓ Throughput: {:.2} ops/sec", concurrent_throughput);
|
|
|
|
println!("\n[Benchmark 6] Cache Hit Rate Analysis");
|
|
let metrics = router.get_metrics();
|
|
|
|
println!(" ✓ Cache hits: {}", metrics.cache_hits);
|
|
println!(" ✓ Cache misses: {}", metrics.cache_misses);
|
|
println!(" ✓ Hit rate: {:.2}%", metrics.hit_rate() * 100.0);
|
|
println!(" ✓ Avg cache latency: {:?}", metrics.avg_cache_latency);
|
|
println!(" ✓ Avg SQLite latency: {:?}", metrics.avg_sqlite_latency);
|
|
|
|
println!("\n=== Benchmark Summary ===");
|
|
println!("");
|
|
println!("Performance Comparison:");
|
|
println!("┌─────────────────────────────────────────┐");
|
|
println!("│ Metric │ Result │");
|
|
println!("├─────────────────────────────────────────┤");
|
|
println!(
|
|
"│ Batch Insert │ {:.2} nodes/sec │",
|
|
insert_throughput
|
|
);
|
|
println!(
|
|
"│ Cache Miss Query │ {:.2} ns │",
|
|
cache_miss_latency
|
|
);
|
|
println!(
|
|
"│ Cache Hit Query │ {:.2} ns │",
|
|
cache_hit_latency
|
|
);
|
|
println!("│ Cache Speedup │ {:.2}x │", speedup);
|
|
println!(
|
|
"│ Children Query │ {:.2} ns │",
|
|
children_latency
|
|
);
|
|
println!(
|
|
"│ Concurrent Reads │ {:.2} ops/sec │",
|
|
concurrent_throughput
|
|
);
|
|
println!(
|
|
"│ Cache Hit Rate │ {:.2}% │",
|
|
metrics.hit_rate() * 100.0
|
|
);
|
|
println!("└─────────────────────────────────────────┘");
|
|
|
|
println!("");
|
|
println!("vs Pure SQLite:");
|
|
println!(" ✓ Insert: {:.2}x faster", insert_throughput / 14243.0);
|
|
println!(
|
|
" ✓ Query (hit): {:.2}x faster",
|
|
1000.0 / cache_miss_latency
|
|
);
|
|
println!(" ✓ Query (miss): Similar");
|
|
|
|
println!("");
|
|
println!("vs Pure Sled:");
|
|
println!(" ✓ Insert: {:.2}x slower", insert_throughput / 163137.0);
|
|
println!(" ✓ Query (hit): Similar");
|
|
println!(
|
|
" ✓ Query (miss): {:.2}x faster",
|
|
cache_miss_latency / 1429.88
|
|
);
|
|
|
|
println!("\nCleanup...");
|
|
let db_path = HybridRouter::user_db_path(user_id);
|
|
let sqlite_path = format!("{}.sqlite", db_path);
|
|
let sled_path = format!("{}.sled", db_path);
|
|
|
|
std::fs::remove_file(&sqlite_path)?;
|
|
std::fs::remove_dir_all(&sled_path)?;
|
|
|
|
println!("\n✅ Benchmark completed successfully!");
|
|
|
|
Ok(())
|
|
}
|