codewinsdotcom/PostgresClientKit

Please migrate from BlueSocket and BlueSSLService to swift-nio

sdpopov-keyvariable opened this issue · 7 comments

Migrate from BlueSocket and BlueSSLService to definitely preferred Apple's open source swift-nio.

Currently BlueSocket and BlueSSLService block modern versions of swift-argument-parser. They depend on 'swift-argument-parser' 0.4.1..<1.0.0. It's definitely wrong when networking libraries (not their applications) depend on argument parser.

NIO has its own PG library (https://github.com/vapor/postgres-nio). Though PG access doesn't really make sense in a non-blocking context in the first place. Would be nice to keep that as a proper blocking lib.

Let's move the swift-argument-parser version constraint problem to #42.

And use this issue (#41) to explore the bigger question of moving PostgresClientKit from BlueSocket/BlueSSLService to swift-nio.

(1) I'd also like to be rid of BlueSocket/BlueSSL in favor of Network Framework, which is already baked into macOS, iOS, watchOS, and tvOS. I've moved all my API services from Swift-NIO to NW-framework and not looking back. NIO is somewhat long in the tooth and I consider it bloatware at this point. WIth no async/await and now only Vapor as its chief supporter, one has to wonder how long NIO will be maintained in its current form.

(2) Speaking of async/await... Overall performance and ease-of-use would also be improved if PostgresClientKit moved to an async/await model instead of dispatch. Dispatch is not totally dead, but it's slow-walking toward the graveyard.

I agree that removing the BlueSocket/BlueSSLService dependencies is highly desirable. Thank you for your thoughts about SwiftNIO vs. Network Framework. Right now, I don't know enough to have my own opinion on this. @helje5, you have written about this. Do you have any further guidance on selecting a framework for a non-HTTP TCP client?

I see how an async/await API would be helpful for ConnectionPool, replacing the completion handler pattern. Do you see benefit to async APIs elsewhere?

  1. Thanks for the update. Please see my comment over at #10.

  2. Thanks for sharing your experience and thoughts on Swift NIO & Network Framework. Appreciated!

Thanks, David, for your expeditious assistance. I went back and re-read the API docs. And sure enough, for socketTimeout: "The timeout for socket operations, in seconds, or 0 for no timeout." In my mind, I was mistakenly reading this as "The timeout for the socket to complete the connection." It's much clearer to me now that this means ALL socket operations for a given connection, including wait time for the remote server to respond.

My initial 10-second value wasn't causing a problem at first. But as my API service has become more and more busy, this value was not allowing enough time between the Execute statement and when a loaded-down, remote server could finally respond. I wasn't comfortable with a "never timeout." So I've set the production value to 300 and it seems to be humming along in splendid fashion, even in SSL mode. More CPUs in the AWS config are certainly on the docket as well.