-
Notifications
You must be signed in to change notification settings - Fork 334
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
ClientManager #23
ClientManager #23
Conversation
I don't think the Go 1.4.3 failure in Travis is my doing, but I could be wrong. |
Thanks for the pull request @dwieeb |
@sideshow You're welcome. Does everything look good? |
Behaviors of |
@AlphaPigger Right, it's not a "connection" pool one would be used to. What would a better name be? |
|
Okay, that's renamed. All ready. |
Is there any update on this? |
@dwieeb Sorry for the delay on reviewing this. We are doing something very similar in an internal project which is used in production, so my way of testing this was to try swapping out our current implementation for yours which looks superior. I think this will be an awesome addition to the library. Thanks again an will try and review shortly. |
@sideshow Great to hear! I look forward to pulling this in. |
@sideshow Have you had time to review it again? Really looking forward to having this in the library. |
Is only me seeing the problem with potential connection leaking (after eviction) in this code? |
Hey @dwieeb We are currently trying to merge into a large project to test. |
@nordicdyno can you be more specific. Thanks |
@sideshow There is no explicit disconnection before |
@nordicdyno I ran some tests and this does leak/hold connections open after they are removed from the ConnectionManager. We need some kind of explicit CloseConnections method on the client which we can call before removing them. @dwieeb with the exception of this, it has been tested and is ready to merge. I just want to fix this before I merge in (any help appreciated). Thanks again for the code! |
@nordicdyno @sideshow To me, this is normal behavior. See https://golang.org/src/net/http/transport.go#L54
I believe this PR has merely revealed a larger issue with this library, in that anyone who is "accessing many hosts" (by creating many Clients) will have connections left open. I also believe this is fine (it is the normal behavior of the http go libs). If we want to address this, we can provide configuration options for |
@dwieeb "I believe this PR has merely revealed a larger issue with this library" Agree with this. I will go ahead and merge and we can address this as a seperate issue. Thanks again for the PR! |
Here's an implementation of a potential client pool for this library. The request originated from #21. It has a few features one might expect in a pool, such as a maximum size and age (both of which can be disabled), as well as a way to create clients automatically if not found in the pool. Clients are looked up by doing a sha1 hash of the credential's bytes.
Implementation is basically a LRU cache with an optional time constraint. Lookups are O(1) using a map. LRU is achieved with a doubly linked list. These data structures are not thread safe, but the implementation should be thread safe as a simple mutex is wrapped around each potentially unsafe method.
I have not used this version in production. I wanted to submit this early to open discussion. What are some likes/dislikes, etc.
@sideshow @c3mb0 @nordicdyno
Credit to bradfitz: https://github.com/golang/groupcache/blob/master/lru/lru.go