vapor / async-kit

Sugary extensions for the SwiftNIO library
MIT License
71 stars 25 forks source link

pool: replacing closed connections #41

Closed tanner0101 closed 5 years ago

tanner0101 commented 5 years ago

The connection pool currently replaces closed available connections by replacing them when they are requested. This means that once a pool's active connection count increases, it will never decrease.

It would be better to check the available connections list first for any open connections before attempting to open a new replacement.

MrMage commented 5 years ago

In case you are interested, here's my current thread-safe "resource pool" implementation with pruning. Working well in practice, but would need some adaptations for Vapor, of course: https://gist.github.com/MrMage/6fe071f405ac2c1b8a4cde25f05061db

Surprisingly, it is actually shorter than the Vapor one even though it supports pruning (mostly due to the lack of documentation, I guess).

tanner0101 commented 5 years ago

I ended up going with a while loop that I think will do the job: https://github.com/vapor/async-kit/blob/master/Sources/AsyncKit/ConnectionPool.swift#L214-L226