定期嗅探

740 发布于: 2021-03-25 读完约需 1 分钟

SupportsReseeding返回结果为true的连接池可被配置成定期嗅探。除了在启动时嗅探和故障时嗅探之外,定期嗅探还在集群经常在高峰时间水平伸缩的场景中有帮助。应用程序可能拥有节点子集的健康视图,但如果不定期嗅探,它将永远无法找到作为水平扩展的而添加的节点:

var audit = new Auditor(() => VirtualClusterWith
    .Nodes(10)
    .MasterEligible(9202, 9203, 9204)
    .ClientCalls(r => r.SucceedAlways())
    .Sniff(s => s.SucceedAlways(VirtualClusterWith
        .Nodes(100)
        .MasterEligible(9202, 9203, 9204)
        .ClientCalls(r => r.SucceedAlways())
        .Sniff(ss => ss.SucceedAlways(VirtualClusterWith
            .Nodes(10)
            .MasterEligible(9202, 9203, 9204)
            .ClientCalls(r => r.SucceedAlways())
        ))
    ))
    .SniffingConnectionPool()
    .Settings(s => s
        .DisablePing()
        .SniffOnConnectionFault(false)
        .SniffOnStartup(false)
        .SniffLifeSpan(TimeSpan.FromMinutes(30))
    )
);

正常集群所有节点均返回正常响应:

audit = await audit.TraceCalls(
    new ClientCall { { HealthyResponse, 9200 } },
    new ClientCall { { HealthyResponse, 9201 } },
    new ClientCall { { HealthyResponse, 9202 } },
    new ClientCall { { HealthyResponse, 9203 } },
    new ClientCall { { HealthyResponse, 9204 } },
    new ClientCall { { HealthyResponse, 9205 } },
    new ClientCall { { HealthyResponse, 9206 } },
    new ClientCall { { HealthyResponse, 9207 } },
    new ClientCall { { HealthyResponse, 9208 } },
    new ClientCall { { HealthyResponse, 9209 } },
    new ClientCall {
        { HealthyResponse, 9200 },
        { pool => pool.Nodes.Count.Should().Be(10) }
    }
);

现在我们把时钟拨快31分钟。嗅探生命周期现在应该失效了,第一个调用应该执行嗅探,它会发现我们已经扩展到100个节点了!

audit.ChangeTime(d => d.AddMinutes(31));

audit = await audit.TraceCalls(
    new ClientCall {
        { SniffOnStaleCluster },
        { SniffSuccess, 9202 },
        { HealthyResponse, 9201 },
        { pool => pool.Nodes.Count.Should().Be(100) }
    }
);

如果我们把时钟再往前移31分钟,现在会发现我们已经缩小到10个节点了:

audit.ChangeTime(d => d.AddMinutes(31));

audit = await audit.TraceCalls(
    new ClientCall {

        { SniffOnStaleCluster },
        { SniffSuccess, 9202 },
        { HealthyResponse, 9200 },
        { pool => pool.Nodes.Count.Should().Be(10) }
    }
);

版权声明:本作品系原创,版权归码友网所有,如未经许可,禁止任何形式转载,违者必究。

发表评论

登录用户才能发表评论, 请 登 录 或者 注册