Velocity 代理的性能、防护与可观测性支持 —— 无需替换代理的核心网络模块。
VelocityBoost 是一款适用于 Velocity 3.x 的轻量级插件,用于减少滥用性的服务器列表流量,避免玩家连接至已失效的后端服务器,并提供简单的运维可见性。它被设计为即插即用式的补充组件:无外部运行时依赖,不修补 Velocity 内部实现,也不改变代理处理正常连接的方式。
功能特性
服务器列表 Ping 缓存与防洪水攻击
基于每个 IP 的令牌桶算法、可选的全局 Ping 预算、基于 TTL(生存时间)的响应缓存以及自动缓存清理。超额的 Ping 请求将接收上一次缓存的响应,而非触发新的处理工作。该插件在 API 层面进行节流和缓存;它无法在 Velocity 开始处理之前拦截 Ping 请求(详见“已知限制”)。
健康感知负载均衡
采用 P2C(两的幂次方选择)或最少连接数策略进行选择,并支持可配置故障转移。按服务器追踪玩家状态,因此负载计数器在重连和断开连接时仍能保持准确。
后端健康检查
异步 Ping 检测,支持可配置的超时时间和失败阈值。状态不佳的服务器将从选择列表中排除,并在恢复后自动重新加入。
聊天与命令速率限制
基于 UUID 和 IP 应用无锁令牌桶算法。安全处理签名聊天和签名命令,以避免在 Minecraft 1.19.1 及以上版本中导致玩家被踢出。
批处理框架
用于高频更新的合并队列 —— 作为未来开发工作的 API 构建块。
指标与管理命令
/vboost status(别名 /vb)报告缓存命中率、被节流的 Ping 请求、被拒绝的聊天/命令、追踪的键值数量、不健康的服务器数量以及队列大小。权限要求:velocityboost.admin。
极简资源占用
无外部运行时依赖;Netty 和 Velocity API 均由代理本身提供。
基准测试结果
测试环境:Velocity 3.4.0 (build 566),Java 21,回环接口(loopback),48 个并发连接,每次运行包含 2,000 次测量 Ping + 2,000 次预热 Ping。插件限制设置:每 IP 3 个 Ping/秒,全局 500 个 Ping/秒,缓存 TTL 为 3 秒。
| 指标 |
无插件 |
带 VelocityBoost |
变化 |
| 吞吐量 |
12,999 ping/s |
12,532 ping/s |
−3.5% |
| 每 2,000 次 Ping 的服务器 CPU 耗时 |
805 ms |
922 ms |
+15% |
| p50 延迟 |
2.48 ms |
2.51 ms |
+1% |
| p99 延迟 |
9.1 ms |
17.0 ms |
+87% |
| 错误数 |
0 |
0 |
— |
| 内存 (RSS) |
315 MB |
329 MB |
+14 MB |
| 从缓存提供的响应数 |
— |
10,800 |
— |
| 实际处理的 Ping 数 |
10,800 |
9 |
−99.9% |
如何解读这些数据。在此合成基准测试中,VelocityBoost 将实际的 Ping 处理量减少了 99.9%(从 10,800 降至 9),但由于代理仍需在插件响应之前执行其自身的逐请求工作,端到端的吞吐量和延迟并未得到改善 —— 反而略有下降(p99 增加 87%)。因此,更恰当的理解是将该插件视为一种流量整形和防护层,而非纯粹的吞吐量优化方案。实际表现很大程度上取决于流量构成以及滥用流量所占的比例。
令牌桶:旧版 vs 优化后的实现
| 场景 |
旧版 (2 × AtomicLong) |
优化版 (单次 CAS) |
加速比 |
| 1 个线程 |
43.3 ns/op |
39.2 ns/op |
1.11× |
| 8 个线程,共享桶 |
149.0 ns/op |
55.3 ns/op |
2.70× |
| 8 个线程,每线程独立桶 |
19.8 ns/op |
12.5 ns/op |
1.58× |
兼容性
Velocity 3.x(基于 Velocity API 3.4.0 构建)
Java 17+(类目标版本:17)
Netty 4.1(由 Velocity 提供)
配置
TOML 格式配置文件,包含 general(常规)、ping-cache(Ping 缓存)、balancer(负载均衡器)、ratelimit(速率限制)、batching(批处理)、health(健康检查)、metrics(指标)和 jfr(JFR 集成)等部分。无效值将在启动时被钳制(clamp);未知键将被忽略。
已知限制
Velocity 的公开 API 无法在代理处理之前拦截服务器列表 Ping 请求,因此 Ping 模块只能对响应进行节流和缓存,而无法消除代理的逐请求工作开销。
数据包批处理和 JFR 集成仅为框架支撑;它们不会修补 Velocity 的内部实现。
未包含 HTTP 指标导出器。
Performance, protection, and observability for Velocity proxies — without replacing the proxy's core networking.
VelocityBoost is a lightweight plugin for Velocity 3.x that reduces abusive server-list traffic, keeps players away from dead backends, and adds simple operational visibility. It is designed as a drop-in addition: no external runtime dependencies, no patching of Velocity internals, and no changes to how the proxy handles normal connections.
Features
Server-list ping cache and anti-flood
Per-IP token bucket, optional global ping budget, TTL-based response cache, and automatic cache cleanup. Excess pings receive the last cached response instead of triggering fresh work. The plugin throttles and caches responses at the API level; it cannot intercept pings before Velocity begins processing them (see Known limits).
Health-aware load balancing
P2C (power of two choices) or least-connections selection with configurable failover. Players are tracked per server, so load counters stay accurate across reconnects and disconnects.
Backend health checks
Asynchronous pings with configurable timeout and failure threshold. Unhealthy servers are excluded from selection and automatically restored after recovery.
Chat and command rate limiting
Lock-free token buckets applied per UUID and per IP. Signed chat and signed commands are handled safely to avoid kicks on 1.19.1+.
Batching scaffold
Coalescing queue for high-frequency updates — an API building block for future work.
Metrics and admin command
/vboost status (alias /vb) reports cache hits, throttled pings, denied chat/commands, tracked keys, unhealthy servers, and queue size. Permission: velocityboost.admin.
Minimal footprint
No external runtime dependencies; Netty and the Velocity API are provided by the proxy.
Benchmark results
Test setup: Velocity 3.4.0 (build 566), Java 21, loopback, 48 concurrent connections, 2,000 measured pings + 2,000 warm-up pings per run. Plugin limits: 3 pings/s per IP, 500 pings/s global, 3 s cache TTL.
Metric Without plugin With VelocityBoost Change
Throughput 12,999 ping/s 12,532 ping/s −3.5%
Server CPU per 2,000 pings 805 ms 922 ms +15%
p50 latency 2.48 ms 2.51 ms +1%
p99 latency 9.1 ms 17.0 ms +87%
Errors 0 0 —
Memory (RSS) 315 MB 329 MB +14 MB
Responses served from cache — 10,800 —
Pings actually processed 10,800 9 −99.9%
How to read these numbers. In this synthetic benchmark, VelocityBoost reduces actual ping processing by 99.9% (10,800 → 9), but because the proxy still performs its own per-request work before the plugin can respond, end-to-end throughput and latency do not improve — they regress slightly (p99 +87%). The plugin is therefore best understood as a traffic-shaping and protection layer rather than a raw throughput optimization. Real-world behavior depends heavily on traffic mix and on how much of the load is abusive.
Token bucket: previous vs. optimized implementation
Scenario Previous (2 × AtomicLong) Optimized (single CAS) Speedup
1 thread 43.3 ns/op 39.2 ns/op 1.11×
8 threads, shared bucket 149.0 ns/op 55.3 ns/op 2.70×
8 threads, per-thread buckets 19.8 ns/op 12.5 ns/op 1.58×
Compatibility
Velocity 3.x (built against Velocity API 3.4.0)
Java 17+ (class target: 17)
Netty 4.1 (provided by Velocity)
Configuration
TOML config with sections for general, ping-cache, balancer, ratelimit, batching, health, metrics, and jfr. Invalid values are clamped at startup; unknown keys are ignored.
Known limits
Velocity's public API cannot intercept server-list pings before the proxy processes them, so the ping module throttles and caches responses but cannot eliminate the proxy's per-request work.
Packet batching and JFR integration are scaffolding; they do not patch Velocity internals.
No HTTP metrics exporter is included.
评论 0
登录后参与评分
还没有评论,来抢沙发吧