Skip to content

Native async support (asyncio/greenlets/just-use-threads/???) #389

Open

Description

@bitprophet

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.

Activity

  1. travcunn commented on Dec 12, 2014

    @travcunn

    +1

  2. nchammas commented on Mar 22, 2015

    @nchammas

    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.

  3. nchammas commented on Mar 22, 2015

    @nchammas

    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)?

  4. bitprophet commented on Mar 24, 2015

    @bitprophet
    MemberAuthor

    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.

  5. changed the title [-]Eventlet/greenlet support[/-] [+]Native async support (asyncio/greenlets/just-use-threads/???)[/+] on Mar 24, 2015
  6. nchammas commented on Mar 24, 2015

    @nchammas

    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.

  7. sivabudh commented on Jan 8, 2016

    @sivabudh

    +1

  8. giampaolo commented on Apr 12, 2016

    @giampaolo

    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).

  9. Fizzadar commented on Jun 6, 2016

    @Fizzadar

    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

  10. YevIgn commented on Nov 18, 2016

    @YevIgn

    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.

  11. johnarnold commented on Mar 24, 2017

    @johnarnold

    Is anybody working on this?

  12. bitprophet commented on Mar 24, 2017

    @bitprophet
    MemberAuthor

    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.

  13. johnarnold commented on Mar 25, 2017

    @johnarnold

    @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?

  14. bitprophet commented on Mar 29, 2017

    @bitprophet
    MemberAuthor

    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!

  15. Fizzadar commented on Apr 1, 2017

    @Fizzadar

    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.

  16. graingert commented on Jan 21, 2021

    @graingert

    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

  17. inlann commented on Dec 19, 2024

    @inlann

    Is there any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions