You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

188 lines
4.0 KiB

  1. #!/bin/bash
  2. rpcs=(1)
  3. conns=(1)
  4. warmup=10
  5. dur=10
  6. reqs=(1)
  7. resps=(1)
  8. rpc_types=(unary)
  9. # idx[0] = idx value for rpcs
  10. # idx[1] = idx value for conns
  11. # idx[2] = idx value for reqs
  12. # idx[3] = idx value for resps
  13. # idx[4] = idx value for rpc_types
  14. idx=(0 0 0 0 0)
  15. idx_max=(1 1 1 1 1)
  16. inc()
  17. {
  18. for i in $(seq $((${#idx[@]}-1)) -1 0); do
  19. idx[${i}]=$((${idx[${i}]}+1))
  20. if [ ${idx[${i}]} == ${idx_max[${i}]} ]; then
  21. idx[${i}]=0
  22. else
  23. break
  24. fi
  25. done
  26. local fin
  27. fin=1
  28. # Check to see if we have looped back to the beginning.
  29. for v in ${idx[@]}; do
  30. if [ ${v} != 0 ]; then
  31. fin=0
  32. break
  33. fi
  34. done
  35. if [ ${fin} == 1 ]; then
  36. rm -Rf ${out_dir}
  37. clean_and_die 0
  38. fi
  39. }
  40. clean_and_die() {
  41. rm -Rf ${out_dir}
  42. exit $1
  43. }
  44. run(){
  45. local nr
  46. nr=${rpcs[${idx[0]}]}
  47. local nc
  48. nc=${conns[${idx[1]}]}
  49. req_sz=${reqs[${idx[2]}]}
  50. resp_sz=${resps[${idx[3]}]}
  51. r_type=${rpc_types[${idx[4]}]}
  52. # Following runs one benchmark
  53. base_port=50051
  54. delta=0
  55. test_name="r_"${nr}"_c_"${nc}"_req_"${req_sz}"_resp_"${resp_sz}"_"${r_type}"_"$(date +%s)
  56. echo "================================================================================"
  57. echo ${test_name}
  58. while :
  59. do
  60. port=$((${base_port}+${delta}))
  61. # Launch the server in background
  62. ${out_dir}/server --port=${port} --test_name="Server_"${test_name}&
  63. server_pid=$(echo $!)
  64. # Launch the client
  65. ${out_dir}/client --port=${port} --d=${dur} --w=${warmup} --r=${nr} --c=${nc} --req=${req_sz} --resp=${resp_sz} --rpc_type=${r_type} --test_name="client_"${test_name}
  66. client_status=$(echo $?)
  67. kill -INT ${server_pid}
  68. wait ${server_pid}
  69. if [ ${client_status} == 0 ]; then
  70. break
  71. fi
  72. delta=$((${delta}+1))
  73. if [ ${delta} == 10 ]; then
  74. echo "Continuous 10 failed runs. Exiting now."
  75. rm -Rf ${out_dir}
  76. clean_and_die 1
  77. fi
  78. done
  79. }
  80. set_param(){
  81. local argname=$1
  82. shift
  83. local idx=$1
  84. shift
  85. if [ $# -eq 0 ]; then
  86. echo "${argname} not specified"
  87. exit 1
  88. fi
  89. PARAM=($(echo $1 | sed 's/,/ /g'))
  90. if [ ${idx} -lt 0 ]; then
  91. return
  92. fi
  93. idx_max[${idx}]=${#PARAM[@]}
  94. }
  95. while [ $# -gt 0 ]; do
  96. case "$1" in
  97. -r)
  98. shift
  99. set_param "number of rpcs" 0 $1
  100. rpcs=(${PARAM[@]})
  101. shift
  102. ;;
  103. -c)
  104. shift
  105. set_param "number of connections" 1 $1
  106. conns=(${PARAM[@]})
  107. shift
  108. ;;
  109. -w)
  110. shift
  111. set_param "warm-up period" -1 $1
  112. warmup=${PARAM}
  113. shift
  114. ;;
  115. -d)
  116. shift
  117. set_param "duration" -1 $1
  118. dur=${PARAM}
  119. shift
  120. ;;
  121. -req)
  122. shift
  123. set_param "request size" 2 $1
  124. reqs=(${PARAM[@]})
  125. shift
  126. ;;
  127. -resp)
  128. shift
  129. set_param "response size" 3 $1
  130. resps=(${PARAM[@]})
  131. shift
  132. ;;
  133. -rpc_type)
  134. shift
  135. set_param "rpc type" 4 $1
  136. rpc_types=(${PARAM[@]})
  137. shift
  138. ;;
  139. -h|--help)
  140. echo "Following are valid options:"
  141. echo
  142. echo "-h, --help show brief help"
  143. echo "-w warm-up duration in seconds, default value is 10"
  144. echo "-d benchmark duration in seconds, default value is 60"
  145. echo ""
  146. echo "Each of the following can have multiple comma separated values."
  147. echo ""
  148. echo "-r number of RPCs, default value is 1"
  149. echo "-c number of Connections, default value is 1"
  150. echo "-req req size in bytes, default value is 1"
  151. echo "-resp resp size in bytes, default value is 1"
  152. echo "-rpc_type valid values are unary|streaming, default is unary"
  153. ;;
  154. *)
  155. echo "Incorrect option $1"
  156. exit 1
  157. ;;
  158. esac
  159. done
  160. # Build server and client
  161. out_dir=$(mktemp -d oss_benchXXX)
  162. go build -o ${out_dir}/server $GOPATH/src/google.golang.org/grpc/benchmark/server/main.go && go build -o ${out_dir}/client $GOPATH/src/google.golang.org/grpc/benchmark/client/main.go
  163. if [ $? != 0 ]; then
  164. clean_and_die 1
  165. fi
  166. while :
  167. do
  168. run
  169. inc
  170. done