-
Couldn't load subscription status.
- Fork 16
RFC: Update API to enable connection re-use, allow streaming… #138
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
|
@brienw, @holetse, @rjanja, @svoynow here's a quick draft on how we could enable connection reuse with SSHKit.ex. Since this could possibly speed up deployments, I thought you might be interested 🙂 We haven't updated the package in a while and now with some distance I have a few new ideas. I'd be happy about your thoughts on the API design. It adds another parameter to the main functions, but at the same time cleanly separates (execution) context from connection information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ace @pmeinhardt 🙇
I vaguely remember we discussed this topic a while ago... 🤔 In my personal opinion, this makes the API way cleaner and a lot more "natural" to use (see my comment about upload, run and probably also download...)
|
Thanks a lot for the great round today @klappradla, @lwassermann and @andreasknoepfle ❤️ ❤️ Here's a quick braindump:
I've updated the PR description as well to integrate some of the results. Cheers 👋 and again much ❤️ |
|
As an additional note: mint uses a message-based API that we can draw inspiration from: {:ok, conn} = Mint.HTTP.connect(:http, "httpbin.org", 80)
{:ok, conn, request_ref} = Mint.HTTP.request(conn, "GET", "/", [], "")
receive do
message ->
{:ok, conn, responses} = Mint.HTTP.stream(conn, message)
IO.inspect responses
endI think this could work very similarly for SSH connect, run, stream… |
|
Closing in favor of #164 😊 |
Related to: #41
Description
Update the top-level SSHKit API in order to reuse SSH connections across SSHKit operations, i.e.
SSHKit.run/3,SSHKit.upload/4andSSHKit.download/4.The updated API could look as follows (feedback welcome):
cf. current README.md
Additional considerations
A major idea/API change that may play into this draft is how we handle stdout/stderr streaming which is an interesting case we did not handle in SSHKit 0.x but is definitely interesting to give quicker user feedback, e.g. on deployment cases as with bootleg (see the alt.
captureimplementation).This might solve/play into #53 as well.
Make context optional?
With the API update, context could be made an optional or keyword argument, because for some things you want to run, you might not need any user/group/path/env/umask changes.
Update host struct
There was a request to include host information in result tuples #132 and Bootleg defines a
%Host{}struct to assign aname, we should consider addingnameand possiblytagsto hosts.Motivation and Context
At the moment, SSHKit is establishing a new connection for every command. The outlined API changes could allow us to reuse established connections for multiple consecutive operations and improve the speed with which server automation tasks can be carried out. Deployments with bootleg (cc @labzero) for instance could benefit from this.
Discussion: Alternative Designs
As #41 outlines, we could also use a (GenServer) process to cache connections. This however means that it would be harder/not possible to - for instance - open multiple connections to the same server.
It also seems more explicit and conceptually cleaner to separate execution context (
SSHKit.context/0) from connection information (the newconnstruct).Types of changes
Checklist
## mastersection).