gpt4 book ai didi

c# - Redis Sentinel C# 客户端

转载 作者:IT王子 更新时间:2023-10-29 06:02:31 26 4
gpt4 key购买 nike

我有 3 个 redis 服务器,1 个主服务器和 2 个从服务器。目前只有 1 个哨兵在运行,它正在很好地监视它们。它会在需要时升级任何实例,并且非常流畅。

我目前遇到的问题是从 C# 与它通信。从我的谷歌搜索来看,似乎只有 csredis 支持用于检索奴隶/主人的哨兵。所以使用这样的代码...

//Create a manager, which has all the sentinels in it (this would have 3 when we go live)
RedisSentinelManager sentman = new RedisSentinelManager("localhost:26379");

//Get a slave, as these are read-only
sentman.GetSlave("mymaster", 100, 100);

//Get a master, for storing an object
sentman.GetMaster("mymaster", 100, 100);

这行得通,绝对没问题,当我杀死一个实例时,各种响应都会发生变化。但是,它的速度非常慢!

如果我创建管理器并尝试获取从站 5 次,那么每个从站请求大约需要 1 秒,这太慢了。我注意到,第一个请求非常非常快。看下面的代码...

//Try and get 5 slaves
for ( int i = 0; i < 5; i ++ )
{
Stopwatch a = Stopwatch.StartNew();
var slave = sentman.GetSlave("mymaster", 50, 50);

if (slave == null)
Console.WriteLine("Failed to get slave");

Console.WriteLine("Took " + a.ElapsedMilliseconds.ToString() + "ms to get " + slave.Host + ":" + slave.Port);
}

这是输出...

Took 4ms to get localhost:6400
Took 844ms to get localhost:6400
Took 1007ms to get localhost:6400
Took 999ms to get localhost:6400
Took 994ms to get localhost:6400

这很奇怪,第一个是 4 毫秒!然后需要很长时间才能获得任何后续客户。所以我尝试另一个测试,为每个循环项目创建一个新的 SentinelManager,这样更快吗?不,完全一样。第一个非常快,然后非常非常慢。

我是不是用错了这个库,还是我发现了一个错误?将尝试获取源代码并逐步完成它...

大家好...


最佳答案

我在这里发现了问题,这是客户端的问题。在它的 dispose 方法中,处理一些异步对象大约需要 1 秒。

关于c# - Redis Sentinel C# 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22908507/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com