MagicStack / MagicStack/asyncpg
Feature request: Support for asynchronous command processing
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 8.1k
- Fork
- 468
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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:
```python
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.)
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với tài liệu về xử lý lệnh bất đồng bộ của libpq được liên kết trong issue, sau đó kiểm tra API kết nối của asyncpg xoay quanh conn.fetch và hành vi InterfaceError hiện tại khi các coroutine được gather. So sánh hành vi không pipelining được đề xuất với extended query protocol và xác định liệu API cùng ngữ nghĩa đồng bộ hóa được yêu cầu có khả thi hay không; issue không cung cấp điểm bắt đầu cho tệp hoặc bài kiểm thử.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- postgresql, python
- Lĩnh vực
- databases
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 25/100