dht-crawler
一个高性能的 Rust DHT(分布式哈希表)爬虫库,用于爬取 BitTorrent DHT 网络中的种子信息。
特性
- 🚀 高性能:基于 Tokio 异步运行时,支持高并发处理
- 🌐 双栈支持:同时支持 IPv4 和 IPv6(DualStack 模式)
- 📦 自动元数据获取:自动从对等节点获取完整的种子元数据
- ⚡ 可配置并发:支持自定义元数据获取并发数和队列大小
- 🎯 灵活回调:提供多种回调接口,方便自定义处理逻辑
- 📊 监控支持:内置统计和监控接口
安装
在 Cargo.toml 中添加依赖:
[]
= "0.0.5"
或者查看 crates.io 获取最新版本号。
启用可选 Features
如果需要使用 Prometheus 指标支持,可以启用 metrics feature:
[]
= { = "0.0.5", = ["metrics"] }
Features
本库支持以下可选特性:
mimalloc - 高性能内存分配器
使用 mimalloc 作为全局内存分配器,可以显著降低内存占用(通常降低 10-30%),特别适合长时间运行的高并发场景。
metrics - Prometheus 指标支持
启用 metrics feature 后,库会通过 metrics crate 暴露统计指标,可以与 Prometheus 等监控系统集成。
注意:
mimalloc和metrics-exporter-prometheus仅在编译 example 时可用(位于dev-dependencies)- 使用 example 时需要显式启用对应的 features
- 库本身可以使用
metricsfeature(通过[dependencies]中的可选依赖)
快速开始
基本使用
请参考 examples/main.rs 查看完整的使用示例。
编译示例
基本编译(不启用任何 features)
# Debug 模式
# Release 模式
启用 mimalloc(推荐)
# Debug 模式
# Release 模式(推荐用于生产环境)
启用 metrics(Prometheus 指标导出)
# 启用 metrics feature
# Release 模式
同时启用 mimalloc 和 metrics
# Debug 模式
# Release 模式(推荐)
交叉编译(Linux)
# 编译 Linux 版本(推荐使用 mimalloc 以获得更好的内存性能)
# 编译后的可执行文件位于:
# target/x86_64-unknown-linux-gnu/release/examples/dht_crawler_example
运行示例
基本运行(不使用任何 features)
启用 mimalloc 运行
启用 metrics 运行
启用 metrics 后,Prometheus metrics 导出器会在 http://localhost:9000/metrics 启动。
然后在浏览器或使用 curl 访问:
同时启用 mimalloc 和 metrics(推荐)
在项目中使用 Features
使用库本身(不带任何 features)
[]
= "0.0.4"
使用库并启用 metrics feature
[]
= { = "0.0.4", = ["metrics"] }
这样可以在你的代码中使用库暴露的 metrics 指标。
注意:mimalloc feature 仅用于 example,库本身不依赖 mimalloc。
许可证
MIT License