Title: performance issues due to breadth first execution of grapqhl queries in case of async resolvers during calls burst · Issue #200 · graphql-python/graphql-core · GitHub
Open Graph Title: performance issues due to breadth first execution of grapqhl queries in case of async resolvers during calls burst · Issue #200 · graphql-python/graphql-core
X Title: performance issues due to breadth first execution of grapqhl queries in case of async resolvers during calls burst · Issue #200 · graphql-python/graphql-core
Description: When we receive calls burst we found that the calls "wait each other" (i.e. the first call of the burst waits the last one). This result in degradation of performances in both time of execution and memory consumption in the server becaus...
Open Graph Description: When we receive calls burst we found that the calls "wait each other" (i.e. the first call of the burst waits the last one). This result in degradation of performances in both time of execution and...
X Description: When we receive calls burst we found that the calls "wait each other" (i.e. the first call of the burst waits the last one). This result in degradation of performances in both time of exe...
Opengraph URL: https://github.com/graphql-python/graphql-core/issues/200
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"performance issues due to breadth first execution of grapqhl queries in case of async resolvers during calls burst","articleBody":"When we receive calls burst we found that the calls \"wait each other\" (i.e. the first call of the burst waits the last one).\r\nThis result in degradation of performances in both time of execution and memory consumption in the server because we have to keep many calls in fly.\r\n\r\nThis is particularly evident in big graphql queries where the users request many fields and we have several depth in the queries where each level has many async fields.\r\n\r\nJust to be TLDR, looking the implementations of graphql and asyncio we understood that this is due to the following:\r\n- graphql breadth first way to schedule and resolve the fields\r\n- asyncio internal FIFO queue of tasks to be executed\r\n\r\n\r\nAs an example lets have queries like that, where data may be like beer vendors and we want for each beer vendor many fields that describes that vendor, a1...a100, b1...b100, ...:\r\n\r\n```\r\nquery {\r\n data {\r\n a1 {\r\n b1 {\r\n c1\r\n ...\r\n c100\r\n }\r\n ...\r\n b100 {\r\n c1\r\n ...\r\n c100\r\n }\r\n }\r\n ...\r\n a100 { ... }\r\n }\r\n}\r\n``` \r\n\r\nIf we have n of this calls coming in burst when we arrive to the depth of the c fields we have many many task scheduled in the asyncio queue. \r\n\r\nIf we check the of order of execution we have that the first query, on each level, \"waits\" the other queries, because all the queries schedules a lot of tasks.\r\n\r\nIn the proof of concept, that you may find at the end of the post, you can verify the order of execution of the resolvers.\r\n\r\nIt could be very nice to have some sort of priority in the order to let the first query not wait the scheduling and resolve of all the queries before ending.\r\nI understand that this is something between graphql and asyncio but i think it could affect the use of graphql in environments receiving many calls.\r\nFixes, helps and hints in how to improve this would be very appreciated.\r\n\r\n```python\r\nimport asyncio\r\n\r\nfrom graphene import ObjectType, Schema, String, Field\r\n\r\nFIELD_NUMBER = 2\r\nCONCURRENT_QUERIES = 10\r\n\r\n\r\ndef make_resolver(i, j=None):\r\n async def resolver(self, info):\r\n print(f\"START query {info.context['query_number']} | a{i} | b{j}\")\r\n await asyncio.sleep(0.001)\r\n print(f\"END query {info.context['query_number']} | a{i} | b{j}\")\r\n return i\r\n\r\n return resolver\r\n\r\n\r\ndef create_fields():\r\n fields = {}\r\n for i in range(FIELD_NUMBER):\r\n inner_fields = {}\r\n for j in range(FIELD_NUMBER):\r\n inner_fields[f\"b{j}\"] = String()\r\n inner_fields[f\"resolve_b{j}\"] = make_resolver(i, j)\r\n\r\n MyType = type(\r\n f\"MyType\",\r\n (ObjectType,),\r\n inner_fields,\r\n )\r\n\r\n fields[f\"a{i}\"] = Field(MyType)\r\n fields[f\"resolve_a{i}\"] = make_resolver(i)\r\n\r\n return fields\r\n\r\n\r\nasync def make_query(schema, query_number):\r\n inner_query_values = [f\"b{i}\" for i in range(FIELD_NUMBER)]\r\n query_values = [\r\n \"a%s {%s}\" % (i, \" \".join(inner_query_values)) for i in range(FIELD_NUMBER)\r\n ]\r\n query_string = \"{ %s }\" % (\" \".join(query_values),)\r\n\r\n await schema.execute_async(\r\n query_string, context_value=dict(query_number=query_number)\r\n )\r\n\r\n\r\nasync def main():\r\n Query = type(\"Query\", (ObjectType,), create_fields())\r\n schema = Schema(query=Query)\r\n\r\n await asyncio.gather(*[make_query(schema, i) for i in range(CONCURRENT_QUERIES)])\r\n\r\n\r\nasyncio.run(main())\r\n\r\n``` ","author":{"url":"https://github.com/alessandrolulli","@type":"Person","name":"alessandrolulli"},"datePublished":"2023-05-12T10:05:36Z","url":"https://github.com/graphql-python/graphql-core/issues/200"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f87a1c2c-cdc2-e739-1d70-f906a4c3bbff |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8402:3022B5:246A4B:2F25FF:6AFFC41D |
| html-safe-nonce | afcea0a3255281129d9b2b9d6a15d1dfcf567b30a089b336ae67bcf982cc4341 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NDAyOjMwMjJCNToyNDZBNEI6MkYyNUZGOjZBRkZDNDFEIiwidmlzaXRvcl9pZCI6IjEwNDg3MjY3NTk0NDIyMDM2NzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2af4e5b5d0cc5b5d1bd41c49a1b65350d01604f7a52a2d30055852614f8f6059 |
| hovercard-subject-tag | issue:1707342207 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/graphql-python/graphql-core/200/issue_layout |
| twitter:image | https://opengraph.githubassets.com/804e068321d8be8f299fc7fc4c7822719114038a22fe36700594e63a27497604/graphql-python/graphql-core/issues/200 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/804e068321d8be8f299fc7fc4c7822719114038a22fe36700594e63a27497604/graphql-python/graphql-core/issues/200 |
| og:image:alt | When we receive calls burst we found that the calls "wait each other" (i.e. the first call of the burst waits the last one). This result in degradation of performances in both time of execution and... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | alessandrolulli |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1e805b832df235bb21305db712c3b6432920019dfc12cb25b9cb8d3b0c9403cf |
| turbo-cache-control | no-preview |
| go-import | github.com/graphql-python/graphql-core git https://github.com/graphql-python/graphql-core.git |
| octolytics-dimension-user_id | 15002022 |
| octolytics-dimension-user_login | graphql-python |
| octolytics-dimension-repository_id | 143207933 |
| octolytics-dimension-repository_nwo | graphql-python/graphql-core |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 143207933 |
| octolytics-dimension-repository_network_root_nwo | graphql-python/graphql-core |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8fa4a54e6871c7908eda1c246ad5972982c0b59d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width