You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Native async support (asyncio/greenlets/just-use-threads/???) #389
Paramiko has always used regular threads and as far as I'm aware has never been set up to support eventlet/gevent/greenlets in general.
I'm also not 100% sure what it would take to make that work since my personal experience there is lacking. It might only require a few tweaks or it might require serious work in a lot of places.
There are a few 'bug' tickets about this that I've closed: #337, #173.
Reacted by Laël Cellier, Florian Ludwig, Dustin Burke, Nick Mills-Barrett, Hussein Kadiri, Ashish Ranjan, Vladimir Rutsky, Ivan Petukhov, procaff3inator, Martin Weinelt and 16 more
FWIW, there is already a project out there called parallel-ssh that claims to use Paramiko with gevent successfully. Perhaps their use case is limited enough that they haven't run into any issues yet.
asyncore was replaced by asyncio in 3.4 (which has a Python 2.6/2.7 backport called trollius).
If the main purpose of this issue is to track progress towards asynchronous SSH support, shouldn't we rename the issue accordingly and consider asyncio support as another option that could replace having to support gevent (or similar libraries)?
asyncio is the same as 'tulip' right? (EDIT: yup, it is) - yes, I had my eye on that since last PyCon and it feels like the best place to start for this kind of topic.
I've got "look at a better way to do parallelism" on my plate for Fabric 2 (which used multiprocessing + Paramiko, for various reasons), as well as "push Fabric-y things back down into Paramiko where they make sense", so we'll see what happens there.
asyncio at this point is Python 3.X only as Trollius (the port of asyncio to python 2.7) is no longer being maintained. Tornado, gevent and Twisted would represent viable alternatives as they work on both 2.X and 3.X. My personal preference would be Tornado, as it's self contained and well documented (and it also can be integrated with asyncio loop).
Update: I've managed to fix the below by monkey-patching gevent at the start of the executable bin file, rather than the __main__ it imports. So I have Paramiko 1/2 + gevent now working flawlessly in Py2/3.
Also, I recently used paramiko 2.0.2 (through plumbum's PramikoMachine) successfully with the eventlet 0.19 under Python 3.5.2. Everything (uploading/downloading files, long-running commands, etc.) worked flawlessly.
I took a very brief look at it the other week when poking the Fabric 2 alpha's concurrency features (which right now is just "threading works, unlike in v1"). Seemed like some of the linked tickets have various approaches - asyncio, gevent, etc. I didn't have time to deep-dive because I want that alpha to get out first (& that codebase will provide a very nice, easy framework for testing out Paramiko-level feature changes), but it's still a topic I'm interested in.
My first concern when this is fully revisited is finding a useful test case or benchmark, to prove that one of these other approaches brings a significant benefit over high-level threading. My uneducated guess is it would start becoming noticeable once the number of active connections gets above some "the GIL is becoming a serious drain" threshold.
So that, plus an updated overview of the available Python 2+3 compatible options, would be super useful.
@bitprophet I had similar thoughts. I just completed some code using asyncio event loop + ThreadPoolExecutor to get thread-level parallelism with paramiko (netmiko), but I think it's going to suck performance-wise when communicating on more than a few dozen (?hundred?) devices. Process parallelism has its own headaches, and either way we're still blocking on I/O within threads.
I'd like to see paramiko fix the blocking-on-io thing with async/await methods to optimize single-thread performance, and let the users sort out thread-vs-process for their intended app. I can probably contribute to that, but I would like to first hear thoughts on how to proceed -- my bias is to implement new async classes/methods for Python3.5+ and python2.7 can stay the way it is. Thoughts?
Reacted by Ondřej Súkup, sunxiaoyong and peterjasc
If there's no useful 2.7 analogue (my Python ~3.3 era memory is of the 'tulip' backport library, but no idea if that maps to the newer 3.4/3.5 constructs) then yea, "extra goodness if you're on 3.5+" sounds reasonable, as long as the code is organized cleanly. Thanks!
Just to note on performance - pyinfra is using paramiko + gevent (working perfectly) and I've found that this scales amazingly well across hundreds of hosts (limiting the gevent pool to ~75-100 gives the best performance, above that things slow down), especially when compared to threaded solutions like Ansible. There's a chart of results here.
Activity
travcunn commentedon Dec 12, 2014
+1
nchammas commentedon Mar 22, 2015
FWIW, there is already a project out there called parallel-ssh that claims to use Paramiko with gevent successfully. Perhaps their use case is limited enough that they haven't run into any issues yet.
nchammas commentedon Mar 22, 2015
Oh, and to make another connection, there is an (abandoned) PR here to support asynchronous SSH connections by using Python's builtin asyncore library.
asyncore was replaced by asyncio in 3.4 (which has a Python 2.6/2.7 backport called trollius).
If the main purpose of this issue is to track progress towards asynchronous SSH support, shouldn't we rename the issue accordingly and consider asyncio support as another option that could replace having to support gevent (or similar libraries)?
bitprophet commentedon Mar 24, 2015
asyncio is the same as 'tulip' right? (EDIT: yup, it is) - yes, I had my eye on that since last PyCon and it feels like the best place to start for this kind of topic.
I've got "look at a better way to do parallelism" on my plate for Fabric 2 (which used
multiprocessing+ Paramiko, for various reasons), as well as "push Fabric-y things back down into Paramiko where they make sense", so we'll see what happens there.[-]Eventlet/greenlet support[/-][+]Native async support (asyncio/greenlets/just-use-threads/???)[/+]nchammas commentedon Mar 24, 2015
Sounds good to me. Yes, asyncio seems to be the way of the future.
As an example of prior art in this space, you may want to take a look at the asyncssh project, which implements SSH using asyncio.
sivabudh commentedon Jan 8, 2016
+1
giampaolo commentedon Apr 12, 2016
asyncio at this point is Python 3.X only as Trollius (the port of asyncio to python 2.7) is no longer being maintained. Tornado, gevent and Twisted would represent viable alternatives as they work on both 2.X and 3.X. My personal preference would be Tornado, as it's self contained and well documented (and it also can be integrated with asyncio loop).
Fizzadar commentedon Jun 6, 2016
Update: I've managed to fix the below by monkey-patching gevent at the start of the executable bin file, rather than the
__main__it imports. So I have Paramiko 1/2 + gevent now working flawlessly in Py2/3.I am using Paramiko + gevent without (many) issues for my pyinfra project. Everything works as expected in Python 2 (with Paramiko < 2 & 2) - however in Python 3 the process hangs indefinitely (both Paramiko's) at: https://gist.github.com/Fizzadar/c829bf185c6c54aa31065fcb84e41e99
YevIgn commentedon Nov 18, 2016
Also, I recently used paramiko 2.0.2 (through plumbum's PramikoMachine) successfully with the eventlet 0.19 under Python 3.5.2. Everything (uploading/downloading files, long-running commands, etc.) worked flawlessly.
johnarnold commentedon Mar 24, 2017
Is anybody working on this?
bitprophet commentedon Mar 24, 2017
I took a very brief look at it the other week when poking the Fabric 2 alpha's concurrency features (which right now is just "threading works, unlike in v1"). Seemed like some of the linked tickets have various approaches - asyncio, gevent, etc. I didn't have time to deep-dive because I want that alpha to get out first (& that codebase will provide a very nice, easy framework for testing out Paramiko-level feature changes), but it's still a topic I'm interested in.
My first concern when this is fully revisited is finding a useful test case or benchmark, to prove that one of these other approaches brings a significant benefit over high-level threading. My uneducated guess is it would start becoming noticeable once the number of active connections gets above some "the GIL is becoming a serious drain" threshold.
So that, plus an updated overview of the available Python 2+3 compatible options, would be super useful.
johnarnold commentedon Mar 25, 2017
@bitprophet I had similar thoughts. I just completed some code using asyncio event loop + ThreadPoolExecutor to get thread-level parallelism with paramiko (netmiko), but I think it's going to suck performance-wise when communicating on more than a few dozen (?hundred?) devices. Process parallelism has its own headaches, and either way we're still blocking on I/O within threads.
I'd like to see paramiko fix the blocking-on-io thing with async/await methods to optimize single-thread performance, and let the users sort out thread-vs-process for their intended app. I can probably contribute to that, but I would like to first hear thoughts on how to proceed -- my bias is to implement new async classes/methods for Python3.5+ and python2.7 can stay the way it is. Thoughts?
bitprophet commentedon Mar 29, 2017
If there's no useful 2.7 analogue (my Python ~3.3 era memory is of the 'tulip' backport library, but no idea if that maps to the newer 3.4/3.5 constructs) then yea, "extra goodness if you're on 3.5+" sounds reasonable, as long as the code is organized cleanly. Thanks!
Fizzadar commentedon Apr 1, 2017
Just to note on performance - pyinfra is using paramiko + gevent (working perfectly) and I've found that this scales amazingly well across hundreds of hosts (limiting the gevent pool to ~75-100 gives the best performance, above that things slow down), especially when compared to threaded solutions like Ansible. There's a chart of results here.
graingert commentedon Jan 21, 2021
this might be worth revisiting now that Python 2 support may be dropped soon. Also I'd like to see a sansio interface like h2/h11
inlann commentedon Dec 19, 2024
Is there any updates?