-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathperformance.py
More file actions
200 lines (168 loc) · 6.04 KB
/
Copy pathperformance.py
File metadata and controls
200 lines (168 loc) · 6.04 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
""" A performance testing framework for AppScale. """
from google.appengine.api import namespace_manager
from google.appengine.ext import db
import math
import time
import webapp2
try:
import json
except ImportError:
import simplejson as json
class TestEntity(db.Model):
""" An entity model used for puts, get, deletes, and queries with dummy data.
"""
prop1 = db.StringProperty(required=True)
prop2 = db.StringProperty(required=True)
prop3 = db.DateProperty(auto_now=True)
def get_summation(points):
""" Gets the summation over a set of points.
Args:
points: A list of floats.
Returns:
A float which is the summation over the set of points.
"""
total = 0.0
for point in points:
total += point
return total
def get_stdev(points):
""" Gets the standard deviation of a set of float data points.
Args:
points: A list of floats.
Returns:
A float, the standard deviation of a given set of points.
"""
summation = get_summation(points)
avg = get_average(points)
mean2 = avg * avg
return math.sqrt((summation * summation / len(points)) - mean2)
def get_average(points):
""" Gets the average of a set of float data points.
Args:
points: A list of floats.
Returns:
The average of the list of floats.
"""
return get_summation(points)/len(points)
class Puts(webapp2.RequestHandler):
""" Handlers for puts. """
def __init__(self, request, response):
""" Constructor.
Args:
request: The webapp2.Request object that contains information about the
current web request.
response: The webapp2.Response object that contains the response to be
sent back to the browser.
"""
self.initialize(request, response)
def post(self):
""" Handler for POST requests.
Request handler takes in the following arguments:
namespace: The namespace to write to.
number: The number of entities to write.
"""
namespace = self.request.get("namespace")
namespace_manager.set_namespace(namespace)
number = int(self.request.get("number"))
timings = []
for index in range(0, number):
test_ent = TestEntity(id=index+1, prop1="test1", prop2="test2")
start = time.time()
test_ent.put()
time_taken = time.time() - start
timings.append(time_taken)
response = {"avg": get_average(timings), "stdev": get_stdev(timings),
"total": get_summation(timings)}
self.response.out.write(json.dumps(response))
class Gets(webapp2.RequestHandler):
""" Handlers for gets. """
def __init__(self, request, response):
""" Constructor.
Args:
request: The webapp2.Request object that contains information about the
current web request.
response: The webapp2.Response object that contains the response to be
sent back to the browser.
"""
self.initialize(request, response)
def post(self):
""" Handler for POST requests.
Request handler takes in the following arguments:
namespace: The namespace to read to.
number: The number of entities to read.
"""
namespace = self.request.get("namespace")
namespace_manager.set_namespace(namespace)
number = int(self.request.get("number"))
timings = []
for index in range(0, number):
start = time.time()
_ = TestEntity.get_by_id(index+1)
time_taken = time.time() - start
timings.append(time_taken)
response = {"avg": get_average(timings), "stdev": get_stdev(timings),
"total": get_summation(timings)}
self.response.out.write(json.dumps(response))
class Deletes(webapp2.RequestHandler):
""" Handlers for deletes. """
def __init__(self, request, response):
""" Constructor.
Args:
request: The webapp2.Request object that contains information about the
current web request.
response: The webapp2.Response object that contains the response to be
sent back to the browser.
"""
self.initialize(request, response)
def post(self):
""" Handler for POST requests.
Request handler takes in the following arguments:
namespace: The namespace to delete to.
number: The number of entities to delete.
"""
namespace = self.request.get("namespace")
namespace_manager.set_namespace(namespace)
number = int(self.request.get("number"))
timings = []
for index in range(0, number):
test_ent_key = db.Key.from_path('TestEntity', index+1)
start = time.time()
db.delete(test_ent_key)
time_taken = time.time() - start
timings.append(time_taken)
response = {"avg": get_average(timings), "stdev": get_stdev(timings),
"total": get_summation(timings)}
self.response.out.write(json.dumps(response))
class Queries(webapp2.RequestHandler):
""" Handlers for queries. """
def __init__(self, request, response):
""" Constructor.
Args:
request: The webapp2.Request object that contains information about the
current web request.
response: The webapp2.Response object that contains the response to be
sent back to the browser.
"""
self.initialize(request, response)
def post(self):
""" Handler for POST requests.
Request handler takes in the following arguments:
namespace: The namespace to query from.
number: The maximum number of entities to fetch per query.
"""
namespace = self.request.get("namespace")
namespace_manager.set_namespace(namespace)
number = int(self.request.get("number"))
timings = []
for _ in range(0, number):
start = time.time()
TestEntity.all().fetch(number)
time_taken = time.time() - start
timings.append(time_taken)
response = {"avg": get_average(timings), "stdev": get_stdev(timings),
"total": get_summation(timings)}
self.response.out.write(json.dumps(response))
app = webapp2.WSGIApplication([('/puts', Puts),
('/gets', Gets),
('/deletes', Deletes),
('/queries', Queries)], debug=True)