remote_script_helper.py 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. def generate_concurrency_script(benchmarker_config,
  2. name,
  3. url,
  4. port,
  5. accept_header,
  6. wrk_command="wrk"):
  7. '''
  8. Generates the string containing the bash script that will be run on the
  9. client to benchmark a single test. This specifically works for the variable
  10. concurrency tests.
  11. '''
  12. headers = headers_template.format(
  13. server_host=benchmarker_config.server_host, accept=accept_header)
  14. return concurrency_template.format(
  15. max_concurrency=max(benchmarker_config.concurrency_levels),
  16. name=name,
  17. duration=benchmarker_config.duration,
  18. levels=" ".join("{}".format(item)
  19. for item in benchmarker_config.concurrency_levels),
  20. server_host=benchmarker_config.server_host,
  21. port=port,
  22. url=url,
  23. headers=headers,
  24. wrk=wrk_command)
  25. def generate_pipeline_script(benchmarker_config,
  26. name,
  27. url,
  28. port,
  29. accept_header,
  30. wrk_command="wrk"):
  31. '''
  32. Generates the string containing the bash script that will be run on the
  33. client to benchmark a single pipeline test.
  34. '''
  35. headers = headers_template.format(
  36. server_host=benchmarker_config.server_host, accept=accept_header)
  37. return pipeline_template.format(
  38. max_concurrency=max(benchmarker_config.pipeline_concurrency_levels),
  39. name=name,
  40. duration=benchmarker_config.duration,
  41. levels=" ".join(
  42. "{}".format(item)
  43. for item in benchmarker_config.pipeline_concurrency_levels),
  44. server_host=benchmarker_config.server_host,
  45. port=port,
  46. url=url,
  47. headers=headers,
  48. wrk=wrk_command,
  49. pipeline=16)
  50. def generate_query_script(benchmarker_config, name, url, port, accept_header,
  51. query_levels):
  52. '''
  53. Generates the string containing the bash script that will be run on the
  54. client to benchmark a single test. This specifically works for the variable
  55. query tests (Query)
  56. '''
  57. headers = headers_template.format(
  58. server_host=benchmarker_config.server_host, accept=accept_header)
  59. return query_template.format(
  60. max_concurrency=max(benchmarker_config.concurrency_levels),
  61. name=name,
  62. duration=benchmarker_config.duration,
  63. levels=" ".join("{}".format(item) for item in query_levels),
  64. server_host=benchmarker_config.server_host,
  65. port=port,
  66. url=url,
  67. headers=headers)
  68. ##########################################################################################
  69. # Constants
  70. ##########################################################################################
  71. headers_template = "-H 'Host: {server_host}' -H 'Accept: {accept}' -H 'Connection: keep-alive'"
  72. # Used for test types that require no pipelining or query string params.
  73. concurrency_template = """
  74. let max_threads=$(cat /proc/cpuinfo | grep processor | wc -l)
  75. echo ""
  76. echo "---------------------------------------------------------"
  77. echo " Running Primer {name}"
  78. echo " {wrk} {headers} --latency -d 5 -c 8 --timeout 8 -t 8 \"http://{server_host}:{port}{url}\""
  79. echo "---------------------------------------------------------"
  80. echo ""
  81. {wrk} {headers} --latency -d 5 -c 8 --timeout 8 -t 8 "http://{server_host}:{port}{url}"
  82. sleep 5
  83. echo ""
  84. echo "---------------------------------------------------------"
  85. echo " Running Warmup {name}"
  86. echo " {wrk} {headers} --latency -d {duration} -c {max_concurrency} --timeout 8 -t $max_threads \"http://{server_host}:{port}{url}\""
  87. echo "---------------------------------------------------------"
  88. echo ""
  89. {wrk} {headers} --latency -d {duration} -c {max_concurrency} --timeout 8 -t $max_threads "http://{server_host}:{port}{url}"
  90. sleep 5
  91. echo ""
  92. echo "---------------------------------------------------------"
  93. echo " Synchronizing time"
  94. echo "---------------------------------------------------------"
  95. echo ""
  96. ntpdate -s pool.ntp.org
  97. for c in {levels}
  98. do
  99. echo ""
  100. echo "---------------------------------------------------------"
  101. echo " Concurrency: $c for {name}"
  102. echo " {wrk} {headers} --latency -d {duration} -c $c --timeout 8 -t $(($c>$max_threads?$max_threads:$c)) \"http://{server_host}:{port}{url}\""
  103. echo "---------------------------------------------------------"
  104. echo ""
  105. STARTTIME=$(date +"%s")
  106. {wrk} {headers} --latency -d {duration} -c $c --timeout 8 -t "$(($c>$max_threads?$max_threads:$c))" http://{server_host}:{port}{url}
  107. echo "STARTTIME $STARTTIME"
  108. echo "ENDTIME $(date +"%s")"
  109. sleep 2
  110. done
  111. """
  112. # Used for test types that require pipelining.
  113. pipeline_template = """
  114. let max_threads=$(cat /proc/cpuinfo | grep processor | wc -l)
  115. echo ""
  116. echo "---------------------------------------------------------"
  117. echo " Running Primer {name}"
  118. echo " {wrk} {headers} --latency -d 5 -c 8 --timeout 8 -t 8 \"http://{server_host}:{port}{url}\""
  119. echo "---------------------------------------------------------"
  120. echo ""
  121. {wrk} {headers} --latency -d 5 -c 8 --timeout 8 -t 8 "http://{server_host}:{port}{url}"
  122. sleep 5
  123. echo ""
  124. echo "---------------------------------------------------------"
  125. echo " Running Warmup {name}"
  126. echo " {wrk} {headers} --latency -d {duration} -c {max_concurrency} --timeout 8 -t $max_threads \"http://{server_host}:{port}{url}\""
  127. echo "---------------------------------------------------------"
  128. echo ""
  129. {wrk} {headers} --latency -d {duration} -c {max_concurrency} --timeout 8 -t $max_threads "http://{server_host}:{port}{url}"
  130. sleep 5
  131. echo ""
  132. echo "---------------------------------------------------------"
  133. echo " Synchronizing time"
  134. echo "---------------------------------------------------------"
  135. echo ""
  136. ntpdate -s pool.ntp.org
  137. for c in {levels}
  138. do
  139. echo ""
  140. echo "---------------------------------------------------------"
  141. echo " Concurrency: $c for {name}"
  142. echo " {wrk} {headers} --latency -d {duration} -c $c --timeout 8 -t $(($c>$max_threads?$max_threads:$c)) \"http://{server_host}:{port}{url}\" -s ~/pipeline.lua -- {pipeline}"
  143. echo "---------------------------------------------------------"
  144. echo ""
  145. STARTTIME=$(date +"%s")
  146. {wrk} {headers} --latency -d {duration} -c $c --timeout 8 -t "$(($c>$max_threads?$max_threads:$c))" http://{server_host}:{port}{url} -s ~/pipeline.lua -- {pipeline}
  147. echo "STARTTIME $STARTTIME"
  148. echo "ENDTIME $(date +"%s")"
  149. sleep 2
  150. done
  151. """
  152. # Used for test types that require a database -
  153. # These tests run at a static concurrency level and vary the size of
  154. # the query sent with each request
  155. query_template = """
  156. let max_threads=$(cat /proc/cpuinfo | grep processor | wc -l)
  157. echo ""
  158. echo "---------------------------------------------------------"
  159. echo " Running Primer {name}"
  160. echo " wrk {headers} --latency -d 5 -c 8 --timeout 8 -t 8 \"http://{server_host}:{port}{url}2\""
  161. echo "---------------------------------------------------------"
  162. echo ""
  163. wrk {headers} --latency -d 5 -c 8 --timeout 8 -t 8 "http://{server_host}:{port}{url}2"
  164. sleep 5
  165. echo ""
  166. echo "---------------------------------------------------------"
  167. echo " Running Warmup {name}"
  168. echo " wrk {headers} --latency -d {duration} -c {max_concurrency} --timeout 8 -t $max_threads \"http://{server_host}:{port}{url}2\""
  169. echo "---------------------------------------------------------"
  170. echo ""
  171. wrk {headers} --latency -d {duration} -c {max_concurrency} --timeout 8 -t $max_threads "http://{server_host}:{port}{url}2"
  172. sleep 5
  173. echo ""
  174. echo "---------------------------------------------------------"
  175. echo " Synchronizing time"
  176. echo "---------------------------------------------------------"
  177. echo ""
  178. ntpdate -s pool.ntp.org
  179. for c in {levels}
  180. do
  181. echo ""
  182. echo "---------------------------------------------------------"
  183. echo " Queries: $c for {name}"
  184. echo " wrk {headers} --latency -d {duration} -c {max_concurrency} --timeout 8 -t $max_threads \"http://{server_host}:{port}{url}$c\""
  185. echo "---------------------------------------------------------"
  186. echo ""
  187. STARTTIME=$(date +"%s")
  188. wrk {headers} --latency -d {duration} -c {max_concurrency} --timeout 8 -t $max_threads "http://{server_host}:{port}{url}$c"
  189. echo "STARTTIME $STARTTIME"
  190. echo "ENDTIME $(date +"%s")"
  191. sleep 2
  192. done
  193. """