Skip to content
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

asyncio: Windows Proactor Event Loop UDP Support #74069

Closed
ameily mannequin opened this issue Mar 22, 2017 · 9 comments
Closed

asyncio: Windows Proactor Event Loop UDP Support #74069

ameily mannequin opened this issue Mar 22, 2017 · 9 comments
Labels
3.8 only security fixes topic-asyncio type-feature A feature request or enhancement

Comments

@ameily
Copy link
Mannequin

ameily mannequin commented Mar 22, 2017

BPO 29883
Nosy @vstinner, @giampaolo, @asvetlov, @1st1, @willingc, @ameily, @miss-islington
PRs
  • bpo-29883: Add UDP support to Windows Proactor Event Loop #1067
  • bpo-29883: Asyncio proactor udp #13440
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-05-28.09:54:22.871>
    created_at = <Date 2017-03-22.19:28:01.129>
    labels = ['type-feature', '3.8', 'expert-asyncio']
    title = 'asyncio: Windows Proactor Event Loop UDP Support'
    updated_at = <Date 2019-05-28.10:46:30.358>
    user = 'https://github.com/ameily'

    bugs.python.org fields:

    activity = <Date 2019-05-28.10:46:30.358>
    actor = 'asvetlov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-05-28.09:54:22.871>
    closer = 'asvetlov'
    components = ['asyncio']
    creation = <Date 2017-03-22.19:28:01.129>
    creator = 'meilyadam'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 29883
    keywords = ['patch']
    message_count = 9.0
    messages = ['290010', '325388', '325389', '325390', '325453', '339446', '343754', '343762', '343763']
    nosy_count = 8.0
    nosy_names = ['vstinner', 'giampaolo.rodola', 'asvetlov', 'yselivanov', 'willingc', 'meilyadam', 'miss-islington', 'Alex Chandel']
    pr_nums = ['1067', '13440']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue29883'
    versions = ['Python 3.8']

    @ameily
    Copy link
    Mannequin Author

    ameily mannequin commented Mar 22, 2017

    I am working on a Python 3.5 project that uses asyncio on a Windows system to poll both UDP and TCP connections. Multiple sources online say that the Windows Proactor event loop, which uses I/O Completion Ports, is considerably faster and more efficient than the default Selector event loop. I'm using both UDP and TCP connections so I am stuck with the Selector event loop for the time being. I've seen the overhead of 128 open UDP/TCP connections on the Selector event loop to be near 85%, which I understand is entirely spent in Windows proprietary code and not the Python implementation.

    I'd like to take a shot at implementing UDP support in the IOCP event loop. It looks like there will be a considerable amount of code shared between TCP and UDP IOCP so I plan on implementing UDP support directly in _ProactorReadPipeTransport and _ProactorBaseWritePipeTransport. I should be able to do this by wrapping any TCP/UDP specific function calls in a check of:

    if sock.type == socket.SOCK_DGRAM:
        # Do UDP stuff
    elif sock.type == socket.SOCK_STREAM:
        # Do TCP stuff

    My initial implementation plan is to:

    • Call datagram_received() instead of data_received() when UDP data is available in _ProactorReadPipeTransport._loop_reading().
    • Implement BaseProactorEventLoop._make_datagram_transport().
    • Implement wrappers for WSAConnect, WSARecvFrom, and WSASendTo in _overlapped.
    • Implement sendto() and recvfrom() in IocpProactor, which will use the new functions in _overlapped.
    • Implement handling for UDP "connections" in IocpProactor.connect() to call WSAConnect(). WSAConnect() appears to always return immediately so the function not supporting IOCP shouldn't be an issue. We can't use ConnectEx() for UDP because ConnectEx() is for connection-oriented sockets only.

    My project is unfortunately tied to Python 3.5. So, if possible, I'd like to have UDP support merged into a v3.5 release. I can fork off of master instead of v3.5.3 if Python 3.5 support isn't an option.

    @ameily ameily mannequin added topic-asyncio type-feature A feature request or enhancement labels Mar 22, 2017
    @terryjreedy terryjreedy added the 3.7 (EOL) end of life label Mar 24, 2017
    @vstinner
    Copy link
    Member

    I just marked my old issue bpo-23295 as duplicate of this one. Copy of my messages:

    """
    ProactorEventLoop lacks UDP support: create_datagram_endpoint() is not supported.

    New functions should be added to the _overlapped modul. Example: add maybe WSARecvFrom()?

    See also https://code.google.com/p/tulip/issues/detail?id=187
    """

    @vstinner vstinner added 3.8 only security fixes and removed 3.7 (EOL) end of life labels Sep 14, 2018
    @vstinner
    Copy link
    Member

    Copy of my messages in July 2014:
    python/asyncio#187

    """
    ProcatorEventLoop doesn't support UDP right now.

    I'm working on a patch. I need to implement WSARecvFrom in the _overlapped module for example.

    ConnectEx() fails with an error 10022 when create_datagram_endpoint() is called with remote_address. A workaround is to replace "yield from sock_connect(sock, remote_address)" with "sock.connect(remote_address)".
    """

    @vstinner
    Copy link
    Member

    Adam Meily: Thanks for the proposed pull request. Would you mind to try to rebase it on the current master branch, please?

    @ameily
    Copy link
    Mannequin Author

    ameily mannequin commented Sep 15, 2018

    I've rebased onto upstream master and I fixed the CI build.

    @alexchandel
    Copy link
    Mannequin

    alexchandel mannequin commented Apr 4, 2019

    Could this be merged? UDP and pipes are critical for non-trivial asyncio programs on Windows, and this should be merged before the 3.8 feature window closes.

    @miss-islington
    Copy link
    Contributor

    New changeset bafd4b5 by Miss Islington (bot) (Andrew Svetlov) in branch 'master':
    bpo-29883: Asyncio proactor udp (GH-13440)
    bafd4b5

    @vstinner
    Copy link
    Member

    I planned to ask you (Adam and Andrew) to merge the PR even if it's not finished, just to make sure that UDP support will land into Python 3.8. But Andrew finished the PR, yahoo!

    Thanks you very much Adam Meily and Andrew Svetlov! Sorry, I planned to do what Andrew did: "finish" the PR, but I was just too busy on other things :-(

    Well done, I see that you fixed max_size, pause/resume protocol, etc.

    asyncio on Windows will be much better experience with IOCP by default, CTRL+c support, UDP support, etc.

    @asvetlov
    Copy link
    Contributor

    You are welcome, Victor!

    Thank you very much, Adam!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes topic-asyncio type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants