| 1 | #! /usr/bin/python |
|---|
| 2 | |
|---|
| 3 | import os, time, re, subprocess, urllib |
|---|
| 4 | |
|---|
| 5 | TAHOE = os.path.expanduser("~/tahoe/tahoe-lafs/bin/tahoe") |
|---|
| 6 | BASEDIR = os.path.expanduser("~/grids/perfgrid/perf-client") |
|---|
| 7 | |
|---|
| 8 | def restart(basedir, k, N): |
|---|
| 9 | fn = os.path.join(basedir, "tahoe.cfg") |
|---|
| 10 | newfn = fn+".new" |
|---|
| 11 | new = open(newfn, "w") |
|---|
| 12 | for line in open(fn,"r").readlines(): |
|---|
| 13 | if line.startswith("shares.needed"): |
|---|
| 14 | line = "shares.needed = %d\n" % k |
|---|
| 15 | if line.startswith("shares.happy"): |
|---|
| 16 | line = "shares.happy = 1\n" |
|---|
| 17 | if line.startswith("shares.total"): |
|---|
| 18 | line = "shares.total = %d\n" % N |
|---|
| 19 | new.write(line) |
|---|
| 20 | new.close() |
|---|
| 21 | os.rename(newfn, fn) |
|---|
| 22 | |
|---|
| 23 | p = subprocess.Popen([TAHOE, "restart", BASEDIR]) |
|---|
| 24 | p.communicate() |
|---|
| 25 | if p.returncode != 0: |
|---|
| 26 | print "unable to restart tahoe" |
|---|
| 27 | os.exit(1) |
|---|
| 28 | # now we need to wait until all servers are connected |
|---|
| 29 | timeout = 60 |
|---|
| 30 | while True: |
|---|
| 31 | timeout -= 1 |
|---|
| 32 | if timeout <= 0: |
|---|
| 33 | print "gave up waiting for restart" |
|---|
| 34 | os.exit(1) |
|---|
| 35 | time.sleep(1) |
|---|
| 36 | d = urllib.urlopen("http://localhost:8123/").readlines() |
|---|
| 37 | d2 = [l for l in d |
|---|
| 38 | if "Connected to" in l and |
|---|
| 39 | "introducer" not in l and "helper" not in l] |
|---|
| 40 | if len(d2) != 1: |
|---|
| 41 | continue |
|---|
| 42 | mo = re.search(r'<span>(\d+)</span>', d2[0]) |
|---|
| 43 | if not mo: |
|---|
| 44 | continue |
|---|
| 45 | count = int(mo.group(1)) |
|---|
| 46 | if count < 6: |
|---|
| 47 | continue |
|---|
| 48 | break |
|---|
| 49 | |
|---|
| 50 | print "restarted" |
|---|
| 51 | |
|---|
| 52 | def upload(basedir, k, N, size, name): |
|---|
| 53 | size = int(size) |
|---|
| 54 | restart(basedir, k, N) |
|---|
| 55 | fn = "%s--%d-of-%d" % (name, k, N) |
|---|
| 56 | assert size > 8 |
|---|
| 57 | data = os.urandom(8) + "\x00" * (size-8) |
|---|
| 58 | p = subprocess.Popen([TAHOE, "put", "-", "perf:%s" % fn], stdin=subprocess.PIPE) |
|---|
| 59 | p.communicate(data) |
|---|
| 60 | if p.returncode != 0: |
|---|
| 61 | print "unable to upload" |
|---|
| 62 | os.exit(1) |
|---|
| 63 | |
|---|
| 64 | for size,name in [(1e6,"1MB"), (10e6,"10MB"), (100e6,"100MB")]: |
|---|
| 65 | for k in range(1, 60+1): |
|---|
| 66 | N = k |
|---|
| 67 | upload(BASEDIR, k, N, size, name) |
|---|