Commit dcb9daaf authored by Cecylia Bocovich's avatar Cecylia Bocovich
Browse files

added a large file download for bandwidth/throttling tests

parent 9a9f6603
...@@ -10,7 +10,7 @@ Add to crontab to run hourly tests: ...@@ -10,7 +10,7 @@ Add to crontab to run hourly tests:
0 */1 * * * cd ~/kz && ./bridgetest.sh [SITENAME] 0 */1 * * * cd ~/kz && ./bridgetest.sh [SITENAME]
Generate a CSV file from logs: Generate a CSV file from logs:
find log -name '*.log' | sort | ./makecsv > bridgetest.csv find log -name '*.log' | sort | ./makecsv > bridgetest.csv 2> bandwidth.csv
Make a graph: Make a graph:
Rscript graph.R bridgetest.csv Rscript graph.R bridgetest.csv
...@@ -43,6 +43,22 @@ def start_tcpdump(basename, addr): ...@@ -43,6 +43,22 @@ def start_tcpdump(basename, addr):
stderr=open(basename + ".tcpdump.err", "w")) stderr=open(basename + ".tcpdump.err", "w"))
return p return p
def download_file():
logging.info("Attempting to download large file")
try:
start = time.time()
subprocess.check_call(["/usr/bin/torsocks", "wget", "-O", "/dev/null", "http://mirror.cs.uwaterloo.ca/raspbian/images/apc_apricot_r1.zip"])
stop = time.time()
download_time = stop - start
except subprocess.CalledProcessError as e:
logging.info("failed to download file: %s", e)
download_time = -1
finally:
return download_time
def start_tor(tor_config): def start_tor(tor_config):
assert "DataDirectory" in tor_config assert "DataDirectory" in tor_config
...@@ -133,6 +149,13 @@ with open(bridge_lines_file) as f: ...@@ -133,6 +149,13 @@ with open(bridge_lines_file) as f:
except OSError as err: except OSError as err:
logging.info("failed to start tor: %s" % err) logging.info("failed to start tor: %s" % err)
continue continue
#Now try a large file download
download_time = download_file()
f = open(os.path.join(".", "%s.log" % nickname), 'a')
f.write("Downloaded " + str(download_time) + "s\n")
f.close()
tor_proc.terminate() tor_proc.terminate()
tor_proc.wait() tor_proc.wait()
finally: finally:
......
...@@ -12,29 +12,43 @@ locale.setlocale(locale.LC_ALL, "C") ...@@ -12,29 +12,43 @@ locale.setlocale(locale.LC_ALL, "C")
# Dec 01 20:57:53.000 [notice] Bootstrapped 0%: Starting # Dec 01 20:57:53.000 [notice] Bootstrapped 0%: Starting
bootstrapped_re = re.compile(r'^(\w+ \d+ \d\d:\d\d:\d\d\.\d\d\d) \[\w+\] Bootstrapped (\d+)%') bootstrapped_re = re.compile(r'^(\w+ \d+ \d\d:\d\d:\d\d\.\d\d\d) \[\w+\] Bootstrapped (\d+)%')
bandwidth_re = re.compile(r'^Downloaded (-?\d+.\d+)s')
csvW = csv.DictWriter(sys.stdout, fieldnames=("timestamp", "site", "runid", "nickname", "percent")) csvW = csv.DictWriter(sys.stdout, fieldnames=("timestamp", "site", "runid", "nickname", "percent"))
csvW.writeheader() csvW.writeheader()
csvE = csv.DictWriter(sys.stderr, fieldnames=("site", "runid", "nickname", "download"))
csvE.writeheader()
def process_log(f, site, runid, nickname): def process_log(f, site, runid, nickname):
for line in f: for line in f:
m = bootstrapped_re.match(line) m = bootstrapped_re.match(line)
if m is None: n = bandwidth_re.match(line)
continue if m is not None:
timestamp = datetime.datetime.strptime(m.group(1), "%b %d %H:%M:%S.%f") timestamp = datetime.datetime.strptime(m.group(1), "%b %d %H:%M:%S.%f")
# tor logs don't contain the year, so grab it from the runid. # tor logs don't contain the year, so grab it from the runid.
timestamp = timestamp.replace(year=int(runid[:4])) timestamp = timestamp.replace(year=int(runid[:4]))
percent = m.group(2) percent = m.group(2)
row = { row = {
"timestamp": timestamp.strftime("%Y-%m-%d %H:%M:%S.%f"), "timestamp": timestamp.strftime("%Y-%m-%d %H:%M:%S.%f"),
"site": site, "site": site,
"runid": runid, "runid": runid,
"nickname": nickname, "nickname": nickname,
"percent": percent, "percent": percent,
} }
csvW.writerow(row) csvW.writerow(row)
elif n is not None:
download_time = n.group(1)
row = {
"site": site,
"runid": runid,
"nickname": nickname,
"download": download_time,
}
csvE.writerow(row)
for filename in sys.stdin: for filename in sys.stdin:
filename = filename.strip() filename = filename.strip()
......
Supports Markdown
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