MagicStack / MagicStack/uvloop

Using vectorized IO (scatter/gather)

Ouverte
#404 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
Cython
Étoiles
11.9k
Forks
616
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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 )

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par uvloop/handles/stream.pyx autour des lignes référencées de writelines et de _write, puis examinez les APIs libuv uv_write, uv_fs_write, sendmsg et WSASend liées. Déterminez si la collecte des buffers de writelines peut permettre une opération vectorisée et définissez la portée qui en résulte ainsi que les critères d’achèvement.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
networking, performance
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
30/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.