在使用ratio算法的过程中,发现修改比例以后,结果没有很快体现出来。查了一下官方的文档,说修改比例以后,会存在明显的延迟。于是对GTM的比例算法进行了一些测试。
1、比例1:1测试
配置如下:
域名为:www.test.com
域名下面共两个地址,配置首选算法为ratio,比例为1:1
使用脚本测试,可以看到此时的结果为两个地址轮询
while true; do dig www.test.com @10.1.10.240 +short ;done
10.1.10.21
10.1.10.20
10.1.10.21
10.1.10.20
10.1.10.21
10.1.10.20
10.1.10.21
10.1.10.20
10.1.10.21
10.1.10.20
10.1.10.21
10.1.10.20
10.1.10.21
10.1.10.20
10.1.10.21
10.1.10.20
2、修改比例
可以看到将其中一个的比例修改为80以后,结果马上生效了
while true; do dig www.test.com @10.1.10.240 +short ;done
10.1.10.21
10.1.10.21
10.1.10.21
10.1.10.21
10.1.10.21
10.1.10.21
10.1.10.21
10.1.10.21
10.1.10.21
10.1.10.21
10.1.10.21
10.1.10.21
10.1.10.21
10.1.10.21
3、
继续修改另一个成员的比例为20
查看决策日志,可以发现,每一次请求到达以后ratio counter减1,并且优先使用比例值较大的成员,当减到两个成员的ratio counter计数器相同时,开始进行轮询。
Dec 8 00:12:58 bigip1 info tmm[17565]: 2023-12-08 00:12:57 bigip1 qid 42285 from 10.1.10.1#61527 [www.test.com A] [pool member check succeeded (10.1.10.20:10.1.10.20) - pool member state is available (green)] [ratio selected pool member (10.1.10.20:10.1.10.20) - ratio counter (20) is higher] [pool member check succeeded (10.1.10.21:10.1.10.21) - pool member state is available (green)] [ratio selected pool member (10.1.10.21:10.1.10.21) - ratio counter (69) is higher] [ratio selected pool member (10.1.10.21:10.1.10.21) with the first highest ratio counter (69)] [ratio selected pool member (10.1.10.21:10.1.10.21)]
Dec 8 00:12:58 bigip1 info tmm[17565]: 2023-12-08 00:12:57 bigip1 qid 63003 from 10.1.10.1#61528: view none: query: www.test.com IN A +E (10.1.10.240%0)
Dec 8 00:12:58 bigip1 info tmm[17565]: 2023-12-08 00:12:57 bigip1 qid 63003 from 10.1.10.1#61528 [www.test.com A] [pool member check succeeded (10.1.10.20:10.1.10.20) - pool member state is available (green)] [ratio selected pool member (10.1.10.20:10.1.10.20) - ratio counter (20) is higher] [pool member check succeeded (10.1.10.21:10.1.10.21) - pool member state is available (green)] [ratio selected pool member (10.1.10.21:10.1.10.21) - ratio counter (68) is higher] [ratio selected pool member (10.1.10.21:10.1.10.21) with the first highest ratio counter (68)] [ratio selected pool member (10.1.10.21:10.1.10.21)]
Dec 8 00:12:58 bigip1 info tmm[17565]: 2023-12-08 00:12:57 bigip1 qid 14637 from 10.1.10.1#61529: view none: query: www.test.com IN A +E (10.1.10.240%0)
Dec 8 00:12:58 bigip1 info tmm[17565]: 2023-12-08 00:12:57 bigip1 qid 14637 from 10.1.10.1#61529 [www.test.com A] [pool member check succeeded (10.1.10.20:10.1.10.20) - pool member state is available (green)] [ratio selected pool member (10.1.10.20:10.1.10.20) - ratio counter (20) is higher] [pool member check succeeded (10.1.10.21:10.1.10.21) - pool member state is available (green)] [ratio selected pool member (10.1.10.21:10.1.10.21) - ratio counter (67) is higher] [ratio selected pool member (10.1.10.21:10.1.10.21) with the first highest ratio counter (67)] [ratio selected pool member (10.1.10.21:10.1.10.21)]
Dec 8 00:12:58 bigip1 info tmm[17565]: 2023-12-08 00:12:58 bigip1 qid 40202 from 10.1.10.1#54964: view none: query: www.test.com IN A +E (10.1.10.240%0)
Dec 8 00:12:58 bigip1 info tmm[17565]: 2023-12-08 00:12:58 bigip1 qid 40202 from 10.1.10.1#54964 [www.test.com A] [pool member check succeeded (10.1.10.20:10.1.10.20) - pool member state is available (green)] [ratio selected pool member (10.1.10.20:10.1.10.20) - ratio counter (20) is higher] [pool member check succeeded (10.1.10.21:10.1.10.21) - pool member state is available (green)] [ratio selected pool member (10.1.10.21:10.1.10.21) - ratio counter (66) is higher] [ratio selected pool member (10.1.10.21:10.1.10.21) with the first highest ratio counter (66)] [ratio selected pool member (10.1.10.21:10.1.10.21)]
Dec 8 00:13:04 bigip1 info tmm[17565]: 2023-12-08 00:13:03 bigip1 qid 58171 from 10.1.10.1#54672 [www.test.com A] [pool member check succeeded (10.1.10.20:10.1.10.20) - pool member state is available (green)] [ratio selected pool member (10.1.10.20:10.1.10.20) - ratio counter (18) is higher] [pool member check succeeded (10.1.10.21:10.1.10.21) - pool member state is available (green)] [ratio skipped pool member (10.1.10.21:10.1.10.21) - ratio counter (18) is not higher] [ratio selected pool member (10.1.10.20:10.1.10.20) with the first highest ratio counter (18)] [ratio selected pool member (10.1.10.20:10.1.10.20)]
Dec 8 00:13:04 bigip1 info tmm[17565]: 2023-12-08 00:13:03 bigip1 qid 49377 from 10.1.10.1#54673: view none: query: www.test.com IN A +E (10.1.10.240%0)
Dec 8 00:13:04 bigip1 info tmm[17565]: 2023-12-08 00:13:03 bigip1 qid 49377 from 10.1.10.1#54673 [www.test.com A] [pool member check succeeded (10.1.10.20:10.1.10.20) - pool member state is available (green)] [ratio selected pool member (10.1.10.20:10.1.10.20) - ratio counter (17) is higher] [pool member check succeeded (10.1.10.21:10.1.10.21) - pool member state is available (green)] [ratio selected pool member (10.1.10.21:10.1.10.21) - ratio counter (18) is higher] [ratio selected pool member (10.1.10.21:10.1.10.21) with the first highest ratio counter (18)] [ratio selected pool member (10.1.10.21:10.1.10.21)]
Dec 8 00:13:04 bigip1 info tmm[17565]: 2023-12-08 00:13:03 bigip1 qid 17609 from 10.1.10.1#54674: view none: query: www.test.com IN A +E (10.1.10.240%0)
Dec 8 00:13:04 bigip1 info tmm[17565]: 2023-12-08 00:13:03 bigip1 qid 17609 from 10.1.10.1#54674 [www.test.com A] [pool member check succeeded (10.1.10.20:10.1.10.20) - pool member state is available (green)] [ratio selected pool member (10.1.10.20:10.1.10.20) - ratio counter (17) is higher] [pool member check succeeded (10.1.10.21:10.1.10.21) - pool member state is available (green)] [ratio skipped pool member (10.1.10.21:10.1.10.21) - ratio counter (17) is not higher] [ratio selected pool member (10.1.10.20:10.1.10.20) with the first highest ratio counter (17)] [ratio selected pool member (10.1.10.20:10.1.10.20)]
Dec 8 00:13:04 bigip1 info tmm[17565]: 2023-12-08 00:13:03 bigip1 qid 54376 from 10.1.10.1#54675: view none: query: www.test.com IN A +E (10.1.10.240%0)
Dec 8 00:13:04 bigip1 info tmm[17565]: 2023-12-08 00:13:03 bigip1 qid 54376 from 10.1.10.1#54675 [www.test.com A] [pool member check succeeded (10.1.10.20:10.1.10.20) - pool member state is available (green)] [ratio selected pool member (10.1.10.20:10.1.10.20) - ratio counter (16) is higher] [pool member check succeeded (10.1.10.21:10.1.10.21) - pool member state is available (green)] [ratio selected pool member (10.1.10.21:10.1.10.21) - ratio counter (17) is higher] [ratio selected pool member (10.1.10.21:10.1.10.21) with the first highest ratio counter (17)] [ratio selected pool member (10.1.10.21:10.1.10.21)]
Dec 8 00:13:04 bigip1 info tmm[17565]: 2023-12-08 00:13:03 bigip1 qid 14681 from 10.1.10.1#54676: view none: query: www.test.com IN A +E (10.1.10.240%0)
Dec 8 00:13:04 bigip1 info tmm[17565]: 2023-12-08 00:13:03 bigip1 qid 14681 from 10.1.10.1#54676 [www.test.com A] [pool member check succeeded (10.1.10.20:10.1.10.20) - pool member state is available (green)] [ratio selected pool member (10.1.10.20:10.1.10.20) - ratio counter (16) is higher] [pool member check succeeded (10.1.10.21:10.1.10.21) - pool member state is available (green)] [ratio skipped pool member (10.1.10.21:10.1.10.21) - ratio counter (16) is not higher] [ratio selected pool member (10.1.10.20:10.1.10.20) with the first highest ratio counter (16)] [ratio selected pool member (10.1.10.20:10.1.10.20)]
4、总结
在使用比例算法时,如果DNS请求量较小,或者对短期的效果要求较高,建议使用较小的数字作为比例,比如10:20。不要使用数字0作为比例,如果你不想给某个成员分配流量,可以直接将其禁用。