graphql-python / graphql-python/graphene
Performance issues with large data sets
- 主要语言
- Python
- 星标
- 8.2k
- 派生
- 818
- PR 合并指标
- 30 天内没有已合并 PR
描述
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)
```
贡献指南
这个仓库没有索引到贡献指南
调研方向
使用所示的 UserQuery、Query、resolve_users 和 schema.execute 入口点运行该 issue 的 10,000 对象基准测试。阅读该查询涉及的执行和数值解析路径,然后确定一个经过测量的改进目标和回归覆盖范围;该 issue 未指定具体的验收阈值。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- api, performance
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100