StackExchange / StackExchange.Redis

General purpose redis client
https://stackexchange.github.io/StackExchange.Redis/
Other
5.84k stars 1.5k forks source link

threads hanging on production when using transaction #2695

Open pianoman4873 opened 2 months ago

pianoman4873 commented 2 months ago

Hello, I have a synchronous method which does the following -

var transaction = _connectionMultiplexer.GetDatabase(0).CreateTransaction();

var returnValueTask = transaction.HashSetAsync(key, KeyValuePairsToHashEntries(keyValuePairs));

transaction.KeyExpireAsync(key, expiry);

var success = transaction.Commit(); if (!success) throw new Exception("transaction failed");

return returnValueTask.Result;

I've load tested it locally (100 threads doing the same to either the same key or different keys ) everything seems to be working fine, but we've seen in production env that pretty frequently the transactions don't seem to complete ( or take very long to complete ).

Am I doing something wrong in the code ? ( other than the method being synchronous which is a prerequisite ). Could you suggest an alternative to simulate atomic writing of both the hash and the expiry ?

Thanks in advance !