1#!/bin/bash 2# Copyright 2021 The gRPC Authors 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16# This script generates a set of load test examples from templates. 17 18LOADTEST_CONFIG=tools/run_tests/performance/loadtest_config.py 19 20if (( $# < 1 )); then 21 echo "Usage: ${0} <output directory>" >&2 22 exit 1 23fi 24 25if [[ ! -x "${LOADTEST_CONFIG}" ]]; then 26 echo "${LOADTEST_CONFIG} not found." >&2 27 exit 1 28fi 29 30outputbasedir="${1}" 31 32mkdir -p "${outputbasedir}/templates/psm/prebuilt" 33 34example_file() { 35 local scenario="${1}" 36 local suffix="${2}" 37 if [[ "${scenario#cpp_}" != "${scenario}" ]]; then 38 echo "cxx${suffix}" 39 return 40 fi 41 if [[ "${scenario#python_asyncio_}" != "${scenario}" ]]; then 42 echo "python_asyncio${suffix}" 43 return 44 fi 45 if [[ "${scenario#php7_protobuf_c_}" != "${scenario}" ]]; then 46 echo "php7_protobuf_c${suffix}" 47 return 48 fi 49 echo "${scenario%%_*}${suffix}" 50} 51 52example_language() { 53 local filename="${1}" 54 if [[ "${filename#cxx_}" != "${filename}" ]]; then 55 echo "c++" 56 return 57 fi 58 if [[ "${filename#python_asyncio_}" != "${filename}" ]]; then 59 echo "python_asyncio" 60 return 61 fi 62 if [[ "${filename#php7_protobuf_c_}" != "${filename}" ]]; then 63 echo "php7_protobuf_c" 64 return 65 fi 66 echo "${filename%%_*}" 67} 68 69scenarios=( 70 "cpp_generic_async_streaming_ping_pong_secure" 71 "csharp_protobuf_async_unary_ping_pong" 72 "dotnet_protobuf_async_unary_ping_pong" 73 "go_generic_sync_streaming_ping_pong_secure" 74 "java_generic_async_streaming_ping_pong_secure" 75 "node_to_node_generic_async_streaming_ping_pong_secure" 76 "php7_protobuf_php_extension_to_cpp_protobuf_sync_unary_ping_pong" 77 "php7_protobuf_c_extension_to_cpp_protobuf_sync_unary_ping_pong" 78 "python_generic_sync_streaming_ping_pong" 79 "python_asyncio_generic_async_streaming_ping_pong" 80 "ruby_protobuf_sync_streaming_ping_pong" 81) 82 83psm_scenarios=( 84 "cpp_protobuf_async_unary_5000rpcs_1KB_psm" 85 "go_protobuf_async_unary_5000rpcs_1KB_psm" 86 "java_protobuf_async_unary_5000rpcs_1KB_psm" 87 "node_to_node_protobuf_async_unary_5000rpcs_1KB_psm" 88 "php7_protobuf_php_extension_to_cpp_protobuf_async_unary_5000rpcs_1KB_psm" 89 "php7_protobuf_c_extension_to_cpp_protobuf_async_unary_5000rpcs_1KB_psm" 90 "python_protobuf_async_unary_5000rpcs_1KB_psm" 91 "python_asyncio_protobuf_async_unary_5000rpcs_1KB_psm" 92) 93 94# Basic examples are intended to be runnable _as is_, so substitution keys 95# are stripped. Fields can be inserted manually following the pattern of the 96# prebuilt examples. 97basic_example() { 98 local -r scenario="${1}" 99 local -r outputdir="${2}" 100 local -r outputfile="$(example_file "${scenario}" _example_loadtest.yaml)" 101 local -r language="$(example_language "${outputfile}")" 102 ${LOADTEST_CONFIG} \ 103 -l "${language}" \ 104 -t ./tools/run_tests/performance/templates/loadtest_template_basic_all_languages.yaml \ 105 -s client_pool= -s server_pool= -s big_query_table= \ 106 -s timeout_seconds=900 --prefix=examples -u basic -r "^${scenario}$" \ 107 --allow_client_language=c++ --allow_server_language=c++ \ 108 -o "${outputdir}/${outputfile}" 109 echo "Created example: ${outputdir}/${outputfile}" 110} 111 112# Prebuilt examples contain substitution keys, so must be processed before 113# running. 114prebuilt_example() { 115 local -r scenario="${1}" 116 local -r outputdir="${2}" 117 local -r outputfile="$(example_file "${scenario}" _example_loadtest_with_prebuilt_workers.yaml)" 118 local -r language="$(example_language "${outputfile}")" 119 ${LOADTEST_CONFIG} \ 120 -l "${language}" \ 121 -t ./tools/run_tests/performance/templates/loadtest_template_prebuilt_all_languages.yaml \ 122 -s driver_pool="\${driver_pool}" -s driver_image="\${driver_image}" \ 123 -s client_pool="\${workers_pool}" -s server_pool="\${workers_pool}" \ 124 -s big_query_table="\${big_query_table}" -s timeout_seconds=900 \ 125 -s prebuilt_image_prefix="\${prebuilt_image_prefix}" \ 126 -s prebuilt_image_tag="\${prebuilt_image_tag}" --prefix=examples -u prebuilt \ 127 -a pool="\${workers_pool}" -r "^${scenario}$" \ 128 --allow_client_language=c++ --allow_server_language=c++ \ 129 -o "${outputdir}/${outputfile}" 130 echo "Created example: ${outputdir}/${outputfile}" 131} 132 133# PSM basic examples are intended to be runnable with only subsituding the 134# xds-server and sidecar images, so substitution keys for xds-server and 135# sidecar images are kept. 136psm_basic_example() { 137 local -r scenario="${1}" 138 local -r outputdir="${2}" 139 local -r uniquifier="${3}" 140 local -r outputfile="$(example_file "${scenario}" _example_loadtest_"${uniquifier}".yaml)" 141 local -r language="$(example_language "${outputfile}")" 142 ${LOADTEST_CONFIG} \ 143 -l "${language}" \ 144 -t ./tools/run_tests/performance/templates/loadtest_template_psm_"${uniquifier}"_basic_all_languages.yaml \ 145 -s client_pool= -s server_pool= -s big_query_table= \ 146 -s psm_image_prefix="\${psm_image_prefix}" \ 147 -s psm_image_tag="\${psm_image_tag}" \ 148 -s timeout_seconds=900 --prefix=psm-examples -u "${uniquifier}" -r "^${scenario}$" \ 149 -a enablePrometheus=true \ 150 --allow_client_language=c++ --allow_server_language=c++ \ 151 --client_channels=8 \ 152 --category=psm \ 153 --server_threads=16 \ 154 --offered_loads 5000 \ 155 -o "${outputdir}/${outputfile}" 156 echo "Created example: ${outputdir}/${outputfile}" 157} 158 159# PSM prebuilt examples contain substitution keys, so must be processed before 160# running. 161psm_prebuilt_example() { 162 local -r scenario="${1}" 163 local -r outputdir="${2}" 164 local -r uniquifier="${3}" 165 local -r outputfile="$(example_file "${scenario}" _example_loadtest_"${uniquifier}"_with_prebuilt_workers.yaml)" 166 local -r language="$(example_language "${outputfile}")" 167 ${LOADTEST_CONFIG} \ 168 -l "${language}" \ 169 -t ./tools/run_tests/performance/templates/loadtest_template_psm_"${uniquifier}"_prebuilt_all_languages.yaml \ 170 -s driver_pool="\${driver_pool}" -s driver_image="\${driver_image}" \ 171 -s client_pool="\${workers_pool}" -s server_pool="\${workers_pool}" \ 172 -s big_query_table="\${big_query_table}" -s timeout_seconds=900 \ 173 -s prebuilt_image_prefix="\${prebuilt_image_prefix}" \ 174 -s prebuilt_image_tag="\${prebuilt_image_tag}" \ 175 -s psm_image_prefix="\${psm_image_prefix}" \ 176 -s psm_image_tag="\${psm_image_tag}" \ 177 --prefix=psm-examples -u prebuilt-"${uniquifier}" -r "^${scenario}$" \ 178 -a pool="\${workers_pool}" \ 179 -a enablePrometheus=true \ 180 --allow_client_language=c++ --allow_server_language=c++ \ 181 --client_channels=8 \ 182 --category=psm \ 183 --server_threads=16 \ 184 --offered_loads 5000 \ 185 -o "${outputdir}/${outputfile}" 186 echo "Created example: ${outputdir}/${outputfile}" 187} 188 189for scenario in "${scenarios[@]}"; do 190 basic_example "${scenario}" "${outputbasedir}" 191done 192 193for scenario in "${scenarios[@]}"; do 194 prebuilt_example "${scenario}" "${outputbasedir}/templates" 195done 196 197for scenario in "${psm_scenarios[@]}"; do 198 psm_basic_example "${scenario}" "${outputbasedir}/templates/psm" "proxied" 199 psm_basic_example "${scenario}" "${outputbasedir}/templates/psm" "proxyless" 200done 201 202for scenario in "${psm_scenarios[@]}"; do 203 psm_prebuilt_example "${scenario}" "${outputbasedir}/templates/psm/prebuilt" "proxied" 204 psm_prebuilt_example "${scenario}" "${outputbasedir}/templates/psm/prebuilt" "proxyless" 205done 206