Skip to content

Instantly share code, notes, and snippets.

@eycorsican
Last active July 26, 2023 15:30
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save eycorsican/356debc8295e752c1df6ad7286f98ad4 to your computer and use it in GitHub Desktop.
Save eycorsican/356debc8295e752c1df6ad7286f98ad4 to your computer and use it in GitHub Desktop.

在 V2Ray 中加入自动选择延迟最小的 outbound 的负载均衡器

下载

https://github.com/eycorsican/v2ray-core/releases/tag/v4.13.0-latency-load-balancer-v3

从源码编译

首先 checkout 这两个分支

然后根据 这个页面 给出的步骤来编译,主要是下面这条命令:

bazel build --action_env=GOPATH=$GOPATH --action_env=PATH=$PATH //release:v2ray_linux_amd64_package

配置

    "routing": {
        "balancers": [
            {
                "tag": "proxy",
                "selector": [
                    "primary_proxy",
                    "backup_proxy"
                ],
                "strategy": "latency"
            }
        ],
        "rules": [
            {
                "network": "tcp,udp",
                "type": "field",
                "balancerTag": "proxy"
            }
        ]
    }

方法

启用 latency balancer 后,会每隔 30 秒对所有选中的 outbound 做速度测试,对每个 outbound 做 5 次测速,每次测速间隔 1 秒,最后记录下平均时间。每当需要代理请求时,就选择最后一次测速结果中延迟最低的 outbound 来用。

测速方式是使用对应 outbound 实际发出一个 HTTP 请求,目标地址是 www.google.com:80 ,请求内容如下:

HEAD / HTTP/1.1\r\n\r\n

服务器返回任何非空数据则视作连接没问题,并记录时间作为延迟时间。

使用场景

典型的使用场景是当你有一个速度很快的 VPS,但这个 VPS 偶尔会抽风一会,抽风期间你要切换使用另一个 VPS(可能是比较慢的 VPS),这时你就用得上这个功能了。

@huang5307
Copy link

支持。很需要这个功能,自己建立一个服务器,因为担心被墙,所以小心使用,平时有些免费的V2Ray可以用,希望能够平均使用,以免被墙发现

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment