-
Couldn't load subscription status.
- Fork 1.5k
Open
Labels
Description
I created two simple console apps with same code.
Set single cache, get 10 times with single thread, compile in release mode.
Test was performed on same client VM, pointing to same Redis cluster (v6) using same connection string.
Left - StackExchange.Redis 1.2.6 + .Net Framework 4.5.2
Right - StackExchange.Redis 2.6.7 + .Net Framework 4.8
New driver GET is 2-4 times slower.
Wondering whether there is a TURBO button I haven’t pressed within new driver?
Did I miss anything?
`static async Task Main(string[] args)
{
var sizeOfKeyInKB = !args.Any() || string.IsNullOrWhiteSpace(args[0]) ? 10000 : int.Parse(args[0]);
var iteration = !args.Any() || string.IsNullOrWhiteSpace(args[1]) ? 10 : int.Parse(args[1]);
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(_redisConnectionString);
IDatabase db = redis.GetDatabase();
TestSync(sizeOfKeyInKB, iteration, db);
await TestAsync(sizeOfKeyInKB, iteration, db);
}
private static void TestSync(int sizeOfKeyInKB, int iteration, IDatabase db)
{
var key = ($"{version}_Sync_" + Guid.NewGuid().ToString()).ToLower();
var timer = new Stopwatch();
timer.Start();
db.StringSet(key, new string('*', sizeOfKeyInKB * 1000));
timer.Stop();
Console.WriteLine($"{DateTime.Now} PST - {version}_Set key {key} - {sizeOfKeyInKB / 1000} MB - {timer.Elapsed.TotalSeconds:0.00}s");
for (int i = 1; i <= iteration; i++)
{
timer.Restart();
try
{
var cache = db.StringGet(key);
if (!cache.HasValue)
Console.WriteLine($"{DateTime.Now} PST - Failed get cache {key}");
}
catch (Exception ex)
{
Console.WriteLine($"{DateTime.Now} PST - {version}_GET Exception {ex}");
}
timer.Stop();
Console.WriteLine($"{DateTime.Now} PST - {version}_GET Iteration {i} - {sizeOfKeyInKB / 1000} MB - {timer.Elapsed.TotalSeconds:0.00}s ");
}
timer.Restart();
db.KeyDelete(key);
timer.Stop();
Console.WriteLine($"{DateTime.Now} PST - {version}_Delete key {key} - {sizeOfKeyInKB / 1000} MB - {timer.Elapsed.TotalSeconds:0.00}s");
}
private static async Task TestAsync(int sizeOfKeyInKB, int iteration, IDatabase db)
{
var key = ($"{version}_Async_" + Guid.NewGuid().ToString()).ToLower();
var timer = new Stopwatch();
timer.Start();
await db.StringSetAsync(key, new string('*', sizeOfKeyInKB * 1000));
timer.Stop();
Console.WriteLine($"{DateTime.Now} PST - {version}_SetAsync key {key} - {sizeOfKeyInKB / 1000} MB - {timer.Elapsed.TotalSeconds:0.00}s");
for (int i = 1; i <= iteration; i++)
{
timer.Restart();
try
{
var cache = await db.StringGetAsync(key);
if (!cache.HasValue)
Console.WriteLine($"{DateTime.Now} PST - Failed get cache {key}");
}
catch (Exception ex)
{
Console.WriteLine($"{DateTime.Now} PST - {version}_GetAsync Exception {ex}");
}
timer.Stop();
Console.WriteLine($"{DateTime.Now} PST - {version}_GetAsync Iteration {i} - {sizeOfKeyInKB / 1000} MB - {timer.Elapsed.TotalSeconds:0.00}s ");
}
timer.Restart();
await db.KeyDeleteAsync(key);
timer.Stop();
Console.WriteLine($"{DateTime.Now} PST - {version}_DeleteAsync key {key} - {sizeOfKeyInKB / 1000} MB - {timer.Elapsed.TotalSeconds:0.00}s");
}`
