Commit 24e4feca by Victor Shnayder

Clean up the load test script a bit

parent 958f1409
...@@ -44,6 +44,12 @@ For loop to ramp up load: ...@@ -44,6 +44,12 @@ For loop to ramp up load:
for conc in 1 2 3 5 8 13 21; do bench anon ${conc}00 $conc /jobs; done for conc in 1 2 3 5 8 13 21; do bench anon ${conc}00 $conc /jobs; done
Useful curl incantation:
curl stage-edx-001.m.edx.org/courses/BerkeleyX/CS188/fa12/courseware/Week_1/Project_0_Tutorial/ -b "sessionid=de0fe775b2192445dce76a09deeb740a;csrftoken=2987de2837f3d7051a9d92335b448cf1" -u "anant:agarwal" -D headers
pass cookies, user/pass, and dump headers to file "headers"
""" """
def test_url(url, requests, concurrency, ab_options, logpath): def test_url(url, requests, concurrency, ab_options, logpath):
...@@ -59,15 +65,48 @@ def test_url(url, requests, concurrency, ab_options, logpath): ...@@ -59,15 +65,48 @@ def test_url(url, requests, concurrency, ab_options, logpath):
print "running {0}".format(cmd) print "running {0}".format(cmd)
os.system(cmd) os.system(cmd)
def read_pagelist(filepath):
def loadtest(server, pages, ab_options, args): """
read list of pages, skipping blank lines and lines that start with '#'
"""
out = []
try:
with open(filepath) as f:
for line in f:
line = line.strip()
if line.startswith('#') or len(line) == 0:
continue
out.append(line)
except:
print "Couldn't load {0}".format(filepath)
raise
return out
def loadtest(args):
"""Actually do the load test """Actually do the load test
args: argparse result. Should contain:
server: url of server, with or without http[s]:// server: url of server, with or without http[s]://
pages: list of page urls, including leading slash pages: list of page urls, including leading slash
ab_options: list of options to pass to ab. abopts: list of options to pass to ab.
args: dictionary of other random arguments
""" """
server = args.server
name = args.name
ab_options = args.abopt if args.abopt else []
ab_options += ["-Aanant:agarwal"]
if args.sessionid:
ab_options += ["-C 'sessionid={0}'".format(args.sessionid)]
if args.csrftoken:
ab_options += ["-C 'csrftoken={0}'".format(args.csrftoken)]
pages = args.pages if args.pages else []
if args.pagelist:
pages += read_pagelist(args.pagelist)
if not server.startswith('http'): if not server.startswith('http'):
# use http by default, but if https is specified, use that # use http by default, but if https is specified, use that
server = 'http://' + server server = 'http://' + server
...@@ -75,11 +114,14 @@ def loadtest(server, pages, ab_options, args): ...@@ -75,11 +114,14 @@ def loadtest(server, pages, ab_options, args):
# want a string # want a string
ab_options = ' '.join(str(s) for s in ab_options) if ab_options is not None else "" ab_options = ' '.join(str(s) for s in ab_options) if ab_options is not None else ""
reqs_per_thread = 10 reqs_per_thread = 2
name = args.get('name', "noname")
# If there are already results for this run, just delete them. (TODO: Desired behavior?)
os.system("rm -rf {name}".format(name=name))
for page in pages: for page in pages:
url = "{server}{page}".format(server=server, page=page) url = "{server}{page}".format(server=server, page=page)
outdir = "{name}/page_{page}".format(name=name, page=page.replace('/', '-')) outdir = "{name}/page_{page}".format(name=name, page=page.replace('/', '-'))
print "Testing {0}. Output in {1}".format(url, outdir)
os.makedirs(outdir) os.makedirs(outdir)
for conc in [1]: #[1, 2, 3, 10]: for conc in [1]: #[1, 2, 3, 10]:
requests = conc * reqs_per_thread requests = conc * reqs_per_thread
...@@ -97,15 +139,25 @@ def main(): ...@@ -97,15 +139,25 @@ def main():
parser = argparse.ArgumentParser(description='Run load tests on an edx server.') parser = argparse.ArgumentParser(description='Run load tests on an edx server.')
parser.add_argument('server', parser.add_argument('server',
help='the server to test') help='the server to test')
parser.add_argument('pages', metavar='PAGE', type=str, nargs='+', parser.add_argument('--pages', metavar='PAGE', type=str, nargs='*',
help='a page to test (url will be server/{PAGE})') help='a page to test (url will be server/{PAGE})')
parser.add_argument('--sessionid', parser.add_argument('--sessionid',
help='if testing non-anonymously, specify session id') help='if testing non-anonymously, specify session id')
parser.add_argument('--csrftoken',
help='if posting forms, specify csrftoken')
parser.add_argument('--name',
help='test name--results will be in {name}/',
default='noname')
parser.add_argument('--pagelist',
help="""a file containing additional pages to test.
Empty lines and lines that start with # are ignored.
Will be added to pages specified on the command line""")
parser.add_argument('--abopt', action='append') parser.add_argument('--abopt', action='append')
args = parser.parse_args() args = parser.parse_args()
loadtest(args.server, args.pages, args.abopt, vars(args)) loadtest(args)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
# A dumb file specifying pages to test, with abtest options: page\s+(options)? # A dumb file specifying pages to test, with abtest options: page\s+(options)?
# lines that start with '\s*#' ignored
/ /
/jobs /jobs
/courses/ /courses/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment