← 输入框|bugs.python.org|刷新

➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
标题: An attempt to make asyncio.transport.writelines (selector) use Scatter I/O
类型: enhancement Stage: resolved
Components: asyncio Versions: Python 3.9
process
状态: closed Resolution: duplicate
Dependencies: 后续: Implement zero copy writes in SelectorSocketTransport in asyncio
View: 47010
分配给: 抄送列表: asvetlov, jakirkham, tzickel, yselivanov
优先级: normal 关键字:

Created on 2020-03-18 21:00 by tzickel, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19062 closed tzickel, 2020-03-18 21:00
Messages (3)
msg364565 - (view) Author: (tzickel) * 日期: 2020-03-18 21:00
I have a code that tries to be smart and prepare data to be chunked efficiently before sending, so I was happy to read about:

https://docs.python.org/3/library/asyncio-protocol.html#asyncio.WriteTransport.writelines

Only to see that it simply does:

self.write(b''.join(lines))

So I've attempted to write an version that uses sendmsg (scatter I/O) instead (will be attached in PR).

What I've learnt is:
1. It's hard to benchmark (If someone has an good example on checking if it's worth it, feel free to add such).
2. sendmsg has an OS limit on how many items can be done in one call. If the user does not call writer.drain() it might have too many items in the buffer, in that case I concat them (might be an expensive operation ? but that should not be th enormal case).
3. socket.socket.sendmsg can accept any bytes like iterable, but os.writev can only accept sequences, is that a bug ?
4. This is for the selector stream socket for now.
msg364595 - (view) Author: (tzickel) * 日期: 2020-03-19 06:47
BTW, if wanted a much more simpler PR can be made, where writelines simply calls sendmsg on the input if no buffer exists, and if not only then concats and acts like the current code base.
msg415409 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) 日期: 2022-03-17 13:11
A duplicate of #47010
历史
日期 用户 动作 参数
2022-04-11 14:59:28admin修改github: 84188
2022-03-17 13:11:02asvetlov修改状态: open -> closed
后续: Implement zero copy writes in SelectorSocketTransport in asyncio
消息: + msg415409

resolution: duplicate
stage: resolved
2021-02-26 21:49:21jakirkham修改抄送: + jakirkham
2020-03-19 06:47:39tzickel修改消息: + msg364595
2020-03-18 21:00:01tzickel创建