123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- def generate_concurrency_script(benchmarker_config,
- name,
- url,
- port,
- accept_header,
- wrk_command="wrk"):
- '''
- Generates the string containing the bash script that will be run on the
- client to benchmark a single test. This specifically works for the variable
- concurrency tests.
- '''
- headers = headers_template.format(
- server_host=benchmarker_config.server_host, accept=accept_header)
- return concurrency_template.format(
- max_concurrency=max(benchmarker_config.concurrency_levels),
- name=name,
- duration=benchmarker_config.duration,
- levels=" ".join("{}".format(item)
- for item in benchmarker_config.concurrency_levels),
- server_host=benchmarker_config.server_host,
- port=port,
- url=url,
- headers=headers,
- wrk=wrk_command)
- def generate_pipeline_script(benchmarker_config,
- name,
- url,
- port,
- accept_header,
- wrk_command="wrk"):
- '''
- Generates the string containing the bash script that will be run on the
- client to benchmark a single pipeline test.
- '''
- headers = headers_template.format(
- server_host=benchmarker_config.server_host, accept=accept_header)
- return pipeline_template.format(
- max_concurrency=max(benchmarker_config.pipeline_concurrency_levels),
- name=name,
- duration=benchmarker_config.duration,
- levels=" ".join(
- "{}".format(item)
- for item in benchmarker_config.pipeline_concurrency_levels),
- server_host=benchmarker_config.server_host,
- port=port,
- url=url,
- headers=headers,
- wrk=wrk_command,
- pipeline=16)
- def generate_query_script(benchmarker_config, name, url, port, accept_header,
- query_levels):
- '''
- Generates the string containing the bash script that will be run on the
- client to benchmark a single test. This specifically works for the variable
- query tests (Query)
- '''
- headers = headers_template.format(
- server_host=benchmarker_config.server_host, accept=accept_header)
- return query_template.format(
- max_concurrency=max(benchmarker_config.concurrency_levels),
- name=name,
- duration=benchmarker_config.duration,
- levels=" ".join("{}".format(item) for item in query_levels),
- server_host=benchmarker_config.server_host,
- port=port,
- url=url,
- headers=headers)
- ##########################################################################################
- # Constants
- ##########################################################################################
- headers_template = "-H 'Host: {server_host}' -H 'Accept: {accept}' -H 'Connection: keep-alive'"
- # Used for test types that require no pipelining or query string params.
- concurrency_template = """
- let max_threads=$(cat /proc/cpuinfo | grep processor | wc -l)
- echo ""
- echo "---------------------------------------------------------"
- echo " Running Primer {name}"
- echo " {wrk} {headers} --latency -d 5 -c 8 --timeout 8 -t 8 \"http://{server_host}:{port}{url}\""
- echo "---------------------------------------------------------"
- echo ""
- {wrk} {headers} --latency -d 5 -c 8 --timeout 8 -t 8 "http://{server_host}:{port}{url}"
- sleep 5
- echo ""
- echo "---------------------------------------------------------"
- echo " Running Warmup {name}"
- echo " {wrk} {headers} --latency -d {duration} -c {max_concurrency} --timeout 8 -t $max_threads \"http://{server_host}:{port}{url}\""
- echo "---------------------------------------------------------"
- echo ""
- {wrk} {headers} --latency -d {duration} -c {max_concurrency} --timeout 8 -t $max_threads "http://{server_host}:{port}{url}"
- sleep 5
- echo ""
- echo "---------------------------------------------------------"
- echo " Synchronizing time"
- echo "---------------------------------------------------------"
- echo ""
- ntpdate -s pool.ntp.org
- for c in {levels}
- do
- echo ""
- echo "---------------------------------------------------------"
- echo " Concurrency: $c for {name}"
- echo " {wrk} {headers} --latency -d {duration} -c $c --timeout 8 -t $(($c>$max_threads?$max_threads:$c)) \"http://{server_host}:{port}{url}\""
- echo "---------------------------------------------------------"
- echo ""
- STARTTIME=$(date +"%s")
- {wrk} {headers} --latency -d {duration} -c $c --timeout 8 -t "$(($c>$max_threads?$max_threads:$c))" http://{server_host}:{port}{url}
- echo "STARTTIME $STARTTIME"
- echo "ENDTIME $(date +"%s")"
- sleep 2
- done
- """
- # Used for test types that require pipelining.
- pipeline_template = """
- let max_threads=$(cat /proc/cpuinfo | grep processor | wc -l)
- echo ""
- echo "---------------------------------------------------------"
- echo " Running Primer {name}"
- echo " {wrk} {headers} --latency -d 5 -c 8 --timeout 8 -t 8 \"http://{server_host}:{port}{url}\""
- echo "---------------------------------------------------------"
- echo ""
- {wrk} {headers} --latency -d 5 -c 8 --timeout 8 -t 8 "http://{server_host}:{port}{url}"
- sleep 5
- echo ""
- echo "---------------------------------------------------------"
- echo " Running Warmup {name}"
- echo " {wrk} {headers} --latency -d {duration} -c {max_concurrency} --timeout 8 -t $max_threads \"http://{server_host}:{port}{url}\""
- echo "---------------------------------------------------------"
- echo ""
- {wrk} {headers} --latency -d {duration} -c {max_concurrency} --timeout 8 -t $max_threads "http://{server_host}:{port}{url}"
- sleep 5
- echo ""
- echo "---------------------------------------------------------"
- echo " Synchronizing time"
- echo "---------------------------------------------------------"
- echo ""
- ntpdate -s pool.ntp.org
- for c in {levels}
- do
- echo ""
- echo "---------------------------------------------------------"
- echo " Concurrency: $c for {name}"
- 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}"
- echo "---------------------------------------------------------"
- echo ""
- STARTTIME=$(date +"%s")
- {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}
- echo "STARTTIME $STARTTIME"
- echo "ENDTIME $(date +"%s")"
- sleep 2
- done
- """
- # Used for test types that require a database -
- # These tests run at a static concurrency level and vary the size of
- # the query sent with each request
- query_template = """
- let max_threads=$(cat /proc/cpuinfo | grep processor | wc -l)
- echo ""
- echo "---------------------------------------------------------"
- echo " Running Primer {name}"
- echo " wrk {headers} --latency -d 5 -c 8 --timeout 8 -t 8 \"http://{server_host}:{port}{url}2\""
- echo "---------------------------------------------------------"
- echo ""
- wrk {headers} --latency -d 5 -c 8 --timeout 8 -t 8 "http://{server_host}:{port}{url}2"
- sleep 5
- echo ""
- echo "---------------------------------------------------------"
- echo " Running Warmup {name}"
- echo " wrk {headers} --latency -d {duration} -c {max_concurrency} --timeout 8 -t $max_threads \"http://{server_host}:{port}{url}2\""
- echo "---------------------------------------------------------"
- echo ""
- wrk {headers} --latency -d {duration} -c {max_concurrency} --timeout 8 -t $max_threads "http://{server_host}:{port}{url}2"
- sleep 5
- echo ""
- echo "---------------------------------------------------------"
- echo " Synchronizing time"
- echo "---------------------------------------------------------"
- echo ""
- ntpdate -s pool.ntp.org
- for c in {levels}
- do
- echo ""
- echo "---------------------------------------------------------"
- echo " Queries: $c for {name}"
- echo " wrk {headers} --latency -d {duration} -c {max_concurrency} --timeout 8 -t $max_threads \"http://{server_host}:{port}{url}$c\""
- echo "---------------------------------------------------------"
- echo ""
- STARTTIME=$(date +"%s")
- wrk {headers} --latency -d {duration} -c {max_concurrency} --timeout 8 -t $max_threads "http://{server_host}:{port}{url}$c"
- echo "STARTTIME $STARTTIME"
- echo "ENDTIME $(date +"%s")"
- sleep 2
- done
- """
|