StackExchange / StackExchange.Redis

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

Connections dramatically increased after upgrade from 2.2.4 to latest 2.6.122 #2515

Closed piscogit closed 1 year ago

piscogit commented 1 year ago

We have redis cluster with about 40 servers. we have seen after upgrading from v2.2.4 to v2.6.122 that the overall connections almost multiplied in our cluster. this behaviour also apears localy, single app instance open almost as twice tcp connections with the newer version. With the new version we hit the default 10K clients limit for single node. Does this behaviour is normal ? is theres a way to revert it ?

mgravell commented 1 year ago

There are no intentional/structural changes to the number of connections.

You say you're hitting a 10k client limit. How many client nodes are connecting here? What is the connection model? Connections in SE.Redis are intended to be long-lived and massively reused; that should mean that in most cases you have just 2 connections per connecting process (1 connection if you have pub/sub disabled, or if we get RESP3 completed).

If this doesn't match what you're seeing: maybe check when you are creating (connecting) multiplexers; is it "create a new one every request", for example? Also, how long do your processes last? If your processes are incredibly short lived ("serverless", etc) - then maybe this is an unclean disconnect scenario?

piscogit commented 1 year ago

We have many processes that queries redis cluster using batches . Each batch contains thousends of keys. Inside single process were are not multithreading the batches. each proces uses single connectionMultiplexer. the connectionMultiplexer created once per process & the process is very long lived.

After upgrading from 2.2.4 to latest without any code modifications the number of connections per single instance is almost multiplied.

mgravell commented 1 year ago

Then no: that isn't expected.

I can't tell just from that what the cause might be. Hooking the ConnectionFailed event (and others) might be a good starting point, to see if anything interesting is reported. Beyond that... what environment is this? Vanilla on-prem redis? Some specific cloud offering (if so: what?)? Is TLS involved? What runtime/OS? Anything that might help isolate something unusual. But: sounds odd.

On Sat, 29 Jul 2023, 17:01 piscogit, @.***> wrote:

We have many processes that queries redis cluster using batches . Each batch contains thousends of keys. Inside single process were are not multithreading the batches. each proces uses single connectionMultiplexer. the connectionMultiplexer created once per process & the process is very long lived.

After upgrading from 2.2.4 to latest without any code modifications the number of connections per single instance is almost multiplied.

— Reply to this email directly, view it on GitHub https://github.com/StackExchange/StackExchange.Redis/issues/2515#issuecomment-1656764737 or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAEHMDEV737Z6BRBOQOGADXSUXWHBFKMF2HI4TJMJ2XIZLTSOBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDUOJ2WLJDOMFWWLLTXMF2GG2C7MFRXI2LWNF2HTAVFOZQWY5LFUVUXG43VMWSG4YLNMWVXI2DSMVQWIX3UPFYGLLDTOVRGUZLDORPXI6LQMWWES43TOVSUG33NNVSW45FGORXXA2LDOOJIFJDUPFYGLKTSMVYG643JORXXE6NFOZQWY5LFVAYTONZUHAYTQM4CUR2HS4DFUVUXG43VMWSXMYLMOVS2UMJYGI3TIOJZGI4TRJ3UOJUWOZ3FOKTGG4TFMF2GK . You are receiving this email because you commented on the thread.

Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub .

piscogit commented 1 year ago

First of all thanks for replying. the environment is vanilla on-prem. I will try your offer for hooking events.

NickCraver commented 1 year ago

I upgrading from that old, I'd guess it's likely subscription connections actually working correctly in later versions (they didn't always), but you can disable this if you aren't using pub/sub with e.g. $SUBSCRIBE= in your connection string or editing the command map in code: https://stackexchange.github.io/StackExchange.Redis/Configuration#automatic-and-manual-configuration

mgravell commented 1 year ago

You never did specify what the multiplier is here; if it is ~x2, then that ^^^ is a possibility, but the way I interpreted the question, you were seeing a much higher multiplier.

NickCraver commented 1 year ago

Agreed, I'm unclear here too - I was parsing "single app instance open almost as twice tcp connections with the newer version" as my only clue there. More info would help us advise!

mgravell commented 1 year ago

Lol, I totally missed the "almost as twice" - I saw the "multiplied" and must have scanned over the other.

In that case, yes: adding $SUBSCRIBE= to the connection strings should help.

Depending on what server version you're using, if/when we ship RESP3 (hopefully soon), you might be able to get the benefits of pub/sub without additional connections.

NickCraver commented 1 year ago

If there's more info, happy to answer, but closing out to tidy up for now.