2个不稳定版本

0.2.0 2022年3月26日
0.1.0 2020年9月13日

#21 in #multi-threaded


aquatic 中使用

Apache-2.0

16KB
244

aquatic:高性能BitTorrent tracker

CargoBuildAndTest Test HTTP, UDP and WSS file transfer

用Rust编写的闪电般快速的多线程BitTorrent tracker,包括针对不同协议的子实现

名称 协议 操作系统要求
aquatic_udp 通过UDP的BitTorrent 类Unix(使用 mio
aquatic_http 通过HTTP的BitTorrent 与TLS (rustls) Linux 5.8+(使用 glommio
aquatic_ws WebTorrent 通过TLS (rustls) Linux 5.8+(使用 glommio

用法

先决条件

  • 使用 rustup 安装Rust(推荐使用稳定版)

  • 使用您的包管理器安装cmake(例如,apt-get install cmake

  • 克隆此git仓库并进入

编译

编译您感兴趣的实现

# Tell Rust to enable support for all CPU extensions present on current CPU
# except for those relating to AVX-512. This is necessary for aquatic_ws and
# recommended for the other implementations.
. ./scripts/env-native-cpu-without-avx-512

cargo build --release -p aquatic_udp
cargo build --release -p aquatic_http
cargo build --release -p aquatic_ws

运行

除非您只打算运行 aquatic_udp,否则请确保锁定内存限制足够。您可以通过向 /etc/security/limits.conf 添加以下行来实现,然后注销并重新登录

*    hard    memlock    512
*    soft    memlock    512

生成配置文件。它们包含注释,并且根据协议而有所不同。

./target/release/aquatic_udp -p > "aquatic-udp-config.toml"
./target/release/aquatic_http -p > "aquatic-http-config.toml"
./target/release/aquatic_ws -p > "aquatic-ws-config.toml"

调整文件。您可能需要调整 address(监听地址)在 network 部分下的设置。

请注意,aquatic_httpaquatic_ws 都需要配置TLS证书和私钥文件。更多详细信息请参阅相应的配置文件。

完成后,运行tracker

./target/release/aquatic_udp -c "aquatic-udp-config.toml"
./target/release/aquatic_http -c "aquatic-http-config.toml"
./target/release/aquatic_ws -c "aquatic-ws-config.toml"

配置值

建议启动的 socket_workers 数量多于 request_workers。所有实现都非常依赖 I/O,大部分时间都在读取和写入套接字。这是由套接字工作者处理的,它们还负责解析、序列化和访问控制。它们将公告和抓取请求传递给请求工作者,请求工作者更新内部跟踪状态并返回用于发送的响应。

访问控制

支持所有协议的按 info hash 进行访问控制。配置的相关部分是

[access_list]
# Access list mode. Available modes are allow, deny and off.
mode = "off"
# Path to access list file consisting of newline-separated hex-encoded info hashes.
path = ""

文件在程序启动时和程序接收到 SIGUSR1 信号时读取。如果初始解析失败,程序将退出。后续的失败将导致错误级别日志消息的输出,而成功更新访问列表将导致信息级别日志消息的输出。

架构概述

Architectural overview of aquatic

实现细节

aquatic_udp: UDP BitTorrent 跟踪器

实现

  • BEP 015: UDP BitTorrent 跟踪器协议 (更多详情)。异常
    • 不关心公告请求中发送的 IP 地址。始终使用数据包源 IP。
    • 不跟踪种子下载次数(始终发送 0)。

分别跟踪 IPv4 和 IPv6 对等方。

这是最成熟的实现之一。我认为它已准备好用于生产环境。

性能

UDP BitTorrent tracker throughput comparison

更多详情请参阅 此处

未能成功的优化尝试

  • 使用 glommio
  • 使用 io-uring
  • 使用 zerocopy + 向量发送响应
  • 使用 sendmmsg

aquatic_http: HTTP BitTorrent 跟踪器

实现

  • BEP 003: HTTP BitTorrent 协议 (更多详情)。异常
    • 仅通过 TLS 运行
    • 不跟踪种子下载次数(始终发送 0)
    • 仅支持紧凑响应
  • BEP 023: 紧凑 HTTP 响应
  • BEP 007: IPv6 支持
  • BEP 048: HTTP 抓取支持。注意
    • 不允许完整抓取,即所有已注册的 info hash

分别跟踪 IPv4 和 IPv6 对等方。

aquatic_http 的测试不如 aquatic_udp 多,但可能运行良好。

aquatic_ws: WebTorrent 跟踪器

旨在与 WebTorrent 客户端兼容。注意

  • 仅通过 TLS 运行
  • 不跟踪种子下载次数(始终发送 0)。
  • 不允许完整抓取,即所有已注册的 info hash

分别跟踪 IPv4 和 IPv6 对等方。

aquatic_ws 的测试不如 aquatic_udp 多,但可能运行良好。

负载测试

所有协议都有负载测试二进制文件。它们使用类似于跟踪器的 CLI 结构,并支持生成和加载配置文件。

要运行,首先启动您要测试的跟踪器。然后运行相应的负载测试二进制文件

./scripts/run-load-test-udp.sh
./scripts/run-load-test-http.sh
./scripts/run-load-test-ws.sh

要公平比较 HTTP 性能与 opentracker,请在 aquatic_http 设置中将 keepalive 设置为 false。

版权 (c) 2020-2022 Joakim Frostegård

根据 Apache 2.0 许可证分发(详情请参阅 LICENSE 文件。)

趣味知识

跟踪器被称为 aquatic,因为它在比特流中茁壮成长 :-)

依赖项

~3MB
~62K SLoC