Optimized batch loading without blocking
- Ngôn ngữ chính
- Go
- Star
- 10.8k
- Fork
- 1.3k
- Merge trung bình
- 2 ngày 36 phút
- Pull request đã merge (30 ngày)
- 26
Mô tả
I'm trying to understand how `gqlgen` can optimize batch loading lazily/concurrently, given that all resolvers are synchronous — i.e. they return the value itself, instead of a thunk (future).
I was reading through the code example for data loading to try to understand how `dataloaden` works. In the its code, I noticed that `Load(key)` simply calls `LoadThunk(key)()`. Then I noticed this line in the readme: "This method will block for a short amount of time, waiting for any other similar requests to come in". Is this how gqlgen assumes it will work?
If you look at the [graphql-go project](https://www.github.com/graphql-go/graphql), all resolvers can return either values or thunks. This means the entire GraphQL tree can be resolved to thunks, which can then queue up all the keys they need so that when the thunks are called, all the objects can be fetched at once.
Can someone fill me in on how gqlgen is supposed to handle this? A resolver like this:
```
func (r *rootQueryResolver) Things(ctx context.Context, uids []*string, limit *int) ([]*models.Thing, error) {
// ...
}
```
...cannot defer any work at all; it has to return. The only way to batch this is to execute all the resolvers concurrently in goroutines, then have some kind of queue that keeps track of when they've all resolved their keys — or just wait for an arbitrary interval. That seems wrong to me, and all the attendant synchronization sounds like it would be super inefficient.
Hướng dẫn đóng góp
Hướng nghiên cứu
Issue này thảo luận về cách gqlgen xử lý việc tải theo lô so với phương pháp dựa trên thunk của graphql-go. Hãy xem mã ví dụ dataloader của gqlgen và phương thức LoadThunk của thư viện dataloaden. Kiểm tra chữ ký của resolver và cơ chế đồng bộ hóa. Việc hiểu mô hình đồng thời hiện tại và điểm tích hợp dataloader là yếu tố then chốt để đề xuất một tối ưu hóa.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- go, graphql
- Lĩnh vực
- api, backend
- Loại issue
- Tính năng
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- 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
- 35/100