MagicStack / MagicStack/uvloop
Using vectorized IO (scatter/gather)
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Cython
- Sterne
- 11.9k
- Forks
- 616
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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 )
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit uvloop/handles/stream.pyx rund um die referenzierten writelines- und _write-Zeilen und untersuchen Sie anschließend die verknüpften libuv uv_write-, uv_fs_write-, sendmsg- und WSASend-APIs. Bestimmen Sie, ob das Sammeln von writelines-Puffern eine vektorisierte Operation ermöglichen kann, und definieren Sie den daraus resultierenden Umfang und die Kriterien für den Abschluss.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- networking, performance
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 30/100