MagicStack / MagicStack/asyncpg

Feature request: Support for asynchronous command processing

Abierto
#1,141 1 comentario 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Python
Estrellas
8.1k
Forks
468
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

libpq has support for something called asynchronous command processing (https://www.postgresql.org/docs/current/libpq-async.html).

Thea idea is fairly simple: you can queue up multiple queries on one connection without waiting for the previous result and then wait for all the results at the end. This avoids waiting for network round trips between queries, which at least in theory should have the same performance benefits as running multiple queries with one network round trip.

It would be useful if asyncpg could support the same concept. The Python API should be fairly straightforward. You just start multiple coroutines with queries and then await all of them together at the end. Something like this:

q1 = conn.fetch('SELECT $1', 1)
q2 = conn.fetch('SELECT $1', 2)
q3 = conn.fetch('SELECT $1', 3)
results = await asyncio.gather(q1, q2, q3) # (currently this raises InterfaceError)

This could have significant performance benefits in situations where you make multiple fast independent queries, especially if there is a large network round-trip delay.

AFAIK implementing this is definitely possible in theory. In practice, the complexity depends a lot on how the internals of asyncpg are structured, which I am not familiar with.

EDIT: This request is motivated by the same goal as https://github.com/MagicStack/asyncpg/issues/839, but my proposal is to specifically use asynchronous command processing without pipelining. If my understanding of the extended query protocol is correct, it should be possible to issue multiple queries without waiting for results between them but with a sync point after each query, which helps avoid the complex error handling rules of pipeline mode. (If my understanding of extended query protocol is not correct, this may be impossible. Feel free to correct me.)

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con la documentación sobre el procesamiento asíncrono de comandos de libpq enlazada en el issue; después inspecciona la API de conexión de asyncpg alrededor de conn.fetch y el comportamiento actual de InterfaceError cuando se reúnen coroutines. Compara el comportamiento propuesto sin pipelining con el extended query protocol y determina si la API y la semántica de sincronización solicitadas son viables; el issue no proporciona ningún punto de entrada de archivo o de prueba.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
postgresql, python
Área
databases
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.