============================= test session starts ==============================
platform linux -- Python 3.7.13, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
benchmark: 3.4.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=5 calibration_precision=10 warmup=True warmup_iterations=100000)
rootdir: /home/stefan/ws/graphql-core, configfile: setup.cfg
plugins: benchmark-3.4.1, cov-3.0.0, anyio-3.5.0, timeout-2.1.0, describe-2.0.1
timeout: 100.0s
timeout method: signal
timeout func_only: False
collected 2516 items / 2504 deselected / 12 selected
tests/benchmarks/test_build_ast_schema.py . [ 8%]
tests/benchmarks/test_build_client_schema.py . [ 16%]
tests/benchmarks/test_execution_async.py .. [ 33%]
tests/benchmarks/test_execution_sync.py . [ 41%]
tests/benchmarks/test_introspection_from_schema.py . [ 50%]
tests/benchmarks/test_parser.py . [ 58%]
tests/benchmarks/test_validate_gql.py . [ 66%]
tests/benchmarks/test_validate_invalid_gql.py . [ 75%]
tests/benchmarks/test_validate_sdl.py . [ 83%]
tests/benchmarks/test_visit.py .. [100%]
--------------------------------------------------------------------------------------------------------- benchmark: 12 tests ----------------------------------------------------------------------------------------------------------
Name (time in us) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_execute_basic_sync 661.9170 (1.0) 25,781.1220 (1.29) 763.7950 (1.0) 647.2897 (2.59) 727.1705 (1.0) 99.9350 (1.60) 10;310 1,309.2518 (1.0) 7574 1
test_execute_basic_async[asyncio] 789.3590 (1.19) 20,032.9120 (1.0) 867.8673 (1.14) 249.4849 (1.0) 906.9380 (1.25) 120.7202 (1.93) 6;8 1,152.2499 (0.88) 6343 1
test_execute_basic_async_trio[trio] 1,251.8120 (1.89) 25,944.9790 (1.30) 1,409.2772 (1.85) 680.1598 (2.73) 1,395.3320 (1.92) 129.8407 (2.08) 3;228 709.5836 (0.54) 4013 1
test_parse_kitchen_sink 1,330.0340 (2.01) 23,528.3300 (1.17) 1,424.0817 (1.86) 723.1457 (2.90) 1,402.3740 (1.93) 62.5005 (1.0) 4;185 702.2069 (0.54) 3772 1
test_validate_introspection_query 3,918.3780 (5.92) 47,985.1300 (2.40) 4,178.4954 (5.47) 1,758.7993 (7.05) 4,011.1160 (5.52) 78.7470 (1.26) 2;129 239.3206 (0.18) 1277 1
test_validate_invalid_query 37,027.1740 (55.94) 38,657.1470 (1.93) 37,451.0217 (49.03) 271.5596 (1.09) 37,385.6900 (51.41) 283.0698 (4.53) 30;8 26.7015 (0.02) 135 1
test_build_schema_from_ast 38,402.0660 (58.02) 87,811.6550 (4.38) 50,244.0027 (65.78) 19,427.7732 (77.87) 39,887.3900 (54.85) 1,784.4250 (28.55) 31;31 19.9029 (0.02) 130 1
test_build_schema_from_introspection 44,885.4960 (67.81) 83,229.9070 (4.15) 53,670.0072 (70.27) 14,769.6549 (59.20) 45,680.3725 (62.82) 1,343.1600 (21.49) 26;26 18.6324 (0.01) 112 1
test_visit_all_ast_nodes 55,416.7260 (83.72) 56,546.7950 (2.82) 55,881.9364 (73.16) 251.1629 (1.01) 55,881.2460 (76.85) 382.7483 (6.12) 31;0 17.8949 (0.01) 91 1
test_validate_sdl_document 112,529.1490 (170.00) 152,931.9640 (7.63) 114,881.9283 (150.41) 5,848.5372 (23.44) 113,915.4470 (156.66) 1,022.5075 (16.36) 1;2 8.7046 (0.01) 45 1
test_execute_introspection_query 210,025.7760 (317.30) 248,757.4280 (12.42) 216,474.8744 (283.42) 12,211.5627 (48.95) 212,063.4750 (291.63) 2,000.2005 (32.00) 3;3 4.6195 (0.00) 24 1
test_visit_all_ast_nodes_in_parallel 610,209.5660 (921.88) 614,215.2950 (30.66) 612,014.3380 (801.28) 1,352.9536 (5.42) 611,614.2970 (841.09) 1,486.0685 (23.78) 3;0 1.6339 (0.00) 9 1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Legend:
Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
OPS: Operations Per Second, computed as 1 / Mean
=============== 12 passed, 2504 deselected in 199.34s (0:03:19) ================
This PR replaces almost all asyncio usage with anyio, making graphql-core run with asyncio and trio.
This is only a proposal. It is implemented completely and tests run with asyncio and trio, but the PR also includes a few decisions that should probably be discussed before adopting the changes.
Current state:
The following changes were necessary to use anyio:
The following decisions should probably be discussed:
ToDo:
I am aware that this is a large change and it comes with (small) downsides,
e.g. a minimum python version of 3.6.2 and some extra effort for the users of SimplePubSub.
But it would allow the use of graphql with the trio event loop.
Having spent countless hours debugging due to some asyncio task that did not close correctly, I would
be extremely happy to have a structured concurrency approach available for graphql.
If you are at all interested in this proposal, please let me know.
Benchmarks before changes:
Benchmarks after changes: