Reputation: 1116
I've got 3 redis servers, 1 master & 2 slaves. Currently just the 1 sentinel running, which is monitoring them all well. It will promote whichever instance when required and is really smooth.
The problem i currently have is communicating with it from C#. From my googling, it would appear that only csredis supports the sentinel for retrieving slaves/masters. So using code like this...
//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);
This works, absolutely fine and the various responses change when i kill an instance. However, it's incredibly slow!
If i create the manager and try and get the slave 5 times, then it takes around 1second per slave request, which is crazy slow. What i have noticed, is that the very first request is very, very fast. See the code below...
//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);
}
Here is the output...
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
Which is odd, the first one is 4ms! Then it's taking an age to get any subsequent clients. So i try another test, creating a new SentinelManager every loop item, is that faster? Nope, exactly the same. First one is very quick, then very very slow.
Am i using this library wrong, or have I found a bug? Going to try and grab the source and step through it...
Cheers guys...
Upvotes: 3
Views: 2288
Reputation: 1116
I've found the problem here, it's an issue with the client. In it's dispose method it's taking around 1s to dispose of some async objects.
Upvotes: 1