-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Introduce full FIFO pool implementation #1869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a0015db
to
62ba0e2
Compare
Thanks for sharing this 👍 As I understand there are 3 improvements:
Am I missing something? Those are nice features, but TBH none of them look critical enough to duplicate so much code which is complex enough even now. I think we can implement 2) by adding some random time to And I think we can completely ignore 3) for now - that is a non-critical performance improvement and we can do / not do it later. That leaves 1) which as I understand collects some stats about the number of idle conns in the pool for the last X seconds. Then it uses it to close some connections. That is an interesting way to do it even though such connections are not necessary idle - they just happen to be in the pool and not used for some short period of time. I guess we could achieve similar results by just randomly closing a connection once a minute. If it is unused - good, eventually we will close all idle conns. If not, then we will open a new connection. What do you think? |
- Using interface instead of specific pointer type - Introduce FIFO connection pool implementation - Add necessary tests Signed-off-by: Jason Joo <hblzxsj@gmail.com>
62ba0e2
to
40de38c
Compare
Thanks for your reply, Vladimir
I think you have covered all the main points.
It should work. It's an alternated way to do that. And it's definitely a standalone optimisation and can be treated as a small PR.
If we are talking about the FIFO pool, it's a little significant overhead. Because get/put a connection is the most frequent operations, and by copying all the time it's a O(n) time complexity compared to O(1) in stack pool.
There was a small gap on it. The moving window counter works only for FIFO pool not stack pool. Because in a FIFO pool, no connections could get actually idled except we don't have any traffic which it's a special case. How do you think of it? |
It is an interesting idea and I guess it should work fine if we add the
True, but only if we use an efficient linked implementation - no interface{} and no allocations. Otherwise linked list can be slower for small pools. |
Oh really? Do you mean the element structure used by the linked list, or the conversion to and from |
Yep, and that is even more code which is why I guess it rarely happens in practice and people continue to use slices... |
Yeah. Or just make it simple, how about open the ability to use a user implemented connection pool when creating a client? |
That is a possibility but requires moving and exporting everything (including *Conn) from internal/pool. |
Key Points
Notes
In this PR the
PoolFIFO bool
is replaced with a more extensiblePoolType
. It just follows our previous implementation and I don't insist on it. But I think atype
makes more sense than aboolean
. Certainly, we should also consider the backward compatibility.Detail Design
Please refer to Design on the FIFO connection pool (#1868)