This repository has been archived by the owner on Sep 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
/
perf1.py
executable file
·125 lines (97 loc) · 2.89 KB
/
perf1.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
#!/usr/bin/python
import os.path
import string
import random
import os
import sys
import tempfile
from datetime import datetime, timedelta
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
my_char = '.'
def percent_cb(complete, total):
sys.stdout.write(my_char)
sys.stdout.flush()
def cb_random_bucketname(len):
chars = string.letters + string.digits
newpasswd = ""
for i in range(len):
newpasswd = newpasswd + random.choice(chars)
return newpasswd
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(10)
try:
bucket = conn.create_bucket(bucketname)
done = True
except:
print "bucket name %s exists, trying again" % bucketname
done = False
return (bucketname, bucket)
def upload_file(con, filename, mds):
(bucketname,bucket) = create_bucket(con)
k = boto.s3.key.Key(bucket)
k.key = filename
k.set_contents_from_filename(filename, md5=mds)
return (k, bucket)
def time_upload(con, count, size, fname=None, mds=None):
if fname == None:
print "making a new file"
(osf, filename) = tempfile.mkstemp()
os.close(osf)
f = open(filename, "w")
for i in range(0, size):
s = cb_random_bucketname(1024)
f.write(s)
f.close()
else:
filename = fname
size = os.path.getsize(filename)
try:
start_tm = datetime.now()
for i in range(0, count):
upload_file(con, filename, mds)
end_tm = datetime.now()
delt = end_tm - start_tm
us = float(delt.microseconds) / 1000000.0
tm = float(delt.seconds) + us
except:
if fname == None:
os.remove(filename)
raise
if fname == None:
os.remove(filename)
return (tm, size)
def main():
settings=os.path.expanduser('~/.nimbus/cumulus.ini')
s = SafeConfigParser()
s.readfp(open(settings, "r"))
con = cb_get_conn(s)
its = int(sys.argv[1])
kbs = int(sys.argv[2])
fname = None
if len(sys.argv) > 3:
fname = sys.argv[3]
mds = sys.argv[4]
(tm, size) = time_upload(con, its, kbs, fname, mds)
print tm / its
if __name__ == "__main__":
rc = main()
sys.exit(rc)