Comments (2)
I benchmarked the opening of SSH channels, here were the results, the connections for each were opened 1_000 times.
Rehearsal -------------------------------------------------
with ssh key 0.500000 0.090000 0.590000 ( 7.526066)
with password 0.470000 0.100000 0.570000 ( 7.342561)
---------------------------------------- total: 1.160000sec
user system total real
with ssh key 0.510000 0.090000 0.600000 ( 7.381403)
with password 0.500000 0.100000 0.600000 ( 7.513771)
That tells me that it's fast enough, call it 0.007s (7ms) to open a connection, under good conditions, and it should be fast enough for a first implementation.
So saying that, let's say an implementation of on()
might look like this:
def on(hosts, options = {}, &block)
pool = ConnectionPool.new(hosts)
pool.execute(&block, options)
pool.terminate
end
from sshkit.
And further to that, a naïve pseudo implementation of ConnectionPool
:
require 'net/ssh'
class ConnectionPool
Error = Class.new(RuntimeError)
attr_reader :members, :hosts
def initialize(hosts)
@hosts = hosts
@members = {}
end
def perform(&block)
begin
# Something here needs to support
# parallel/sequential/limit/etc
members.each do |host, session|
yield host
end
rescue # Suitable Exception list here
raise ConnectionPool::Error
ensure
terminate
end
end
def terminate
members.map(&:close)
end
private
def open_connections
begin
hosts.each do
members[host] = Net::SSH::Session.new(host)
end
rescue Net::SSH::Authentication::AgentError,
Net::SSH::Authentication::KeyManagerError,
Net::SSH::AuthenticationFailed,
Net::SSH::ConnectionTimeout,
Net::SSH::Exception
# Etcetera
terminate
raise ConnectionPool::Error
end
end
end
With the beginnings of this in mind, I see the following problems:
- I'm starting to dislike the name "ConnectionPool", as we're having stubbed/test backends, we should be careful to come up with a useful name that fits all the paradigms we care about. (HostPool?)
- Further to the first point, It's not just a pool in my naïve implementation, it's also responsible for doing some work, this is a limitation of my spike in the Github issue, and something that we could solve by renaming/redesigning slightly (and I think we should)
- I don't see a nice way to handle the parallel vs. sequential with(±out) limits here, again, splitting this functionality into two classes might be wise.
- Maybe we could have something that checks-out connections from the pool, this could block until a connection is ready (pool would handle :limit) but the something would handle parallel vs. sequential. This something would then be responsible for threading, and/or forking. This way the parallel/sequential option is separated from the handling of the connections.
from sshkit.
Related Issues (20)
- undefined method `[]' for nil:NilClas HOT 5
- within(dir) fails now when dir is an empty string or nil HOT 3
- Upgrade to mocha 1.10+ HOT 1
- Unknown constant SSHKit::MappingInteractionHandler HOT 5
- getaddrinfo HOT 5
- connection pool session keepalive HOT 5
- whoami and id -a return different users HOT 16
- "connection closed by remote host" (JRuby / Capistrano) HOT 6
- Exports added by :with are ineffective when :user is specified
- Using a single tunnel/gateway/jump host to connect to multiple hosts HOT 5
- Any way to set the ssh port in the DSL? HOT 1
- `could not settle on host_key algorithm (SSHKit::Runner::ExecuteError)` with certificate based authentication HOT 1
- Connections with openssl-3.0.0 fail with incompatibility error HOT 1
- Issue with dependency versions (net-ssh and net-scp versions are incompatible) HOT 1
- Connection pending forever if command to execute is long HOT 2
- Is there travis-ci.com build? HOT 2
- pls delete this issue.
- download! method doesn't close file HOT 1
- Dependency Issue in i18n with the latest version of sshkit HOT 2
- SFTP transfer does not work with Ruby 2.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sshkit.