gdp / apps / rest-test / restful_demo_session_amortized.html @ master
History | View | Annotate | Download (1.52 KB)
1 |
<html>
|
---|---|
2 |
<head><title>RESTful Demo - HTTPS/TCP Session Setup and Teardown Amortized</title></head> |
3 |
<body>
|
4 |
<pre>
|
5 |
#!/usr/bin/env python |
6 |
|
7 |
# The RESTful GDP Gateway's HTTPS/TCP Session Setup and Teardown is expensive. |
8 |
# |
9 |
# A single read or append per session (see restful_demo_session_expense.html) |
10 |
# has relatively low performance and high latency. |
11 |
# |
12 |
# Where multiple reads or appends are needed, performance and latency are |
13 |
# significantly improved by amortizing a single HTTPS/TCP session over |
14 |
# multiple actions (as shown in this script). |
15 |
|
16 |
import json |
17 |
import requests |
18 |
import time |
19 |
import random |
20 |
import sys |
21 |
|
22 |
test_auth = ("PLEASE_EDIT_username", "PLEASE_EDIT_password") |
23 |
json_header = { 'Content-type': 'application/json' } |
24 |
|
25 |
def GDPwrite(data, gcl_name, session): |
26 |
|
27 |
start_time = time.time() |
28 |
wrec = session.post("https://gdp-rest-01.eecs.berkeley.edu/gdp/v1/gcl/" + |
29 |
gcl_name, |
30 |
auth = test_auth, |
31 |
timeout = 60, |
32 |
headers = json_header, |
33 |
data = data) # serialize json_body |
34 |
|
35 |
success = wrec.status_code == 200 |
36 |
end_time = time.time() |
37 |
return (end_time - start_time, success) |
38 |
|
39 |
if __name__=="__main__": |
40 |
|
41 |
if len(sys.argv)<2:
|
42 |
sys.stderr.write("Usage: %s <logname>\n" % sys.argv[0]) |
43 |
sys.exit(-1) |
44 |
|
45 |
logname = sys.argv[1] |
46 |
session = requests.Session() |
47 |
for i in xrange(10): |
48 |
random_data = str(random.randint(0, 2**32)) |
49 |
print GDPwrite(random_data, logname, session) |
50 |
|
51 |
</pre>
|
52 |
</body>
|
53 |
</html>
|