|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | + |
| 19 | +import argparse |
| 20 | +import multiprocessing |
| 21 | + |
| 22 | +PREFIXES = { |
| 23 | + "i-": 1, |
| 24 | + "octo.aws.g4dn.52.42.180.210": 2, |
| 25 | + "octo.aws.g4dn.54.185.57.115": 2, |
| 26 | + "octo.aws.g4dn": 1, |
| 27 | + "octo.aws.c4": 4, |
| 28 | + "octo.aws.g4dn.cudabuild": 4, |
| 29 | + "Built-In Node": 2, |
| 30 | + "docs": 1, |
| 31 | + "octo.aws.arm": 4, |
| 32 | +} |
| 33 | + |
| 34 | + |
| 35 | +def guess_num_executors(node_name: str) -> int: |
| 36 | + # There is not a great way to get this from Jenkins directly apparently, so |
| 37 | + # guess it based on node nodes |
| 38 | + for prefix, count in PREFIXES.items(): |
| 39 | + if node_name.startswith(prefix): |
| 40 | + return count |
| 41 | + |
| 42 | + # Fallback to a safe option (4 is the wor |
| 43 | + return 4 |
| 44 | + |
| 45 | + |
| 46 | +if __name__ == "__main__": |
| 47 | + help = "Determine max CPUs possible for this job" |
| 48 | + parser = argparse.ArgumentParser(description=help) |
| 49 | + parser.add_argument("--node-name", required=True, help="current node name") |
| 50 | + args = parser.parse_args() |
| 51 | + |
| 52 | + executors = guess_num_executors(args.node_name) |
| 53 | + nproc = multiprocessing.cpu_count() |
| 54 | + |
| 55 | + available_cpus = nproc // executors |
| 56 | + available_cpus = max(available_cpus, 1) |
| 57 | + |
| 58 | + print(available_cpus) |
0 commit comments