graphql-python / graphql-python/graphene
Performance issues with large data sets
- Ngôn ngữ chính
- Python
- Star
- 8.2k
- Fork
- 818
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
For our use case, we send a few thousand objects to the client. We're currently using a normal JSON API, but are considering using GraphQL instead. However, when returning a few thousand objects, the overhead of resolving values makes it impractical to use. For instance, the example below returns 10000 objects with an ID field, and that takes around ten seconds to run.
Is there a recommended way to improve the performance? The approach I've used successfully so far is to use the existing parser to parse the query, and then generate the response by creating dictionaries directly, which avoids the overhead of resolving/completing on every single value.
``` python
import graphene
class UserQuery(graphene.ObjectType):
id = graphene.Int()
class Query(graphene.ObjectType):
users = graphene.Field(UserQuery.List())
def resolve_users(self, args, info):
return users
class User(object):
def __init__(self, id):
self.id = id
users = [User(index) for index in range(0, 10000)]
schema = graphene.Schema(query=Query)
print(schema.execute('{ users { id } }').data)
```
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
Hướng nghiên cứu
Run the issue's 10,000-object benchmark using the shown UserQuery, Query, resolve_users, and schema.execute entry points. Read the execution and value-resolution path involved in that query, then establish a measured improvement target and regression coverage; the issue does not specify a concrete acceptance threshold.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- api, performance
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100