loadtest_examples.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. # This script generates a set of load test examples from templates.
  16. LOADTEST_CONFIG=tools/run_tests/performance/loadtest_config.py
  17. if (( $# < 1 )); then
  18. echo "Usage: ${0} <output directory>" >&2
  19. exit 1
  20. fi
  21. if [[ ! -x "${LOADTEST_CONFIG}" ]]; then
  22. echo "${LOADTEST_CONFIG} not found." >&2
  23. exit 1
  24. fi
  25. outputbasedir="${1}"
  26. mkdir -p "${outputbasedir}/templates"
  27. example_file() {
  28. local scenario="${1}"
  29. local suffix="${2}"
  30. if [[ "${scenario#cpp_}" != "${scenario}" ]]; then
  31. echo "cxx${suffix}"
  32. return
  33. fi
  34. if [[ "${scenario#python_asyncio_}" != "${scenario}" ]]; then
  35. echo "python_asyncio${suffix}"
  36. return
  37. fi
  38. if [[ "${scenario#php7_protobuf_c_}" != "${scenario}" ]]; then
  39. echo "php7_protobuf_c${suffix}"
  40. return
  41. fi
  42. echo "${scenario%%_*}${suffix}"
  43. }
  44. example_language() {
  45. local filename="${1}"
  46. if [[ "${filename#cxx_}" != "${filename}" ]]; then
  47. echo "c++"
  48. return
  49. fi
  50. if [[ "${filename#python_asyncio_}" != "${filename}" ]]; then
  51. echo "python_asyncio"
  52. return
  53. fi
  54. if [[ "${filename#php7_protobuf_c_}" != "${filename}" ]]; then
  55. echo "php7_protobuf_c"
  56. return
  57. fi
  58. echo "${filename%%_*}"
  59. }
  60. scenarios=(
  61. "cpp_generic_async_streaming_ping_pong_secure"
  62. "csharp_protobuf_async_unary_ping_pong"
  63. "go_generic_sync_streaming_ping_pong_secure"
  64. "java_generic_async_streaming_ping_pong_secure"
  65. "node_to_node_generic_async_streaming_ping_pong_secure"
  66. "php7_protobuf_php_extension_to_cpp_protobuf_sync_unary_ping_pong"
  67. "php7_protobuf_c_extension_to_cpp_protobuf_sync_unary_ping_pong"
  68. "python_generic_sync_streaming_ping_pong"
  69. "python_asyncio_generic_async_streaming_ping_pong"
  70. "ruby_protobuf_sync_streaming_ping_pong"
  71. )
  72. # Basic examples are intended to be runnable _as is_, so substitution keys
  73. # are stripped. Fields can be inserted manually following the pattern of the
  74. # prebuilt examples.
  75. basic_example() {
  76. local -r scenario="${1}"
  77. local -r outputdir="${2}"
  78. local -r outputfile="$(example_file "${scenario}" _example_loadtest.yaml)"
  79. local -r language="$(example_language "${outputfile}")"
  80. ${LOADTEST_CONFIG} \
  81. -l "${language}" \
  82. -t ./tools/run_tests/performance/templates/loadtest_template_basic_all_languages.yaml \
  83. -s client_pool= -s server_pool= -s big_query_table= \
  84. -s timeout_seconds=900 --prefix=examples -u basic -r "^${scenario}$" \
  85. --allow_client_language=c++ --allow_server_language=c++ \
  86. --allow_server_language=node \
  87. -o "${outputdir}/${outputfile}"
  88. echo "Created example: ${outputfile}"
  89. }
  90. # Prebuilt examples contain substitution keys, so must be processed before
  91. # running.
  92. prebuilt_example() {
  93. local -r scenario="${1}"
  94. local -r outputdir="${2}"
  95. local -r outputfile="$(example_file "${scenario}" _example_loadtest_with_prebuilt_workers.yaml)"
  96. local -r language="$(example_language "${outputfile}")"
  97. ${LOADTEST_CONFIG} \
  98. -l "${language}" \
  99. -t ./tools/run_tests/performance/templates/loadtest_template_prebuilt_all_languages.yaml \
  100. -s driver_pool="\${driver_pool}" -s driver_image="\${driver_image}" \
  101. -s client_pool="\${workers_pool}" -s server_pool="\${workers_pool}" \
  102. -s big_query_table="\${big_query_table}" -s timeout_seconds=900 \
  103. -s prebuilt_image_prefix="\${prebuilt_image_prefix}" \
  104. -s prebuilt_image_tag="\${prebuilt_image_tag}" --prefix=examples -u prebuilt \
  105. -a pool="\${workers_pool}" -r "^${scenario}$" \
  106. --allow_client_language=c++ --allow_server_language=c++ \
  107. --allow_server_language=node \
  108. -o "${outputdir}/${outputfile}"
  109. echo "Created example: ${outputfile}"
  110. }
  111. for scenario in "${scenarios[@]}"; do
  112. basic_example "${scenario}" "${outputbasedir}"
  113. done
  114. for scenario in "${scenarios[@]}"; do
  115. prebuilt_example "${scenario}" "${outputbasedir}/templates"
  116. done