8000 Extend async tree benchmarks to cover eager task execution (#279) · python/pyperformance@3615f18 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3615f18

Browse files
Extend async tree benchmarks to cover eager task execution (#279)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
1 parent 2e053ce commit 3615f18

10 files changed

+58
-12
lines changed

doc/benchmarks.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,15 @@ Async workload benchmark, which calls ``asyncio.gather()`` on a tree (6 levels d
6666

6767
* ``async_tree``: no actual async work at any leaf node.
6868
* ``async_tree_io``: all leaf nodes simulate async IO workload (async sleep 50ms).
69-
* ``async_tree_memoization``: all leaf nodes simulate async IO workload with 90% of
69+
* ``async_tree_memoization``: all leaf nodes simulate async IO workload with 90% of
7070
the data memoized.
7171
* ``async_tree_cpu_io_mixed``: half of the leaf nodes simulate CPU-bound workload
72-
(``math.factorial(500)``) and the other half simulate the same workload as the
72+
(``math.factorial(500)``) and the other half simulate the same workload as the
7373
``async_tree_memoization`` variant.
7474

75+
These benchmarks also have an "eager" flavor that uses asyncio eager task factory,
76+
if available.
77+
7578

7679
chameleon
7780
---------

pyperformance/data-files/benchmarks/MANIFEST

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ async_tree <local>
77
async_tree_cpu_io_mixed <local:async_tree>
88
async_tree_io <local:async_tree>
99
async_tree_memoization <local:async_tree>
10+
async_tree_eager <local:async_tree>
11+
async_tree_eager_cpu_io_mixed <local:async_tree>
12+
async_tree_eager_io <local:async_tree>
13+
async_tree_eager_memoization <local:async_tree>
1014
asyncio_tcp <local>
1115
asyncio_tcp_ssl <local:asyncio_tcp>
1216
concurrent_imap <local>
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
[tool.pyperformance]
22
name = "async_tree_cpu_io_mixed"
33
extra_opts = ["cpu_io_mixed"]
4-
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[tool.pyperformance]
2+
name = "async_tree_eager"
3+
extra_opts = ["eager"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[tool.pyperformance]
2+
name = "async_tree_eager_cpu_io_mixed"
3+
extra_opts = ["eager_cpu_io_mixed"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[tool.pyperformance]
2+
name = "async_tree_eager_io"
3+
extra_opts = ["eager_io"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[tool.pyperformance]
2+
name = "async_tree_eager_memoization"
3+
extra_opts = ["eager_memoization"]
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
[tool.pyperformance]
22
name = "async_tree_io"
33
extra_opts = ["io"]
4-
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
[tool.pyperformance]
22
name = "async_tree_memoization"
33
extra_opts = ["memoization"]
4-

pyperformance/data-files/benchmarks/bm_async_tree/run_benchmark.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
77
1) "none": No actual async work in the async tree.
88
2) "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+
6071
class NoneAsyncTree(AsyncTree):
6172
async def workload_func(self):
6273
return
6374

6475

76+
class EagerAsyncTree(EagerMixin, NoneAsyncTree):
77+
pass
78+
79+
6580
class 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+
7089
class 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+
85108
class 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+
95122
def 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:
116143
1) "none": No actual async work in the async tree.
117144
2) "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

127154
BENCHMARKS = {
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

Comments
 (0)
0