|
| 1 | +# Copyright 1999-2022 Alibaba Group Holding Ltd. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import mars.tensor as mt |
| 16 | +import mars.dataframe as md |
| 17 | +from mars.core.graph import TileableGraph, TileableGraphBuilder, ChunkGraphBuilder |
| 18 | +from mars.services.task.analyzer import GraphAnalyzer |
| 19 | +from mars.services.task.analyzer.assigner import GraphAssigner |
| 20 | + |
| 21 | + |
| 22 | +class ChunkGraphAssignerSuite: |
| 23 | + """ |
| 24 | + Benchmark that times performance of chunk graph assigner |
| 25 | + """ |
| 26 | + |
| 27 | + def setup(self): |
| 28 | + num_rows = 10000 |
| 29 | + df1 = md.DataFrame( |
| 30 | + mt.random.rand(num_rows, 4, chunk_size=10), columns=list("abcd") |
| 31 | + ) |
| 32 | + df2 = md.DataFrame( |
| 33 | + mt.random.rand(num_rows, 4, chunk_size=10), columns=list("abcd") |
| 34 | + ) |
| 35 | + merged_df = df1.merge(df2, left_on="a", right_on="a") |
| 36 | + graph = TileableGraph([merged_df.data]) |
| 37 | + next(TileableGraphBuilder(graph).build()) |
| 38 | + self.chunk_graph = next(ChunkGraphBuilder(graph, fuse_enabled=False).build()) |
| 39 | + |
| 40 | + def time_assigner(self): |
| 41 | + start_ops = list(GraphAnalyzer._iter_start_ops(self.chunk_graph)) |
| 42 | + band_slots = {(f"worker-{i}", "numa-0"): 16 for i in range(50)} |
| 43 | + current_assign = {} |
| 44 | + assigner = GraphAssigner(self.chunk_graph, start_ops, band_slots) |
| 45 | + assigned_result = assigner.assign(current_assign) |
| 46 | + assert len(assigned_result) == len(start_ops) |
0 commit comments