66
771) "none": No actual async work in the async tree.
882) "io": All leaf nodes simulate async IO workload (async sleep 50ms).
9- 3) "memoization": All leaf nodes simulate async IO workload with 90% of
9+ 3) "memoization": All leaf nodes simulate async IO workload with 90% of
1010 the data memoized
11- 4) "cpu_io_mixed": Half of the leaf nodes simulate CPU-bound workload and
12- the other half simulate the same workload as the
11+ 4) "cpu_io_mixed": Half of the leaf nodes simulate CPU-bound workload and
12+ the other half simulate the same workload as the
1313 "memoization" variant.
14+
15+ All variants also have an "eager" flavor that uses
16+ the asyncio eager task factory (if available).
1417"""
1518
1619
@@ -57,16 +60,32 @@ async def run(self):
5760 await self .recurse (NUM_RECURSE_LEVELS )
5861
5962
63+ class EagerMixin :
64+ async def run (self ):
65+ loop = asyncio .get_running_loop ()
66+ if hasattr (asyncio , 'eager_task_factory' ):
67+ loop .set_task_factory (asyncio .eager_task_factory )
68+ return await super ().run ()
69+
70+
6071class NoneAsyncTree (AsyncTree ):
6172 async def workload_func (self ):
6273 return
6374
6475
76+ class EagerAsyncTree (EagerMixin , NoneAsyncTree ):
77+ pass
78+
79+
6580class IOAsyncTree (AsyncTree ):
6681 async def workload_func (self ):
6782 await self .mock_io_call ()
6883
6984
85+ class EagerIOAsyncTree (EagerMixin , IOAsyncTree ):
86+ pass
87+
88+
7089class MemoizationAsyncTree (AsyncTree ):
7190 async def workload_func (self ):
7291 # deterministic random, seed set in AsyncTree.__init__()
@@ -82,6 +101,10 @@ async def workload_func(self):
82101 return data
83102
84103
104+ class EagerMemoizationAsyncTree (EagerMixin , MemoizationAsyncTree ):
105+ pass
106+
107+
85108class CpuIoMixedAsyncTree (MemoizationAsyncTree ):
86109 async def workload_func (self ):
87110 # deterministic random, seed set in AsyncTree.__init__()
@@ -92,6 +115,10 @@ async def workload_func(self):
92115 return await MemoizationAsyncTree .workload_func (self )
93116
94117
118+ class EagerCpuIoMixedAsyncTree (EagerMixin , CpuIoMixedAsyncTree ):
119+ pass
120+
121+
95122def add_metadata (runner ):
96123 runner .metadata ["description" ] = "Async tree workloads."
97124 runner .metadata ["async_tree_recurse_levels" ] = NUM_RECURSE_LEVELS
@@ -115,20 +142,24 @@ def add_parser_args(parser):
115142 Determines which benchmark to run. Options:
1161431) "none": No actual async work in the async tree.
1171442) "io": All leaf nodes simulate async IO workload (async sleep 50ms).
118- 3) "memoization": All leaf nodes simulate async IO workload with 90% of
145+ 3) "memoization": All leaf nodes simulate async IO workload with 90% of
119146 the data memoized
120- 4) "cpu_io_mixed": Half of the leaf nodes simulate CPU-bound workload and
121- the other half simulate the same workload as the
147+ 4) "cpu_io_mixed": Half of the leaf nodes simulate CPU-bound workload and
148+ the other half simulate the same workload as the
122149 "memoization" variant.
123150""" ,
124151 )
125152
126153
127154BENCHMARKS = {
128155 "none" : NoneAsyncTree ,
156+ "eager" : EagerAsyncTree ,
129157 "io" : IOAsyncTree ,
158+ "eager_io" : EagerIOAsyncTree ,
130159 "memoization" : MemoizationAsyncTree ,
160+ "eager_memoization" : EagerMemoizationAsyncTree ,
131161 "cpu_io_mixed" : CpuIoMixedAsyncTree ,
162+ "eager_cpu_io_mixed" : EagerCpuIoMixedAsyncTree ,
132163}
133164
134165
@@ -142,4 +173,3 @@ def add_parser_args(parser):
142173 async_tree_class = BENCHMARKS [benchmark ]
143174 async_tree = async_tree_class ()
144175 runner .bench_async_func (f"async_tree_{ benchmark } " , async_tree .run )
145-
0 commit comments