This repository has been archived by the owner on Sep 23, 2020. It is now read-only.
/
disk2disk.py
executable file
·168 lines (137 loc) · 4.1 KB
/
disk2disk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/python
import os.path
import string
import random
import os
import sys
import tempfile
from datetime import datetime, timedelta
import threading
import boto
from boto.s3.connection import S3Connection
from boto.s3.connection import OrdinaryCallingFormat
from boto.s3.connection import VHostCallingFormat
from boto.s3.connection import SubdomainCallingFormat
import sys
from ConfigParser import SafeConfigParser
g_lock = threading.Lock()
g_ctr = 0
g_buckets = []
g_times = []
def percent_cb(complete, total):
my_char = threading.current_thread().getName()
# sys.stdout.write(my_char)
sys.stdout.flush()
def cb_random_bucketname(len):
global g_ctr
g_ctr = g_ctr + 1
chars = string.letters + string.digits
newpasswd = ""
for i in range(len - 1):
newpasswd = newpasswd + random.choice(chars)
bn = "%s%d%s" % (threading.current_thread().getName(), g_ctr, newpasswd)
return bn
def cb_get_conn(s):
cf = OrdinaryCallingFormat()
hostname = s.get("cb", "hostname")
p = int(s.get("cb", "port"))
use_sec = False
pw = s.get("tests", "pw")
id = s.get("tests", "id")
dbg = 0
print "attempting to connect to %s:%d" % (hostname, p)
conn = S3Connection(id, pw, host=hostname, port=p, is_secure=use_sec, debug=dbg, calling_format=cf)
return conn
def create_bucket(conn):
done = False
while done == False:
bucketname = cb_random_bucketname(15)
try:
bucket = conn.create_bucket(bucketname)
done = True
except Exception as ex:
print ex
print "bucket name %s exists, trying again" % (bucketname)
done = False
return (bucketname, bucket)
def upload_file(con, file):
(bucketname,bucket) = create_bucket(con)
k = boto.s3.key.Key(bucket)
k.key = cb_random_bucketname(5)
k.set_contents_from_filename(file, cb=percent_cb, num_cb=10)
return (k, bucket)
def time_upload(s, file):
global g_buckets
global g_lock
global g_times
con = cb_get_conn(s)
try:
my_char = threading.current_thread().getName()
print "Starting thread %s" % (my_char)
start_tm = datetime.now()
(k, b) = upload_file(con, file)
end_tm = datetime.now()
delt = end_tm - start_tm
us = float(delt.microseconds) / 1000000.0
tm = float(delt.seconds) + us
g_lock.acquire()
try:
g_buckets.append((b,k))
g_times.append(tm)
finally:
g_lock.release()
except:
raise
print tm
def main():
global g_buckets
global g_times
global data
settings=os.path.expanduser('~/.nimbus/cumulus.ini')
s = SafeConfigParser()
s.readfp(open(settings, "r"))
its = int(sys.argv[1])
file = sys.argv[2]
size = os.path.getsize(file)
print "file %s of %d bytes" % (file, size)
start_tm = datetime.now()
t_a = []
char = "abcdefghijklmnopqrstuvvxyz"
for i in range(0, its):
t = threading.Thread(target=time_upload, args=(s, file), name=char[i%len(char)])
t_a.append(t)
t.start()
for i in range(0, its):
print "joining %s" % (t_a[i].getName())
t_a[i].join()
end_tm = datetime.now()
delt = end_tm - start_tm
us = float(delt.microseconds) / 1000000.0
tm = float(delt.seconds) + us
for (b,k) in g_buckets:
try:
k.delete()
except:
pass
b.delete()
max = -1.0
min = 99999999.0
for tm in g_times:
if tm > max:
max = tm
if tm < min:
min = tm
sizeMB = size * 1024*1024
total_bytes = size * its
total_bw = float(total_bytes) / float(tm)
avg_tm = float(tm) / float(its)
avg_bw = float(total_bw) / float(its)
print "clients,sizeMB,totalMB,totaltime,totalMBps,avgtm,avgbw,max,min"
print "%d,%d,%d,%f,%f,%f,%f,%f,%f" %(its, size, total_bytes, tm, total_bw, avg_tm, avg_bw, max, min)
for tm in g_times:
sys.stdout.write(tm)
sys.stdout.write(",")
sys.stdout.write("\n")
if __name__ == "__main__":
rc = main()
sys.exit(rc)