MagicStack / MagicStack/uvloop

Using vectorized IO (scatter/gather)

オープン
#404 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Cython
スター
11.9k
フォーク
616
PR マージ指標
30日以内にマージされた PR はありません

説明

Operations like writelines in the Stream and the Transport APIs provide library authors the opportunity to send collections of buffers that they would like written, sent, etc. in one go. This can be really handy as it takes only one pass (as opposed to multiple passes) through layers of code to prepare buffers before they go out.

Many OSes supply similar C-level operations like writev on POSIX compatible or similar on Windows for operating on file descriptors. Similarly sendmsg on Linux and Unix or WSASend on Windows provide implementations for sockets.

Admittedly am not very familiar with libuv's API (so maybe devs here can comment on this), but it appears there are some APIs in libuv like uv_write can take multiple buffers, which can internally redirect to sendmsg or WSASend. This also appears to be true for files with the uv_fs_write API.

AFAICT (and I could be wrong about this) uvloop's writelines for Streams calls an internal _write function in a loop, which could write one entire buffer (if it is sufficiently large, etc.) or at least queue a write. Please correct me if I'm misunderstanding anything here.

However given libuv's own propensity to use scatter/gather IO under-the-hood, it might be worth holding off on queuing write operations until all of the buffers in writelines are collected and prepped. This would allow one larger send, write, etc. to occur and if it is above the high watermark for any buffer (likely?), no additional buffer prepping would be necessary either.


Side note: A separate interesting question would be doing something similar for reading. Not sure there is an API that could leverage this currently (may be wrong about this though). Maybe through pausing and resuming reading one could get close (though likely still leaves something on the table)?

Note: There may be similar optimizations possible in asyncio ( https://github.com/python/asyncio/pull/339 ) ( https://github.com/python/cpython/pull/19062 )

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、参照されている writelines と _write の行の周辺にある uvloop/handles/stream.pyx から始め、次にリンクされた libuv uv_write、uv_fs_write、sendmsg、WSASend API を調べます。writelines バッファを収集することで 1 回のベクトル化された操作を可能にできるかどうかを判断し、その結果としてのスコープと完了基準を定義します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
networking, performance
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。