Skip to content

add connection pool put back#571

Closed
wuzuoliang wants to merge 1 commit into
gomodule:masterfrom
wuzuoliang:master
Closed

add connection pool put back#571
wuzuoliang wants to merge 1 commit into
gomodule:masterfrom
wuzuoliang:master

Conversation

@wuzuoliang

Copy link
Copy Markdown

No description provided.

@stevenh

stevenh commented Sep 14, 2021

Copy link
Copy Markdown
Collaborator

Hi @wuzuoliang could you describe what issue this is trying to fix?

@stevenh

stevenh commented Sep 30, 2021

Copy link
Copy Markdown
Collaborator

Just following up on this @wuzuoliang ?

@wuzuoliang

Copy link
Copy Markdown
Author

something like this
redis/go-redis#1820

@stevenh

stevenh commented Oct 11, 2021

Copy link
Copy Markdown
Collaborator

something like this go-redis/redis#1820

That's an example of a similar function, but what is the benefit of that?

@TangJia025

Copy link
Copy Markdown

waiting for this pr

@stevenh

stevenh commented Nov 15, 2021

Copy link
Copy Markdown
Collaborator

I can't see the benefit of this I'm afraid. Are you able to explain why this is needed?

@TangJia025

Copy link
Copy Markdown

the LIFO connection get mode will lead to load inbalance
when conns in some redis proxy is more than others, the gap will get wider with time going by

@stevenh

stevenh commented Nov 16, 2021

Copy link
Copy Markdown
Collaborator

Sorry I don't follow what do you mean by load in balance?

@tangtj

tangtj commented Nov 27, 2021

Copy link
Copy Markdown

We use Alibaba Cloud's redis. Cloud redis consists of redis and redis proxy. When a client connects to cloud redis, conn forwards it to the corresponding redis through a proxy. A cloud Redis instance usually has multiple proxies. The current redigo conn pool uses fifo mode. It will use the most recently used conn first, and the agents connected later will be busier than other agents. Changing to lifo mode will more balance the load of multiple agents.

1961638003855_ pic

@stevenh

stevenh commented Nov 28, 2021

Copy link
Copy Markdown
Collaborator

Thanks for the details. Seems like the unbalanced nature is actually an issues with the LB which is choosing which proxy the client is connecting to.

FIFO nature of is required to ensure unused connections are freed up when not needed. Without this a spike in connections can never be reduced. FIFO should not adversely impact the behaviour of the setup you described, as long as the LB is doing its job correctly.

So the question is what is doing the load balancing between the client and the 3 proxies?

@tangtj

tangtj commented Nov 29, 2021

Copy link
Copy Markdown

The LB decides which proxy to use when creating a connection. After the establishment is successful, the proxy will not be replaced. So the fifo mode will make the conn at the front of the pool take more work.

@stevenh

stevenh commented Nov 29, 2021

Copy link
Copy Markdown
Collaborator

If I understand the description of the problem correctly it sounds like the issue is with the proxy, so that's where the fix should be done. This is because, as mentioned, changing the pool to LIFO breaks connection clean up so is not something we should do.

@tangtj

tangtj commented Nov 29, 2021

Copy link
Copy Markdown

Just add an option and let the user decide.

@tangtj

tangtj commented Nov 29, 2021

Copy link
Copy Markdown

I may not explain clearly, please refer to for details redis/go-redis#1819 .

@stevenh

stevenh commented Nov 29, 2021

Copy link
Copy Markdown
Collaborator

Just add an option and let the user decide.

The problem with that is it will break connection clean up, causing a different problem.

@stevenh

stevenh commented Nov 30, 2021

Copy link
Copy Markdown
Collaborator

I may not explain clearly, please refer to for details go-redis/redis#1819 .

I understand the problem, in short LIFO results in unbalanced use of connections in the pool, but this is by design to ensure that old connections are expired.

That said if the pool is seeing load which requires multiple concurrent connections and the LB created said connections across the servers evenly to start with you should see relatively consistent server use too. If the connections aren't created evenly then switching to FIFO won't solve the problem, and if the load doesn't demand multiple concurrent connections then I would argue there's no need for multiple servers anyway.

As mentioned switching to FIFO will break connection clear down and result in pool being unable to reduce its size from peak, which is a nasty side effect. This is actually something that I fixed in the database/sql too.

In your case what is doing the load balancing, and what is your access pattern?

@dreamerjackson

Copy link
Copy Markdown

@stevenh old connections are expired can be solved by have a option to set the max life conn time, then force close the connect

@dreamerjackson

Copy link
Copy Markdown

there is a special condition that the connect rise suddenly and one proxy very slowly, FIFO will always get the slowly connect and the state will continued

@stevenh

stevenh commented Dec 13, 2021

Copy link
Copy Markdown
Collaborator

there is a special condition that the connect rise suddenly and one proxy very slowly, FIFO will always get the slowly connect and the state will continued

I'm not sure what you're trying to say here, could you clarify?

@tangtj

tangtj commented Dec 24, 2021

Copy link
Copy Markdown

about break connection clear down and result in pool to reduce its size from peak. I think it can be resolved. #589

@tangtj tangtj mentioned this pull request Dec 24, 2021
@seamusopen

Copy link
Copy Markdown

I may not explain clearly, please refer to for details go-redis/redis#1819 .

I understand the problem, in short LIFO results in unbalanced use of connections in the pool, but this is by design to ensure that old connections are expired.

That said if the pool is seeing load which requires multiple concurrent connections and the LB created said connections across the servers evenly to start with you should see relatively consistent server use too. If the connections aren't created evenly then switching to FIFO won't solve the problem, and if the load doesn't demand multiple concurrent connections then I would argue there's no need for multiple servers anyway.

As mentioned switching to FIFO will break connection clear down and result in pool being unable to reduce its size from peak, which is a nasty side effect. This is actually something that I fixed in the database/sql too.

In your case what is doing the load balancing, and what is your access pattern?

Slow connection processing results in a connection that is always at the end of the queue and is not eliminated because it is idle. In this way, even if the LB creates new connections evenly between server nodes, the less performing server nodes will have more connections。

@stevenh

stevenh commented Dec 30, 2022

Copy link
Copy Markdown
Collaborator

If you're talking about a single or small number connections then that should have little to no impact, so I'm still struggling to understand the issue?

@wuzuoliang

Copy link
Copy Markdown
Author

cancel

@wuzuoliang wuzuoliang closed this Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants