Debian Codegraph @

tools/run_tests/performance/loadtest_examples.sh

raw
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
18 LOADTEST_CONFIG=tools/run_tests/performance/loadtest_config.py
19
20 if (( $# < 1 )); then
21 echo "Usage: ${0} <output directory>" >&2
22 exit 1
23 fi
24
25 if [[ ! -x "${LOADTEST_CONFIG}" ]]; then
26 echo "${LOADTEST_CONFIG} not found." >&2
27 exit 1
28 fi
29
30 outputbasedir="${1}"
31
32 mkdir -p "${outputbasedir}/templates/psm/prebuilt"
33
34 example_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
52 example_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
69 scenarios=(
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
83 psm_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.
97 basic_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 --allow_server_language=node \
109 -o "${outputdir}/${outputfile}"
110 echo "Created example: ${outputdir}/${outputfile}"
111 }
112
113 # Prebuilt examples contain substitution keys, so must be processed before
114 # running.
115 prebuilt_example() {
116 local -r scenario="${1}"
117 local -r outputdir="${2}"
118 local -r outputfile="$(example_file "${scenario}" _example_loadtest_with_prebuilt_workers.yaml)"
119 local -r language="$(example_language "${outputfile}")"
120 ${LOADTEST_CONFIG} \
121 -l "${language}" \
122 -t ./tools/run_tests/performance/templates/loadtest_template_prebuilt_all_languages.yaml \
123 -s driver_pool="\${driver_pool}" -s driver_image="\${driver_image}" \
124 -s client_pool="\${workers_pool}" -s server_pool="\${workers_pool}" \
125 -s big_query_table="\${big_query_table}" -s timeout_seconds=900 \
126 -s prebuilt_image_prefix="\${prebuilt_image_prefix}" \
127 -s prebuilt_image_tag="\${prebuilt_image_tag}" --prefix=examples -u prebuilt \
128 -a pool="\${workers_pool}" -r "^${scenario}$" \
129 --allow_client_language=c++ --allow_server_language=c++ \
130 --allow_server_language=node \
131 -o "${outputdir}/${outputfile}"
132 echo "Created example: ${outputdir}/${outputfile}"
133 }
134
135 # PSM basic examples are intended to be runnable with only subsituding the
136 # xds-server and sidecar images, so substitution keys for xds-server and
137 # sidecar images are kept.
138 psm_basic_example() {
139 local -r scenario="${1}"
140 local -r outputdir="${2}"
141 local -r uniquifier="${3}"
142 local -r outputfile="$(example_file "${scenario}" _example_loadtest_"${uniquifier}".yaml)"
143 local -r language="$(example_language "${outputfile}")"
144 ${LOADTEST_CONFIG} \
145 -l "${language}" \
146 -t ./tools/run_tests/performance/templates/loadtest_template_psm_"${uniquifier}"_basic_all_languages.yaml \
147 -s client_pool= -s server_pool= -s big_query_table= \
148 -s psm_image_prefix="\${psm_image_prefix}" \
149 -s psm_image_tag="\${psm_image_tag}" \
150 -s timeout_seconds=900 --prefix=psm-examples -u "${uniquifier}" -r "^${scenario}$" \
151 -a enablePrometheus=true \
152 --allow_client_language=c++ --allow_server_language=c++ \
153 --allow_server_language=node \
154 --client_channels=8 \
155 --category=psm \
156 --server_threads=16 \
157 --offered_loads 5000 \
158 -o "${outputdir}/${outputfile}"
159 echo "Created example: ${outputdir}/${outputfile}"
160 }
161
162 # PSM prebuilt examples contain substitution keys, so must be processed before
163 # running.
164 psm_prebuilt_example() {
165 local -r scenario="${1}"
166 local -r outputdir="${2}"
167 local -r uniquifier="${3}"
168 local -r outputfile="$(example_file "${scenario}" _example_loadtest_"${uniquifier}"_with_prebuilt_workers.yaml)"
169 local -r language="$(example_language "${outputfile}")"
170 ${LOADTEST_CONFIG} \
171 -l "${language}" \
172 -t ./tools/run_tests/performance/templates/loadtest_template_psm_"${uniquifier}"_prebuilt_all_languages.yaml \
173 -s driver_pool="\${driver_pool}" -s driver_image="\${driver_image}" \
174 -s client_pool="\${workers_pool}" -s server_pool="\${workers_pool}" \
175 -s big_query_table="\${big_query_table}" -s timeout_seconds=900 \
176 -s prebuilt_image_prefix="\${prebuilt_image_prefix}" \
177 -s prebuilt_image_tag="\${prebuilt_image_tag}" \
178 -s psm_image_prefix="\${psm_image_prefix}" \
179 -s psm_image_tag="\${psm_image_tag}" \
180 --prefix=psm-examples -u prebuilt-"${uniquifier}" -r "^${scenario}$" \
181 -a pool="\${workers_pool}" \
182 -a enablePrometheus=true \
183 --allow_client_language=c++ --allow_server_language=c++ \
184 --allow_server_language=node \
185 --client_channels=8 \
186 --category=psm \
187 --server_threads=16 \
188 --offered_loads 5000 \
189 -o "${outputdir}/${outputfile}"
190 echo "Created example: ${outputdir}/${outputfile}"
191 }
192
193 for scenario in "${scenarios[@]}"; do
194 basic_example "${scenario}" "${outputbasedir}"
195 done
196
197 for scenario in "${scenarios[@]}"; do
198 prebuilt_example "${scenario}" "${outputbasedir}/templates"
199 done
200
201 for scenario in "${psm_scenarios[@]}"; do
202 psm_basic_example "${scenario}" "${outputbasedir}/templates/psm" "proxied"
203 psm_basic_example "${scenario}" "${outputbasedir}/templates/psm" "proxyless"
204 done
205
206 for scenario in "${psm_scenarios[@]}"; do
207 psm_prebuilt_example "${scenario}" "${outputbasedir}/templates/psm/prebuilt" "proxied"
208 psm_prebuilt_example "${scenario}" "${outputbasedir}/templates/psm/prebuilt" "proxyless"
209 done